From a57b0bdb0323d0fff133922cc7aa08bc238a94d8 Mon Sep 17 00:00:00 2001 From: hg Date: Mon, 15 Feb 2016 22:03:35 +0100 Subject: [PATCH] fixes --- src/hmi.cpp | 88 +++++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/src/hmi.cpp b/src/hmi.cpp index 75391da..c2ce9cb 100644 --- a/src/hmi.cpp +++ b/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;