97 lines
2.5 KiB
C++
97 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include "FSMTreppe2/FSMTreppe2.h"
|
|
#include "PCA9685.h"
|
|
|
|
#define SENSOR_OBEN 2
|
|
#define SENSOR_UNTEN 12
|
|
#define OE 14
|
|
|
|
#define INT_TIME 20 // interrupt intervall [ms]
|
|
|
|
class Treppe {
|
|
private:
|
|
|
|
uint8_t stairs;
|
|
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
|
|
uint16_t idle_brightness = 100;
|
|
uint16_t active_brightness = 300;
|
|
|
|
uint8_t direction = 0;
|
|
uint8_t switch_direction = 0;
|
|
uint8_t state = 0;
|
|
uint8_t switch_state = 0;
|
|
bool finish = 1;
|
|
|
|
// alternative
|
|
uint32_t tick = 0;
|
|
uint32_t stufe = 0;
|
|
uint8_t an_aus = 0;
|
|
|
|
uint32_t ticks_treppe = 0;
|
|
uint32_t ticks_pro_stufe = 0;
|
|
float differenz_pwm_pro_tick = 0.0;
|
|
// alternative
|
|
|
|
// initialize with i2c-Address 0, use Wire Library
|
|
PCA9685 pwmController;
|
|
FSMTreppeModelClass FSMTreppe_Obj;
|
|
FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs;
|
|
FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs;
|
|
void print_state_on_change();
|
|
|
|
const uint8_t FSMTreppe_IN_animation_down = 1U;
|
|
const uint8_t FSMTreppe_IN_animation_up = 2U;
|
|
const uint8_t FSMTreppe_IN_idle = 3U;
|
|
|
|
|
|
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
|
|
void ledsequence();
|
|
void rampe();
|
|
bool read_sensor(int sensor) {
|
|
int pegel = digitalRead(sensor);
|
|
return static_cast<bool>(pegel);
|
|
}
|
|
public:
|
|
Treppe(uint8_t _stairs) : stairs(_stairs){
|
|
FSMTreppe_Obj.initialize();
|
|
|
|
|
|
|
|
ticks_pro_stufe = time_per_stair / 20; // [ms]
|
|
ticks_treppe = ticks_pro_stufe * stairs;
|
|
|
|
differenz_pwm_pro_tick = (float) (active_brightness - idle_brightness)
|
|
/ (float) ticks_pro_stufe;
|
|
}
|
|
~Treppe() {
|
|
FSMTreppe_Obj.terminate();
|
|
}
|
|
|
|
void setup();
|
|
void task(); // call periodically
|
|
|
|
// Parameter section
|
|
uint16_t setIdle(uint16_t _idle_brightness);
|
|
uint16_t setActive(uint16_t _active_brightness);
|
|
uint16_t setTime(uint16_t _time_per_stair);
|
|
|
|
void setTick(uint32_t _tick) {
|
|
tick = _tick;
|
|
Serial.printf("Treppe: Tick: %u!\n", tick);
|
|
}
|
|
uint32_t getTicks() {
|
|
return ticks_treppe;
|
|
}
|
|
|
|
// Runtime Parameter section
|
|
void setDirection(uint8_t _direction);
|
|
void setState(uint8_t _state);
|
|
void setAnAus(uint8_t _an_aus) {
|
|
an_aus = _an_aus;
|
|
}
|
|
|
|
uint8_t getState() { return state;};
|
|
uint8_t getFinished() { return finish;};
|
|
uint8_t getDirection() {return direction;};
|
|
}; |