fixes
This commit is contained in:
parent
5ae36b63cf
commit
a57b0bdb03
88
src/hmi.cpp
88
src/hmi.cpp
@ -13,45 +13,46 @@ const uint32_t UPPER_SHORT_TIME = 1000;
|
||||
class SwitchPort {
|
||||
public:
|
||||
enum e_switchResult { SWITCH_IDLE, SWITCH_SHORT, SWITCH_LONG };
|
||||
SwitchPort() : m_state(0), m_cnt(0) {
|
||||
SwitchPort() : m_state(STATE_IDLE) {
|
||||
};
|
||||
virtual bool getSwitchState() = 0;
|
||||
virtual bool getSwitchState() { return false; };
|
||||
e_switchResult get() {
|
||||
e_switchResult result = SWITCH_IDLE;
|
||||
bool inValue = getSwitchState();
|
||||
uint32_t duration;
|
||||
switch (m_state) {
|
||||
STATE_IDLE:
|
||||
if (inValue == false) {
|
||||
m_state = STATE_BUTTON_PRESSED;
|
||||
m_timestamp = getMillis();
|
||||
}
|
||||
break;
|
||||
STATE_BUTTON_PRESSED:
|
||||
if (inValue == true) {
|
||||
m_state = STATE_BUTTON_RELEASED;
|
||||
}
|
||||
break;
|
||||
STATE_BUTTON_RELEASED:
|
||||
uint32_t duration = m_timestamp - getMillis();
|
||||
if ((duration => LOWER_SHORT_TIME) && (duration <= UPPER_SHORT_TIME)) {
|
||||
m_state = STATE_SHORT;
|
||||
} else if (duration > UPPER_SHORT_TIME) {
|
||||
m_state = STATE_LONG;
|
||||
} else {
|
||||
m_state = STATE_IDLE;
|
||||
}
|
||||
break;
|
||||
STATE_SHORT:
|
||||
result = SWITCH_SHORT;
|
||||
case STATE_IDLE:
|
||||
if (inValue == false) {
|
||||
m_state = STATE_BUTTON_PRESSED;
|
||||
m_timestamp = getMillis();
|
||||
}
|
||||
break;
|
||||
case STATE_BUTTON_PRESSED:
|
||||
if (inValue == true) {
|
||||
m_state = STATE_BUTTON_RELEASED;
|
||||
}
|
||||
break;
|
||||
case STATE_BUTTON_RELEASED:
|
||||
duration = m_timestamp - getMillis();
|
||||
if ((duration >= LOWER_SHORT_TIME) && (duration <= UPPER_SHORT_TIME)) {
|
||||
m_state = STATE_SHORT;
|
||||
} else if (duration > UPPER_SHORT_TIME) {
|
||||
m_state = STATE_LONG;
|
||||
} else {
|
||||
m_state = STATE_IDLE;
|
||||
break;
|
||||
STATE_LONG:
|
||||
result = SWITCH_LONG;
|
||||
m_state = STATE_IDLE;
|
||||
break;
|
||||
default:
|
||||
m_state = STATE_IDLE;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case STATE_SHORT:
|
||||
result = SWITCH_SHORT;
|
||||
m_state = STATE_IDLE;
|
||||
break;
|
||||
case STATE_LONG:
|
||||
result = SWITCH_LONG;
|
||||
m_state = STATE_IDLE;
|
||||
break;
|
||||
default:
|
||||
m_state = STATE_IDLE;
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -64,36 +65,37 @@ private:
|
||||
|
||||
class SwitchPort2 : public SwitchPort {
|
||||
public:
|
||||
SwitchPort2(uint16_t bit) : SwitchPort() {
|
||||
SwitchPort2(uint16_t bit) : SwitchPort(), m_bit(bit) {
|
||||
P2REN |= bit;
|
||||
P2DIR &= ~bit;
|
||||
P2SEL &= ~bit;
|
||||
};
|
||||
virtual bool getSwitchState() {
|
||||
return P2IN & bit;
|
||||
return P2IN & m_bit;
|
||||
};
|
||||
private:
|
||||
bool m_bit;
|
||||
};
|
||||
class SwitchPort1 : public SwitchPort {
|
||||
public:
|
||||
SwitchPort1(uint16_t bit) : SwitchPort() {
|
||||
SwitchPort1(uint16_t bit) : SwitchPort(), m_bit(bit) {
|
||||
P1REN |= bit;
|
||||
P1DIR &= ~bit;
|
||||
P1SEL &= ~bit;
|
||||
};
|
||||
virtual bool getSwitchState() {
|
||||
return P1IN & bit;
|
||||
return P1IN & m_bit;
|
||||
};
|
||||
private:
|
||||
bool m_bit;
|
||||
};
|
||||
|
||||
|
||||
SwitchPort2 rawIntensitySwitch = SwitchPort2(BIT1);
|
||||
&SwitchPort intensitySwitch = rawIntensitySwitch;
|
||||
SwitchPort2 intensitySwitch = SwitchPort2(BIT1);
|
||||
|
||||
SwitchPort2 rawOnTimeSwitch = SwitchPort2(BIT2);
|
||||
&SwitchPort onTimeSwitch = rawOnTimeSwitch;
|
||||
SwitchPort2 onTimeSwitch = SwitchPort2(BIT2);
|
||||
|
||||
SwitchPort2 rawOffTimeSwitch = SwitchPort2(BIT3);
|
||||
&SwitchPort offTimeSwitch = rawOffTimeSwitch;
|
||||
SwitchPort2 offTimeSwitch = SwitchPort2(BIT3);
|
||||
//SwitchPort modeSwitch = SwitchPort2(BIT4);
|
||||
|
||||
int16_t intensity = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user