diff --git a/src/hmi.cpp b/src/hmi.cpp index 5288bce..fa82971 100644 --- a/src/hmi.cpp +++ b/src/hmi.cpp @@ -10,13 +10,71 @@ #include #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); + } } diff --git a/src/pwm.h b/src/pwm.h index ff2962c..a88b12a 100644 --- a/src/pwm.h +++ b/src/pwm.h @@ -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_ */