implement switches

This commit is contained in:
Wolfgang Hottgenroth 2015-02-22 17:39:09 +01:00
parent 426e690e26
commit 6678fdf101
2 changed files with 67 additions and 12 deletions

View File

@ -10,13 +10,71 @@
#include <stdint.h>
#include "hmi.h"
#include "pwm.h"
class SwitchPort2 {
public:
SwitchPort2(uint16_t bit) : m_bit(bit), m_state(0), m_cnt(0) {
P2REN |= m_bit;
};
bool get() {
bool result = false;
switch (m_state) {
case 0:
if (P2IN & m_bit) {
m_cnt++;
} else {
m_cnt = 0;
}
if (m_cnt > 100) {
m_state = 1;
m_cnt = 0;
}
break;
case 1:
result = true;
m_state = 2;
break;
case 2:
if (P2IN & m_bit) {
m_cnt = 0;
} else {
m_cnt++;
}
if (m_cnt > 20) {
m_state = 0;
m_cnt = 0;
}
break;
default:
m_state = 0;
break;
}
return result;
};
private:
uint16_t m_bit;
uint8_t m_state;
uint16_t m_cnt;
};
SwitchPort2 switch1 = SwitchPort2(BIT0);
SwitchPort2 switch2 = SwitchPort2(BIT1);
SwitchPort2 switch3 = SwitchPort2(BIT2);
void hmiInit() {
}
void hmiExec() {
if (switch1.get()) {
setUDes(0)
}
if (switch2.get()) {
setUDes(getUDes() - 1.0);
}
if (switch3.get()) {
setUDes(getUDes() + 1.0);
}
}

View File

@ -1,12 +1,5 @@
/*
* time.h
*
* Created on: 20.05.2014
* Author: wn
*/
#ifndef TIME_H_
#define TIME_H_
#ifndef PWM_H_
#define PWM_H_
@ -16,8 +9,12 @@ const uint16_t CYCLE_DELAY = 1;
void pwmInit();
float getDutyCycle();
float getUCur();
float getUDes();
void setUDes(float uDes);
#endif /* TIME_H_ */
#endif /* PWM_H_ */