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

@@ -303,6 +303,8 @@ void Treppe::setup()
pwmController.setPWMFrequency(100);
//pwmController.setAllChannelsPWM(idle_pwm);

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

pinMode(13, OUTPUT);
pinMode(0, OUTPUT);
digitalWrite(13, HIGH);
@@ -317,13 +319,17 @@ void Treppe::setup()
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)
{
// future use: parameters.idle_max_pwm
uint16_t new_pwm = parameters.active_pwm * prozent / 100;
set_idle_pwm_max(new_pwm);
}

void Treppe::set_idle_pwm_max(const uint16_t new_pwm)
{
// future use: parameters.idle_max_pwm
@@ -335,15 +341,18 @@ void Treppe::set_idle_pwm_max(const uint16_t new_pwm)

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

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

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

@@ -3,6 +3,7 @@

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

// #define LDRDEBUG // comment in to override LDR measurement
#define LDR_HYS 1 // Hysteresis for switching off FSM [lux]
@@ -13,6 +14,8 @@

#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 {
private:
const uint8_t stufen;
@@ -104,6 +107,7 @@ public:
void task(); // call periodically

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

Loading…
Cancel
Save