Browse Source

EEP implementation

tags/v1.0.0
Dominik Bartsch 3 years ago
parent
commit
31c268487c
2 changed files with 14 additions and 1 deletions
  1. 10
    1
      lib/treppe/treppe.cpp
  2. 4
    0
      lib/treppe/treppe.h

+ 10
- 1
lib/treppe/treppe.cpp View File

pwmController.setPWMFrequency(100); pwmController.setPWMFrequency(100);
//pwmController.setAllChannelsPWM(idle_pwm); //pwmController.setAllChannelsPWM(idle_pwm);


EEPROM.get(EEP_START_ADDR, parameters); // get Parameters of flash

pinMode(13, OUTPUT); pinMode(13, OUTPUT);
pinMode(0, OUTPUT); pinMode(0, OUTPUT);
digitalWrite(13, HIGH); digitalWrite(13, HIGH);
Serial.printf("Treppe: stufen=%d\n", stufen); Serial.printf("Treppe: stufen=%d\n", stufen);
} }


void Treppe::saveParam(){
EEPROM.put(EEP_START_ADDR, parameters); // copy Parameters so "EEPROM"-section in RAM
EEPROM.commit(); // write "EEPROM"-section to flash
}

void Treppe::set_idle_prozent(const int prozent) void Treppe::set_idle_prozent(const int prozent)
{ {
// future use: parameters.idle_max_pwm // future use: parameters.idle_max_pwm
uint16_t new_pwm = parameters.active_pwm * prozent / 100; uint16_t new_pwm = parameters.active_pwm * prozent / 100;
set_idle_pwm_max(new_pwm); set_idle_pwm_max(new_pwm);
} }

void Treppe::set_idle_pwm_max(const uint16_t new_pwm) void Treppe::set_idle_pwm_max(const uint16_t new_pwm)
{ {
// future use: parameters.idle_max_pwm // future use: parameters.idle_max_pwm


Serial.printf("Treppe: idle_pwm_soll=%d\n", idle_pwm_soll); Serial.printf("Treppe: idle_pwm_soll=%d\n", idle_pwm_soll);
fsm_pend.ldr_changed = true; fsm_pend.ldr_changed = true;
//saveParam(); //uncomment if idle_pwm_max is used
} }


void Treppe::set_active_pwm(uint16_t _active_pwm) void Treppe::set_active_pwm(uint16_t _active_pwm)
{ {
parameters.active_pwm = _active_pwm; parameters.active_pwm = _active_pwm;
Serial.printf("Treppe: active_pwm=%d\n", parameters.active_pwm); Serial.printf("Treppe: active_pwm=%d\n", parameters.active_pwm);
saveParam();
} }
void Treppe::set_time_per_stair(uint16_t _time_per_stair) void Treppe::set_time_per_stair(uint16_t _time_per_stair)
{ {
parameters.time_per_stair = _time_per_stair; parameters.time_per_stair = _time_per_stair;
Serial.printf("Treppe: time_per_stair=%d\n", parameters.time_per_stair); Serial.printf("Treppe: time_per_stair=%d\n", parameters.time_per_stair);
saveParam();
} }

+ 4
- 0
lib/treppe/treppe.h View File



#include "FSMTreppe3/FSMTreppe3.h" #include "FSMTreppe3/FSMTreppe3.h"
#include "PCA9685.h" #include "PCA9685.h"
#include <EEPROM.h>


// #define LDRDEBUG // comment in to override LDR measurement // #define LDRDEBUG // comment in to override LDR measurement
#define LDR_HYS 1 // Hysteresis for switching off FSM [lux] #define LDR_HYS 1 // Hysteresis for switching off FSM [lux]


#define INT_TIME 20 // interrupt intervall [ms] #define INT_TIME 20 // interrupt intervall [ms]


#define EEP_START_ADDR 100 // define Start Address for "EEPROM" storage -> depends on size of "wifi_data"!

class Treppe { class Treppe {
private: private:
const uint8_t stufen; const uint8_t stufen;
void task(); // call periodically void task(); // call periodically


// Parameter section // Parameter section
void saveParam();
void set_idle_prozent(int prozent); void set_idle_prozent(int prozent);
void set_idle_pwm_max(const uint16_t new_pwm); void set_idle_pwm_max(const uint16_t new_pwm);
void set_active_pwm(uint16_t _active_pwm); void set_active_pwm(uint16_t _active_pwm);

Loading…
Cancel
Save