implement switches
This commit is contained in:
parent
426e690e26
commit
6678fdf101
62
src/hmi.cpp
62
src/hmi.cpp
@ -10,13 +10,71 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "hmi.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 hmiInit() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void hmiExec() {
|
void hmiExec() {
|
||||||
|
if (switch1.get()) {
|
||||||
|
setUDes(0)
|
||||||
|
}
|
||||||
|
if (switch2.get()) {
|
||||||
|
setUDes(getUDes() - 1.0);
|
||||||
|
}
|
||||||
|
if (switch3.get()) {
|
||||||
|
setUDes(getUDes() + 1.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
17
src/pwm.h
17
src/pwm.h
@ -1,12 +1,5 @@
|
|||||||
/*
|
#ifndef PWM_H_
|
||||||
* time.h
|
#define PWM_H_
|
||||||
*
|
|
||||||
* Created on: 20.05.2014
|
|
||||||
* Author: wn
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TIME_H_
|
|
||||||
#define TIME_H_
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -16,8 +9,12 @@ const uint16_t CYCLE_DELAY = 1;
|
|||||||
|
|
||||||
|
|
||||||
void pwmInit();
|
void pwmInit();
|
||||||
|
float getDutyCycle();
|
||||||
|
float getUCur();
|
||||||
|
float getUDes();
|
||||||
|
void setUDes(float uDes);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* TIME_H_ */
|
#endif /* PWM_H_ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user