files renamed, start with HMI
This commit is contained in:
@ -8,7 +8,7 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "time.h"
|
#include "engine.h"
|
||||||
|
|
||||||
|
|
||||||
volatile uint16_t timestamp = 0;
|
volatile uint16_t timestamp = 0;
|
||||||
@ -64,7 +64,7 @@ interrupt (TIMER0_A0_VECTOR) timer0a0_isr(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void timeInit() {
|
void engineInit() {
|
||||||
timestamp = 0;
|
timestamp = 0;
|
||||||
|
|
||||||
P1DIR |= BIT0 | BIT1 | BIT6;
|
P1DIR |= BIT0 | BIT1 | BIT6;
|
||||||
@ -88,4 +88,10 @@ uint32_t ticks() {
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t engineMaxPwmValue() {
|
||||||
|
return TICK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void engineSetPwmValue(uint16_t val) {
|
||||||
|
TACCR1 = val;
|
||||||
|
}
|
21
src/engine.h
Normal file
21
src/engine.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* time.h
|
||||||
|
*
|
||||||
|
* Created on: 17.01.2016
|
||||||
|
* Author: wn
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ENGINE_H_
|
||||||
|
#define ENGINE_H_
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void engineInit();
|
||||||
|
uint32_t ticks();
|
||||||
|
uint16_t engineMaxPwmValue();
|
||||||
|
void engineSetPwmValue(uint16_t val);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* ENGINE_H_ */
|
121
src/hmi.cpp
Normal file
121
src/hmi.cpp
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
#include <msp430g2553.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "hmi.h"
|
||||||
|
#include "engine.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class SwitchPort {
|
||||||
|
public:
|
||||||
|
enum e_Value { e_NIL, e_SHORT, e_LONG };
|
||||||
|
SwitchPort(uint16_t bit, uint16_t inRegister) : m_bit(bit), m_state(0), m_cnt(0), m_inRegister(inRegister) {
|
||||||
|
};
|
||||||
|
e_Value get() {
|
||||||
|
e_Value result = e_NIL;
|
||||||
|
switch (m_state) {
|
||||||
|
case 0:
|
||||||
|
if (getInValue()) {
|
||||||
|
m_state = 1;
|
||||||
|
} else {
|
||||||
|
m_cnt++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (m_cnt > LONG_THRESHOLD) {
|
||||||
|
result = e_LONG;
|
||||||
|
m_state = 2;
|
||||||
|
} else if (m_cnt > SHORT_THRESHOLD) {
|
||||||
|
result = e_SHORT;
|
||||||
|
} else {
|
||||||
|
m_state = 0;
|
||||||
|
}
|
||||||
|
m_cnt = 0;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (getInValue()) {
|
||||||
|
m_cnt++;
|
||||||
|
} else {
|
||||||
|
m_cnt = 0;
|
||||||
|
}
|
||||||
|
if (m_cnt > COOLDOWN_THRESHOLD) {
|
||||||
|
m_state = 0;
|
||||||
|
m_cnt = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
m_state = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
protected:
|
||||||
|
virtual bool getInValue() =0;
|
||||||
|
uint8_t m_inRegister;
|
||||||
|
private:
|
||||||
|
const uint16_t SHORT_THRESHOLD = 100;
|
||||||
|
const uint16_t LONG_THRESHOLD = 300;
|
||||||
|
const uint16_t COOLDOWN_THRESHOLD = 20;
|
||||||
|
uint16_t m_bit;
|
||||||
|
uint8_t m_state;
|
||||||
|
uint16_t m_cnt;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SwitchPort2 : public SwitchPort {
|
||||||
|
public:
|
||||||
|
SwitchPort2(uint16_t bit) : SwitchPort(bit, 2) {
|
||||||
|
P2REN |= bit;
|
||||||
|
P2DIR &= ~bit;
|
||||||
|
P2SEL &= ~bit;
|
||||||
|
};
|
||||||
|
protected:
|
||||||
|
virtual bool getInValue() {
|
||||||
|
return P2IN & m_inRegister;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
class SwitchPort1 : public SwitchPort {
|
||||||
|
public:
|
||||||
|
SwitchPort1(uint16_t bit) : SwitchPort(bit, 1) {
|
||||||
|
P1REN |= bit;
|
||||||
|
P1DIR &= ~bit;
|
||||||
|
P1SEL &= ~bit;
|
||||||
|
};
|
||||||
|
protected:
|
||||||
|
virtual bool getInValue(uint8_t bit) {
|
||||||
|
return P1IN & m_inRegister;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
SwitchPort intensitySwitch = SwitchPort2(BIT0);
|
||||||
|
SwitchPort onTimeSwitch = SwitchPort2(BIT1);
|
||||||
|
SwitchPort offTimeSwitch = SwitchPort2(BIT2);
|
||||||
|
SwitchPort modeSwitch = SwitchPort2(BIT3);
|
||||||
|
|
||||||
|
int16_t intensity = 0;
|
||||||
|
uint16_t maxIntensity = 0;
|
||||||
|
uint16_t intensityStep = 0;
|
||||||
|
const uint16_t intensityStepCnt = 8;
|
||||||
|
|
||||||
|
|
||||||
|
void hmiInit() {
|
||||||
|
maxIntensity = engineMaxPwmValue();
|
||||||
|
intensityStep = maxIntensity / intensityStepCnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void hmiExec() {
|
||||||
|
if (SwitchPort::e_SHORT == intensitySwitch.get()) {
|
||||||
|
intensity += intensityStep;
|
||||||
|
if (intensity > maxIntensity) {
|
||||||
|
intensity = maxIntensity;
|
||||||
|
}
|
||||||
|
engineSetPwmValue(intensity);
|
||||||
|
} else if (SwitchPort::e_LONG == intensitySwitch.get()) {
|
||||||
|
intensity -= intensityStep;
|
||||||
|
if (intensity < 0) {
|
||||||
|
intensity = 0;
|
||||||
|
}
|
||||||
|
engineSetPwmValue(intensity);
|
||||||
|
}
|
||||||
|
}
|
9
src/hmi.h
Normal file
9
src/hmi.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#ifndef HMI_H_
|
||||||
|
#define HMI_H_
|
||||||
|
|
||||||
|
|
||||||
|
void hmiInit();
|
||||||
|
void hmiExec();
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* HMI_H_ */
|
@ -10,7 +10,7 @@
|
|||||||
#include <intrinsics.h>
|
#include <intrinsics.h>
|
||||||
#include <isr_compat.h>
|
#include <isr_compat.h>
|
||||||
|
|
||||||
#include "time.h"
|
#include "engine.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ int main() {
|
|||||||
WDTCTL = WDTPW | WDTHOLD;
|
WDTCTL = WDTPW | WDTHOLD;
|
||||||
|
|
||||||
|
|
||||||
timeInit();
|
engineInit();
|
||||||
|
|
||||||
|
|
||||||
__enable_interrupt();
|
__enable_interrupt();
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
void switch_interrupt() {
|
|
||||||
unsigned long currentEvent = millis();
|
|
||||||
|
|
||||||
if ((lastEvent == 0) || (lastEvent + DEBOUNCING_DEAD_TIME < currentEvent)) {
|
|
||||||
lastEvent = currentEvent;
|
|
||||||
|
|
||||||
switchState = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool getAndResetSwitchState() {
|
|
||||||
bool res = false;
|
|
||||||
|
|
||||||
noInterrupts();
|
|
||||||
res = switchState;
|
|
||||||
switchState = false;
|
|
||||||
interrupts();
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
*/
|
|
19
src/time.h
19
src/time.h
@ -1,19 +0,0 @@
|
|||||||
/*
|
|
||||||
* time.h
|
|
||||||
*
|
|
||||||
* Created on: 17.01.2016
|
|
||||||
* Author: wn
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TIME_H_
|
|
||||||
#define TIME_H_
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void timeInit();
|
|
||||||
uint32_t ticks();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* TIME_H_ */
|
|
Reference in New Issue
Block a user