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