2023-05-02 13:46:25 +02:00
|
|
|
//********************************//
|
2023-05-01 15:55:42 +02:00
|
|
|
|
2023-04-24 20:26:49 +02:00
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
#include <ESP8266mDNS.h>
|
|
|
|
#include <ESP8266HTTPUpdateServer.h>
|
|
|
|
#include <ESP8266WebServer.h>
|
|
|
|
#include <WiFiManager.h>
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
#include <EEPROM.h>
|
2023-05-02 13:46:25 +02:00
|
|
|
#include <FS.h>
|
2023-04-24 20:26:49 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2023-05-03 11:51:37 +02:00
|
|
|
//********* preprocessor block *********//
|
|
|
|
|
|
|
|
#ifdef DEVELOPMENT
|
|
|
|
#define LIGHT_NAME "Dimmable Hue Light (DEV)"
|
|
|
|
#else
|
|
|
|
#define LIGHT_NAME LIGHT_NAME_STR
|
|
|
|
#endif
|
|
|
|
|
2023-04-24 20:26:49 +02:00
|
|
|
//********* Config block *********//
|
2023-05-03 11:51:37 +02:00
|
|
|
|
2023-04-29 20:30:42 +02:00
|
|
|
// blue, warmwhite, purple, white&red&green
|
|
|
|
// blau, schwarz, rot, weiß
|
2023-04-29 12:05:13 +02:00
|
|
|
// ch1, ch2, ch3, ch4
|
2023-04-29 20:30:42 +02:00
|
|
|
// D1, D2, D7, D5
|
|
|
|
uint8_t pins[LIGHTS_COUNT] = { 5, 4, 13, 14 };
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-05-01 19:39:55 +02:00
|
|
|
#ifndef DEVELOPMENT
|
2023-04-30 19:54:16 +02:00
|
|
|
IPAddress strip_ip (192, 168, 0, 26); // choose an unique IP Adress
|
2023-05-01 19:39:55 +02:00
|
|
|
#endif
|
|
|
|
#ifdef DEVELOPMENT
|
|
|
|
IPAddress strip_ip (192, 168, 0, 27); // choose an unique IP Adress
|
|
|
|
#endif
|
2023-04-30 19:54:16 +02:00
|
|
|
IPAddress gateway_ip (192, 168, 0, 1); // Router IP
|
|
|
|
IPAddress subnet_mask(255, 255, 255, 0);
|
|
|
|
IPAddress dns (192, 168, 0, 1);
|
2023-04-24 20:26:49 +02:00
|
|
|
|
|
|
|
//********************************//
|
|
|
|
|
|
|
|
#define LIGHT_VERSION 2.1
|
|
|
|
|
|
|
|
#define LAST_STATE_STARTUP_LIGHT_LAST_STATE 0
|
2023-04-29 12:05:13 +02:00
|
|
|
#define LAST_STATE_STARTUP_LIGHT_ON_STATE 1
|
|
|
|
#define LAST_STATE_STARTUP_LIGHT_OFF_STATE 2
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
#define LIGHT_STATE_ON 1
|
2023-04-24 20:26:49 +02:00
|
|
|
#define LIGHT_STATE_OFF 0
|
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
#define TIMING_CONTROL_ENABLED 1
|
2023-04-24 20:26:49 +02:00
|
|
|
#define TIMING_CONTROL_DISABLED 0
|
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
#define SCENE_RELEAX 0
|
|
|
|
#define SCENE_BRIGHT 1
|
2023-04-24 20:26:49 +02:00
|
|
|
#define SCENE_NIGHTLY 2
|
|
|
|
|
2023-05-11 16:48:59 +02:00
|
|
|
#define TEST_PWM_STATE_INIT 0
|
|
|
|
#define TEST_PWM_STATE_CH1_INC 1
|
|
|
|
#define TEST_PWM_STATE_CH1_DEC 2
|
|
|
|
#define TEST_PWM_STATE_CH2_INC 3
|
|
|
|
#define TEST_PWM_STATE_CH2_DEC 4
|
|
|
|
#define TEST_PWM_STATE_CH3_INC 5
|
|
|
|
#define TEST_PWM_STATE_CH3_DEC 6
|
|
|
|
#define TEST_PWM_STATE_CH4_INC 7
|
|
|
|
#define TEST_PWM_STATE_CH4_DEC 8
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-04-25 08:18:36 +02:00
|
|
|
//********************************//
|
|
|
|
|
2023-04-24 20:26:49 +02:00
|
|
|
uint8_t scene;
|
|
|
|
uint8_t tc_enabled;
|
2023-05-11 16:48:59 +02:00
|
|
|
uint8_t tc_enabled_old;
|
|
|
|
|
|
|
|
bool test_pwm = false;
|
|
|
|
uint32_t test_pwm_lastcheck_ms = 0;
|
|
|
|
uint8_t test_pwm_state = TEST_PWM_STATE_INIT;
|
2023-04-24 20:26:49 +02:00
|
|
|
|
|
|
|
bool light_state[LIGHTS_COUNT];
|
|
|
|
bool in_transition;
|
|
|
|
|
2023-05-11 19:37:17 +02:00
|
|
|
int default_transitiontime = 4; // 4 = 4 seconds
|
2023-04-29 12:40:14 +02:00
|
|
|
|
2023-05-11 19:37:17 +02:00
|
|
|
uint16_t transitiontime[LIGHTS_COUNT];
|
|
|
|
uint16_t bri[LIGHTS_COUNT];
|
2023-04-28 12:01:50 +02:00
|
|
|
uint16_t current_pwm[LIGHTS_COUNT];
|
2023-04-24 20:26:49 +02:00
|
|
|
|
|
|
|
float step_level[LIGHTS_COUNT];
|
|
|
|
float current_bri[LIGHTS_COUNT];
|
|
|
|
byte mac[6];
|
|
|
|
|
|
|
|
ESP8266WebServer server(80);
|
|
|
|
ESP8266HTTPUpdateServer httpUpdateServer;
|
|
|
|
|
2023-04-25 20:06:04 +02:00
|
|
|
uint32_t last_lightengine_activity = 0;
|
|
|
|
|
2023-04-25 08:18:36 +02:00
|
|
|
//********************************//
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-05-02 08:03:14 +02:00
|
|
|
void apply_scene(uint8_t new_scene, uint8_t light)
|
|
|
|
{
|
|
|
|
if (new_scene == SCENE_RELEAX)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
bri[light] = 144;
|
2023-05-02 08:03:14 +02:00
|
|
|
} else if (new_scene == SCENE_BRIGHT)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
bri[light] = 254;
|
2023-05-02 08:03:14 +02:00
|
|
|
} else if (new_scene == SCENE_NIGHTLY)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
bri[0] = 25;
|
2023-04-27 16:40:27 +02:00
|
|
|
bri[1] = 0;
|
|
|
|
bri[2] = 0;
|
|
|
|
bri[3] = 0;
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-25 08:18:36 +02:00
|
|
|
//********************************//
|
|
|
|
|
2023-04-29 12:40:14 +02:00
|
|
|
void process_lightdata(uint8_t light, float tt)
|
|
|
|
{
|
2023-05-12 12:23:45 +02:00
|
|
|
if (tt <= 0)
|
|
|
|
{
|
|
|
|
tt = default_transitiontime;
|
|
|
|
}
|
2023-04-29 12:40:14 +02:00
|
|
|
if (light_state[light])
|
|
|
|
{
|
2023-04-27 11:26:21 +02:00
|
|
|
step_level[light] = (bri[light] - current_bri[light]) / tt;
|
|
|
|
|
2023-04-24 20:26:49 +02:00
|
|
|
} else {
|
2023-04-27 11:26:21 +02:00
|
|
|
step_level[light] = current_bri[light] / tt;
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-25 08:18:36 +02:00
|
|
|
//********************************//
|
|
|
|
|
2023-04-29 12:40:14 +02:00
|
|
|
void lightEngine()
|
|
|
|
{
|
2023-04-25 20:06:04 +02:00
|
|
|
|
2023-04-27 16:40:27 +02:00
|
|
|
if (millis() < (last_lightengine_activity + TIME_LIGHTENGINE_INTERVAL_MS)) {
|
2023-04-25 20:06:04 +02:00
|
|
|
// abort processing, the transition setting is a delay of seconds
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_lightengine_activity = millis();
|
|
|
|
|
2023-04-28 12:01:50 +02:00
|
|
|
for (int i = 0; i < LIGHTS_COUNT; i++)
|
|
|
|
{
|
2023-04-27 11:26:21 +02:00
|
|
|
|
2023-04-28 12:01:50 +02:00
|
|
|
if (light_state[i])
|
|
|
|
{
|
|
|
|
if (bri[i] != current_bri[i])
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
in_transition = true;
|
2023-04-27 11:26:21 +02:00
|
|
|
current_bri[i] += step_level[i] / BRI_MOD_STEPS_PER_SEC;
|
2023-04-29 12:40:14 +02:00
|
|
|
if ((step_level[i] > 0.0 && current_bri[i] > bri[i]) || (step_level[i] < 0.0 && current_bri[i] < bri[i]))
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
current_bri[i] = bri[i];
|
2023-04-27 11:26:21 +02:00
|
|
|
//Serial.println("Reached target bri[" + (String)i + "] = " + (String)bri[i]);
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
2023-04-25 16:40:28 +02:00
|
|
|
|
2023-04-25 20:06:04 +02:00
|
|
|
uint16_t tmp_pwm = calcPWM(current_bri[i]);
|
2023-04-28 12:01:50 +02:00
|
|
|
current_pwm[i] = tmp_pwm;
|
2023-04-27 11:26:21 +02:00
|
|
|
//Serial.println("lon: pin" + (String)i + " = PWM(" + (String)tmp_pwm + ")");
|
2023-04-25 20:06:04 +02:00
|
|
|
analogWrite(pins[i], tmp_pwm);
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
2023-05-12 07:19:03 +02:00
|
|
|
} else { // light state is off
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-04-28 12:01:50 +02:00
|
|
|
if (current_bri[i] != 0)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
in_transition = true;
|
2023-05-12 12:19:00 +02:00
|
|
|
current_bri[i] -= step_level[i] / BRI_MOD_STEPS_PER_SEC;
|
2023-04-28 12:01:50 +02:00
|
|
|
if (current_bri[i] < 0)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
current_bri[i] = 0;
|
2023-04-27 11:26:21 +02:00
|
|
|
//Serial.println("Reached target bri[" + (String)i + "] = " + (String)bri[i]);
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
2023-04-25 16:40:28 +02:00
|
|
|
|
2023-04-25 20:06:04 +02:00
|
|
|
uint16_t tmp_pwm = calcPWM(current_bri[i]);
|
2023-04-28 12:01:50 +02:00
|
|
|
current_pwm[i] = tmp_pwm;
|
2023-04-27 11:26:21 +02:00
|
|
|
//Serial.println("loff: pin" + (String)i + " = PWM(" + (String)tmp_pwm + ")");
|
2023-04-25 20:06:04 +02:00
|
|
|
analogWrite(pins[i], tmp_pwm);
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
|
|
|
}
|
2023-04-27 11:26:21 +02:00
|
|
|
|
2023-04-27 16:40:27 +02:00
|
|
|
} // for loop end
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-04-28 12:01:50 +02:00
|
|
|
if (in_transition)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
delay(6);
|
|
|
|
in_transition = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-25 08:18:36 +02:00
|
|
|
//********************************//
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-04-28 12:01:50 +02:00
|
|
|
uint16_t calcPWM(float tbri)
|
|
|
|
{
|
2023-04-25 16:40:28 +02:00
|
|
|
uint16_t tmp_pwm = PWM_OFF;
|
2023-04-28 12:01:50 +02:00
|
|
|
if (tbri > 0.0)
|
|
|
|
{
|
2023-04-25 16:40:28 +02:00
|
|
|
tmp_pwm = PWM_MIN + (int)(tbri * BRI_TO_PWM_FACTOR);
|
|
|
|
}
|
2023-04-27 16:40:27 +02:00
|
|
|
if (tmp_pwm > PWM_MAX) {
|
2023-04-25 16:40:28 +02:00
|
|
|
tmp_pwm = PWM_MAX;
|
|
|
|
}
|
2023-04-28 12:01:50 +02:00
|
|
|
|
2023-04-25 16:40:28 +02:00
|
|
|
return tmp_pwm;
|
|
|
|
}
|
|
|
|
|
|
|
|
//********************************//
|
|
|
|
|
2023-04-28 12:01:50 +02:00
|
|
|
void read_eeprom_config()
|
|
|
|
{
|
2023-04-25 08:18:36 +02:00
|
|
|
uint8_t tmp = EEPROM.read(EEPROM_TIMING_CONTROL_ENABLED_ADDRESS);
|
2023-04-28 12:01:50 +02:00
|
|
|
if (tmp == TIMING_CONTROL_DISABLED)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
tc_enabled = TIMING_CONTROL_DISABLED;
|
|
|
|
|
2023-04-28 12:01:50 +02:00
|
|
|
} else if (tmp == TIMING_CONTROL_ENABLED)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
tc_enabled = TIMING_CONTROL_ENABLED;
|
2023-04-27 16:40:27 +02:00
|
|
|
|
2023-04-24 20:26:49 +02:00
|
|
|
} else {
|
2023-05-02 13:46:25 +02:00
|
|
|
// Write default value
|
2023-04-24 20:26:49 +02:00
|
|
|
EEPROM.write(EEPROM_TIMING_CONTROL_ENABLED_ADDRESS, TIMING_CONTROL_DISABLED);
|
|
|
|
EEPROM.commit();
|
|
|
|
tc_enabled = TIMING_CONTROL_DISABLED;
|
2023-05-02 13:46:25 +02:00
|
|
|
Serial.println("Written default timing control config to EEPROM (disabled)");
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
2023-05-02 13:46:25 +02:00
|
|
|
Serial.println("Timing Control status: " + (String)tc_enabled);
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
if (EEPROM.read(EEPROM_LAST_STATE_STARTUP_ADDRESS) > 2)
|
2023-04-29 12:05:13 +02:00
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
// set the default value on uninitialized EEPROM
|
|
|
|
EEPROM.write(EEPROM_LAST_STATE_STARTUP_ADDRESS, 0);
|
|
|
|
EEPROM.commit();
|
2023-05-02 13:46:25 +02:00
|
|
|
Serial.println("Written default 'last state' config to EEPROM");
|
|
|
|
}
|
|
|
|
Serial.println("Last state startup setting: " + (String)EEPROM.read(EEPROM_LAST_STATE_STARTUP_ADDRESS));
|
|
|
|
|
|
|
|
if (EEPROM.read(EEPROM_SCENE_ADDRESS) > 2)
|
|
|
|
{
|
|
|
|
// set the default value on uninitialized EEPROM
|
|
|
|
EEPROM.write(EEPROM_SCENE_ADDRESS, 0);
|
|
|
|
EEPROM.commit();
|
|
|
|
Serial.println("Written default scene config to EEPROM");
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
2023-05-02 13:46:25 +02:00
|
|
|
Serial.println("Scene setting: " + (String)EEPROM.read(EEPROM_SCENE_ADDRESS));
|
2023-04-24 20:26:49 +02:00
|
|
|
|
|
|
|
#ifdef USE_STATIC_IP
|
2023-05-02 13:46:25 +02:00
|
|
|
if (EEPROM.read(EEPROM_DYNAMIC_IP_ADDRESS) > 1)
|
2023-04-29 12:05:13 +02:00
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
EEPROM.write(EEPROM_DYNAMIC_IP_ADDRESS, 0);
|
|
|
|
EEPROM.commit();
|
2023-05-02 13:46:25 +02:00
|
|
|
Serial.println("Written default dynamic IP setting (disabled) to EEPROM");
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
|
|
|
#else
|
2023-05-02 13:46:25 +02:00
|
|
|
if (EEPROM.read(EEPROM_DYNAMIC_IP_ADDRESS) > 1)
|
2023-04-29 12:05:13 +02:00
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
EEPROM.write(EEPROM_DYNAMIC_IP_ADDRESS, 1);
|
|
|
|
EEPROM.commit();
|
2023-05-02 13:46:25 +02:00
|
|
|
Serial.println("Written default dynamic IP setting (enabled) to EEPROM");
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
|
|
|
#endif
|
2023-05-02 13:46:25 +02:00
|
|
|
Serial.println("Dynamic IP setting: " + (String)EEPROM.read(EEPROM_DYNAMIC_IP_ADDRESS));
|
|
|
|
|
|
|
|
for (uint8_t light = 0; light < LIGHTS_COUNT; light++)
|
|
|
|
{
|
|
|
|
apply_scene(EEPROM.read(EEPROM_SCENE_ADDRESS), light);
|
|
|
|
step_level[light] = bri[light] / 150.0;
|
|
|
|
|
|
|
|
if (EEPROM.read(EEPROM_LAST_STATE_STARTUP_ADDRESS) == LAST_STATE_STARTUP_LIGHT_LAST_STATE ||
|
|
|
|
(EEPROM.read(EEPROM_LAST_STATE_STARTUP_ADDRESS) == LAST_STATE_STARTUP_LIGHT_ON_STATE &&
|
|
|
|
EEPROM.read(EEPROM_LAST_STATE_ADDRESS + light) == LIGHT_STATE_ON))
|
|
|
|
{
|
|
|
|
light_state[light] = true; // set the light state to on
|
|
|
|
}
|
|
|
|
Serial.println("light[" + (String)light + "] = " + (String)light_state[light]);
|
|
|
|
}
|
2023-04-29 12:05:13 +02:00
|
|
|
|
2023-04-25 08:18:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//********************************//
|
|
|
|
|
2023-04-28 10:56:26 +02:00
|
|
|
void setup()
|
|
|
|
{
|
2023-04-25 15:35:04 +02:00
|
|
|
EEPROM.begin(256);
|
2023-04-25 08:18:36 +02:00
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
SPIFFS.begin();
|
|
|
|
|
2023-05-10 10:48:50 +02:00
|
|
|
#ifdef DEVELOPMENT
|
|
|
|
// Serial is not used in non development mode
|
2023-04-25 08:18:36 +02:00
|
|
|
Serial.begin(SERIAL_BAUD_RATE);
|
2023-05-10 10:48:50 +02:00
|
|
|
#endif
|
2023-04-25 08:18:36 +02:00
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
Serial.flush();
|
|
|
|
delay(1000);
|
|
|
|
|
2023-05-03 16:40:39 +02:00
|
|
|
//Serial.println("Flash size: " + (String)ESP.getFlashChipSize());
|
2023-05-03 16:21:45 +02:00
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
Dir dir = SPIFFS.openDir("/");
|
|
|
|
Serial.println("\n\nSPIFFS directory content:");
|
|
|
|
while (dir.next())
|
|
|
|
{
|
|
|
|
String fileName = dir.fileName();
|
|
|
|
size_t fileSize = dir.fileSize();
|
|
|
|
Serial.printf("Datei Name: %s, Größe: %s\n", fileName.c_str(), formatBytes(fileSize).c_str());
|
|
|
|
}
|
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
if (EEPROM.read(EEPROM_DYNAMIC_IP_ADDRESS) == 0)
|
|
|
|
{
|
2023-04-25 15:35:04 +02:00
|
|
|
WiFi.config(strip_ip, gateway_ip, subnet_mask, dns);
|
2023-04-25 08:18:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
read_eeprom_config();
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
for (int j = 0; j < 200; j++)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
lightEngine();
|
|
|
|
}
|
|
|
|
|
|
|
|
WiFi.mode(WIFI_STA);
|
|
|
|
WiFiManager wifiManager;
|
|
|
|
wifiManager.setConfigPortalTimeout(120);
|
2023-05-03 11:51:37 +02:00
|
|
|
wifiManager.autoConnect(LIGHT_NAME);
|
2023-04-24 20:26:49 +02:00
|
|
|
|
|
|
|
IPAddress myIP = WiFi.localIP();
|
|
|
|
Serial.print("IP: ");
|
|
|
|
Serial.println(myIP);
|
|
|
|
|
2023-04-30 19:54:16 +02:00
|
|
|
analogWriteFreq(PWM_FREQ);
|
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
if (!light_state[0])
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
// Show that we are connected
|
|
|
|
analogWrite(pins[0], 100);
|
|
|
|
delay(500);
|
|
|
|
analogWrite(pins[0], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
WiFi.macAddress(mac);
|
|
|
|
|
|
|
|
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
|
|
|
|
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
|
|
|
|
|
2023-04-27 16:40:27 +02:00
|
|
|
httpUpdateServer.setup(&server); // start http server
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-04-25 08:18:36 +02:00
|
|
|
init_webserver();
|
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
Serial.println("Init timinc control");
|
2023-04-25 08:18:36 +02:00
|
|
|
tc_init();
|
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
Serial.println("Starting webserver");
|
2023-04-25 08:18:36 +02:00
|
|
|
server.begin();
|
2023-04-27 16:40:27 +02:00
|
|
|
} // end of setup
|
2023-04-25 08:18:36 +02:00
|
|
|
|
2023-04-25 14:32:42 +02:00
|
|
|
//********************************//
|
|
|
|
|
2023-04-28 10:56:26 +02:00
|
|
|
void loop()
|
|
|
|
{
|
2023-04-25 08:18:36 +02:00
|
|
|
server.handleClient();
|
2023-05-11 16:48:59 +02:00
|
|
|
|
|
|
|
ESP.wdtFeed();
|
|
|
|
|
2023-04-25 08:18:36 +02:00
|
|
|
lightEngine();
|
|
|
|
|
2023-05-11 18:21:55 +02:00
|
|
|
//Serial.println("tc_enabled = " + (String)tc_enabled);
|
|
|
|
tc_update_loop();
|
2023-05-11 16:48:59 +02:00
|
|
|
|
|
|
|
ESP.wdtFeed();
|
|
|
|
|
|
|
|
test_pwm_main();
|
|
|
|
delay(100);
|
2023-04-25 08:18:36 +02:00
|
|
|
}
|
|
|
|
|
2023-04-25 14:32:42 +02:00
|
|
|
//********************************//
|
|
|
|
|
2023-04-28 12:01:50 +02:00
|
|
|
void handleNotFound()
|
|
|
|
{
|
2023-04-25 08:18:36 +02:00
|
|
|
String message = "File Not Found\n\n";
|
|
|
|
message += "URI: ";
|
|
|
|
message += server.uri();
|
|
|
|
message += "\nMethod: ";
|
|
|
|
message += (server.method() == HTTP_GET) ? "GET" : "POST";
|
|
|
|
message += "\nArguments: ";
|
|
|
|
message += server.args();
|
|
|
|
message += "\n";
|
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
for (uint8_t i = 0; i < server.args(); i++)
|
|
|
|
{
|
2023-04-25 08:18:36 +02:00
|
|
|
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
|
|
|
|
}
|
|
|
|
server.send(404, "text/plain", message);
|
|
|
|
}
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-04-25 14:32:42 +02:00
|
|
|
//********************************//
|
|
|
|
|
2023-04-28 12:01:50 +02:00
|
|
|
void init_webserver()
|
|
|
|
{
|
2023-04-25 14:32:42 +02:00
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
server.on("/state", HTTP_PUT, []()
|
|
|
|
{ // HTTP PUT request used to set a new light state
|
2023-05-11 11:48:07 +02:00
|
|
|
DynamicJsonDocument root(512);
|
2023-04-24 20:26:49 +02:00
|
|
|
DeserializationError error = deserializeJson(root, server.arg("plain"));
|
|
|
|
|
2023-04-27 16:40:27 +02:00
|
|
|
if (error) {
|
2023-04-24 20:26:49 +02:00
|
|
|
server.send(404, "text/plain", "FAIL. " + server.arg("plain"));
|
|
|
|
} else {
|
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
for (JsonPair state : root.as<JsonObject>())
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
const char* key = state.key().c_str();
|
|
|
|
int light = atoi(key) - 1;
|
2023-05-12 11:43:27 +02:00
|
|
|
if (light < 0)
|
|
|
|
{
|
|
|
|
light = 0;
|
|
|
|
} else if (light > (LIGHTS_COUNT-1))
|
|
|
|
{
|
|
|
|
light = (LIGHTS_COUNT-1);
|
|
|
|
}
|
2023-04-24 20:26:49 +02:00
|
|
|
JsonObject values = state.value();
|
|
|
|
|
2023-04-25 08:18:36 +02:00
|
|
|
uint8_t tmp = EEPROM.read(EEPROM_LAST_STATE_STARTUP_ADDRESS);
|
2023-04-29 12:05:13 +02:00
|
|
|
if (values.containsKey("on"))
|
|
|
|
{
|
|
|
|
if (values["on"])
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
light_state[light] = true;
|
2023-04-29 12:05:13 +02:00
|
|
|
if (tmp == LAST_STATE_STARTUP_LIGHT_LAST_STATE && EEPROM.read(EEPROM_LAST_STATE_ADDRESS + light) == LIGHT_STATE_OFF)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
EEPROM.write(EEPROM_LAST_STATE_ADDRESS + light, LIGHT_STATE_ON);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
light_state[light] = false;
|
2023-04-29 12:05:13 +02:00
|
|
|
if (tmp == LAST_STATE_STARTUP_LIGHT_LAST_STATE && EEPROM.read(EEPROM_LAST_STATE_ADDRESS + light) == LIGHT_STATE_ON)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
EEPROM.write(EEPROM_LAST_STATE_ADDRESS + light, LIGHT_STATE_OFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
if (values.containsKey("bri"))
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
bri[light] = values["bri"];
|
|
|
|
}
|
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
if (values.containsKey("bri_inc"))
|
|
|
|
{
|
2023-04-27 16:40:27 +02:00
|
|
|
bri[light] += (int)values["bri_inc"];
|
2023-04-24 20:26:49 +02:00
|
|
|
if (bri[light] > 255) bri[light] = 255;
|
|
|
|
else if (bri[light] < 1) bri[light] = 1;
|
|
|
|
}
|
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
if (values.containsKey("transitiontime"))
|
|
|
|
{
|
2023-04-29 12:40:14 +02:00
|
|
|
default_transitiontime = values["transitiontime"];
|
2023-05-12 11:43:27 +02:00
|
|
|
if (default_transitiontime < 0)
|
|
|
|
{
|
|
|
|
default_transitiontime = 0;
|
|
|
|
}
|
2023-04-29 12:40:14 +02:00
|
|
|
if (tc_enabled == TIMING_CONTROL_DISABLED)
|
|
|
|
{
|
|
|
|
for (uint8_t i = 0 ; i < LIGHTS_COUNT; i++)
|
|
|
|
{
|
|
|
|
// set the default transition time for all lights
|
|
|
|
process_lightdata(i, default_transitiontime);
|
|
|
|
}
|
|
|
|
}
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
2023-04-29 12:40:14 +02:00
|
|
|
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
|
|
|
String output;
|
|
|
|
serializeJson(root, output);
|
|
|
|
server.send(200, "text/plain", output);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
server.on("/state", HTTP_GET, []()
|
|
|
|
{ // HTTP GET request used to fetch current light state
|
2023-04-24 20:26:49 +02:00
|
|
|
uint8_t light = server.arg("light").toInt() - 1;
|
2023-05-12 11:43:27 +02:00
|
|
|
if (light < 0)
|
|
|
|
{
|
|
|
|
light = 0;
|
|
|
|
} else if (light > (LIGHTS_COUNT-1))
|
|
|
|
{
|
|
|
|
light = (LIGHTS_COUNT-1);
|
|
|
|
}
|
2023-05-11 11:48:07 +02:00
|
|
|
DynamicJsonDocument root(512);
|
|
|
|
root["on"] = light_state[light];
|
|
|
|
root["bri"] = bri[light];
|
2023-04-28 10:56:26 +02:00
|
|
|
root["curbri"] = (int)current_bri[light];
|
2023-04-28 12:01:50 +02:00
|
|
|
root["curpwm"] = current_pwm[light];
|
2023-04-24 20:26:49 +02:00
|
|
|
String output;
|
|
|
|
serializeJson(root, output);
|
|
|
|
server.send(200, "text/plain", output);
|
|
|
|
});
|
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
server.on("/detect", []()
|
|
|
|
{ // HTTP GET request used to discover the light type
|
2023-04-27 16:40:27 +02:00
|
|
|
char macString[32] = { 0 };
|
2023-04-24 20:26:49 +02:00
|
|
|
sprintf(macString, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
|
|
|
DynamicJsonDocument root(1024);
|
2023-05-11 16:48:59 +02:00
|
|
|
root["name"] = LIGHT_NAME;
|
|
|
|
root["lights"] = LIGHTS_COUNT;
|
2023-04-24 20:26:49 +02:00
|
|
|
root["protocol"] = "native_multi";
|
2023-05-11 16:48:59 +02:00
|
|
|
root["modelid"] = "LWB010";
|
|
|
|
root["type"] = "dimmable_light";
|
|
|
|
root["mac"] = String(macString);
|
|
|
|
root["version"] = LIGHT_VERSION;
|
2023-04-24 20:26:49 +02:00
|
|
|
String output;
|
|
|
|
serializeJson(root, output);
|
|
|
|
server.send(200, "text/plain", output);
|
|
|
|
});
|
|
|
|
|
2023-05-11 16:48:59 +02:00
|
|
|
server.on("/test_pwm", []()
|
|
|
|
{
|
|
|
|
test_pwm = true;
|
|
|
|
tc_enabled_old = tc_enabled;
|
2023-05-11 18:17:08 +02:00
|
|
|
tc_enabled = TIMING_CONTROL_DISABLED;
|
2023-05-11 16:48:59 +02:00
|
|
|
|
|
|
|
server.send(200, "text/html", "OK");
|
|
|
|
});
|
|
|
|
|
2023-05-04 18:24:41 +02:00
|
|
|
server.on("/tc_data_blocks_read", []()
|
2023-04-29 12:05:13 +02:00
|
|
|
{
|
2023-04-27 13:39:07 +02:00
|
|
|
String output = tc_getJsonData();
|
|
|
|
|
|
|
|
server.send(200, "application/json", output);
|
|
|
|
});
|
|
|
|
|
2023-05-04 18:24:41 +02:00
|
|
|
server.on("/tc_data_blocks_store", []()
|
|
|
|
{
|
|
|
|
if (server.hasArg("data"))
|
|
|
|
{
|
|
|
|
String jsonData = server.arg("data");
|
2023-05-06 13:38:56 +02:00
|
|
|
Serial.println("Received: " + jsonData);
|
2023-05-04 18:24:41 +02:00
|
|
|
tc_jsonDataBlocksToEEPROM(jsonData);
|
|
|
|
server.send(200, "text/html", "tcdata saved");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-05-05 08:21:09 +02:00
|
|
|
server.on("/js_top", []()
|
2023-05-04 18:24:41 +02:00
|
|
|
{
|
2023-05-05 08:21:09 +02:00
|
|
|
server.send(200, "text/html", replacePlaceholder(loadSPIFFSFile("/top.js")));
|
|
|
|
});
|
|
|
|
|
|
|
|
server.on("/js_bottom", []()
|
|
|
|
{
|
|
|
|
server.send(200, "text/html", replacePlaceholder(loadSPIFFSFile("/bottom.js")));
|
|
|
|
});
|
|
|
|
|
|
|
|
server.on("/css", []()
|
|
|
|
{
|
2023-05-05 10:56:16 +02:00
|
|
|
server.send(200, "text/css", loadSPIFFSFile("/style.css"));
|
2023-05-04 18:24:41 +02:00
|
|
|
});
|
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
server.on("/", []()
|
|
|
|
{
|
2023-04-25 14:32:42 +02:00
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
if (server.hasArg("transition"))
|
|
|
|
{
|
2023-04-29 12:40:14 +02:00
|
|
|
default_transitiontime = server.arg("transition").toFloat();
|
2023-05-12 11:43:27 +02:00
|
|
|
if (default_transitiontime < 0)
|
|
|
|
{
|
|
|
|
default_transitiontime = 0;
|
|
|
|
}
|
2023-04-29 12:40:14 +02:00
|
|
|
if (tc_enabled == TIMING_CONTROL_DISABLED)
|
|
|
|
{
|
|
|
|
for (uint8_t i = 0 ; i < LIGHTS_COUNT; i++)
|
|
|
|
{
|
|
|
|
// set the default transition time for all lights
|
|
|
|
process_lightdata(i, default_transitiontime);
|
2023-05-02 14:32:40 +02:00
|
|
|
Serial.println("transition for light " + (String)i + " set to " + (String)default_transitiontime);
|
2023-04-29 12:40:14 +02:00
|
|
|
}
|
|
|
|
}
|
2023-04-25 08:18:36 +02:00
|
|
|
}
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-04-25 08:18:36 +02:00
|
|
|
// startup behavior switch handling
|
2023-04-29 12:05:13 +02:00
|
|
|
if (server.hasArg("startup"))
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
int startup = server.arg("startup").toInt();
|
2023-04-29 12:05:13 +02:00
|
|
|
if (EEPROM.read(EEPROM_LAST_STATE_STARTUP_ADDRESS) != startup)
|
|
|
|
{
|
2023-04-25 08:18:36 +02:00
|
|
|
EEPROM.write(EEPROM_LAST_STATE_STARTUP_ADDRESS, startup);
|
2023-04-25 14:32:42 +02:00
|
|
|
|
2023-04-27 16:40:27 +02:00
|
|
|
for (uint8_t i = 0; i < LIGHTS_COUNT; i++) {
|
2023-04-25 14:32:42 +02:00
|
|
|
uint8_t tmp = (light_state[i] == true ? LIGHT_STATE_ON : LIGHT_STATE_OFF);
|
2023-04-29 12:05:13 +02:00
|
|
|
if (EEPROM.read(EEPROM_LAST_STATE_ADDRESS + i) != tmp)
|
|
|
|
{
|
2023-04-25 14:32:42 +02:00
|
|
|
EEPROM.write(EEPROM_LAST_STATE_ADDRESS + i, tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-25 08:18:36 +02:00
|
|
|
EEPROM.commit();
|
2023-04-27 16:40:27 +02:00
|
|
|
Serial.print("Startup behavior set to ");
|
|
|
|
Serial.println(EEPROM.read(EEPROM_LAST_STATE_STARTUP_ADDRESS));
|
2023-04-25 08:18:36 +02:00
|
|
|
}
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
|
|
|
|
2023-04-25 08:18:36 +02:00
|
|
|
// timing controller switch handling
|
2023-04-29 12:05:13 +02:00
|
|
|
if (server.hasArg("tc"))
|
|
|
|
{
|
|
|
|
if (server.arg("tc") == "true")
|
|
|
|
{
|
|
|
|
if (tc_enabled == TIMING_CONTROL_DISABLED)
|
|
|
|
{
|
|
|
|
if (EEPROM.read(EEPROM_TIMING_CONTROL_ENABLED_ADDRESS) != TIMING_CONTROL_ENABLED)
|
|
|
|
{
|
2023-04-25 08:18:36 +02:00
|
|
|
tc_enabled = TIMING_CONTROL_ENABLED;
|
|
|
|
EEPROM.write(EEPROM_TIMING_CONTROL_ENABLED_ADDRESS, TIMING_CONTROL_ENABLED);
|
|
|
|
EEPROM.commit();
|
2023-04-27 16:40:27 +02:00
|
|
|
Serial.print("Timing control = ");
|
|
|
|
Serial.println(EEPROM.read(EEPROM_TIMING_CONTROL_ENABLED_ADDRESS));
|
2023-04-29 12:40:14 +02:00
|
|
|
tc_update_main(); // call the main update function to read data and set the light states
|
2023-04-25 08:18:36 +02:00
|
|
|
}
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
|
|
|
|
2023-04-27 16:40:27 +02:00
|
|
|
} else { // tc is set to false or something else
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
if (tc_enabled == TIMING_CONTROL_ENABLED)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
tc_enabled = TIMING_CONTROL_DISABLED;
|
2023-04-29 12:05:13 +02:00
|
|
|
if (EEPROM.read(EEPROM_TIMING_CONTROL_ENABLED_ADDRESS) != TIMING_CONTROL_DISABLED)
|
|
|
|
{
|
2023-04-25 08:18:36 +02:00
|
|
|
EEPROM.write(EEPROM_TIMING_CONTROL_ENABLED_ADDRESS, TIMING_CONTROL_DISABLED);
|
|
|
|
EEPROM.commit();
|
2023-04-27 16:40:27 +02:00
|
|
|
Serial.print("Timing control = ");
|
|
|
|
Serial.println(EEPROM.read(EEPROM_TIMING_CONTROL_ENABLED_ADDRESS));
|
2023-04-29 12:40:14 +02:00
|
|
|
|
|
|
|
for (uint8_t i = 0 ; i < LIGHTS_COUNT; i++)
|
|
|
|
{
|
|
|
|
// set the default transition time for all lights
|
|
|
|
process_lightdata(i, default_transitiontime);
|
|
|
|
}
|
2023-04-25 08:18:36 +02:00
|
|
|
}
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-25 08:18:36 +02:00
|
|
|
// scene switch handling
|
2023-05-12 11:43:27 +02:00
|
|
|
if (server.hasArg("scene"))
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
scene = server.arg("scene").toInt();
|
2023-05-12 11:43:27 +02:00
|
|
|
if (EEPROM.read(EEPROM_SCENE_ADDRESS) != scene)
|
|
|
|
{
|
2023-04-25 08:18:36 +02:00
|
|
|
EEPROM.write(EEPROM_SCENE_ADDRESS, scene);
|
|
|
|
EEPROM.commit();
|
2023-04-27 16:40:27 +02:00
|
|
|
Serial.print("Scene set to ");
|
|
|
|
Serial.println(EEPROM.read(EEPROM_SCENE_ADDRESS));
|
2023-04-25 08:18:36 +02:00
|
|
|
}
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
|
|
|
|
2023-04-27 16:40:27 +02:00
|
|
|
if (server.hasArg("dip")) {
|
2023-04-25 14:32:42 +02:00
|
|
|
uint8_t tmp = EEPROM.read(EEPROM_DYNAMIC_IP_ADDRESS);
|
|
|
|
uint8_t tmp2 = (server.arg("dip") == "true" ? 1 : 0);
|
2023-05-12 11:43:27 +02:00
|
|
|
if (tmp != tmp2)
|
|
|
|
{
|
2023-04-25 14:32:42 +02:00
|
|
|
EEPROM.write(EEPROM_DYNAMIC_IP_ADDRESS, tmp2);
|
|
|
|
EEPROM.commit();
|
2023-04-27 16:40:27 +02:00
|
|
|
Serial.print("Set dynamic IP to ");
|
|
|
|
Serial.println(EEPROM.read(EEPROM_DYNAMIC_IP_ADDRESS));
|
2023-04-25 14:32:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-25 08:18:36 +02:00
|
|
|
// process the received data for every light
|
2023-04-29 12:40:14 +02:00
|
|
|
for (int light = 0; light < LIGHTS_COUNT; light++)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-04-29 12:05:13 +02:00
|
|
|
if (server.hasArg("bri" + (String)light))
|
|
|
|
{
|
2023-05-11 19:37:17 +02:00
|
|
|
int tmp = (int)server.arg("bri" + (String)light).toInt();
|
|
|
|
|
|
|
|
if (tmp > 255)
|
|
|
|
{
|
|
|
|
tmp = 255;
|
|
|
|
} else if (tmp < 0) {
|
|
|
|
tmp = 0;
|
|
|
|
}
|
|
|
|
bri[light] = tmp;
|
2023-04-27 19:26:06 +02:00
|
|
|
Serial.print("Brightness ");
|
|
|
|
Serial.print(light);
|
|
|
|
Serial.print(" set to ");
|
2023-04-27 16:40:27 +02:00
|
|
|
Serial.println(bri[light]);
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
2023-04-27 16:40:27 +02:00
|
|
|
|
2023-04-29 12:40:14 +02:00
|
|
|
if (server.hasArg("on" + (String)light))
|
|
|
|
{
|
2023-04-25 08:18:36 +02:00
|
|
|
uint8_t tmp = EEPROM.read(EEPROM_LAST_STATE_STARTUP_ADDRESS);
|
2023-04-29 12:40:14 +02:00
|
|
|
if (server.arg("on" + (String)light) == "true" && light_state[light] == false)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
light_state[light] = true;
|
2023-04-29 12:40:14 +02:00
|
|
|
if (tmp == 0 && EEPROM.read(EEPROM_LAST_STATE_ADDRESS + light) == 0)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
EEPROM.write(EEPROM_LAST_STATE_ADDRESS + light, LIGHT_STATE_ON);
|
2023-05-02 13:46:25 +02:00
|
|
|
EEPROM.commit();
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
2023-04-27 16:40:27 +02:00
|
|
|
Serial.print("Light ");
|
|
|
|
Serial.print(light);
|
|
|
|
Serial.print(" state set to ");
|
|
|
|
Serial.println(light_state[light]);
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-04-29 12:40:14 +02:00
|
|
|
} else if (server.arg("on" + (String)light) == "false" && light_state[light] == true)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
light_state[light] = false;
|
2023-05-12 12:19:00 +02:00
|
|
|
bri[light] = 0;
|
2023-04-29 12:40:14 +02:00
|
|
|
if (tmp == 0 && EEPROM.read(EEPROM_LAST_STATE_ADDRESS + light) == 1)
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
EEPROM.write(EEPROM_LAST_STATE_ADDRESS + light, LIGHT_STATE_OFF);
|
2023-05-02 13:46:25 +02:00
|
|
|
EEPROM.commit();
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
2023-04-27 16:40:27 +02:00
|
|
|
Serial.print("Light ");
|
|
|
|
Serial.print(light);
|
|
|
|
Serial.print(" state set to ");
|
|
|
|
Serial.println(light_state[light]);
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
|
|
|
|
2023-04-29 14:31:49 +02:00
|
|
|
if (tc_enabled == TIMING_CONTROL_DISABLED)
|
|
|
|
{
|
|
|
|
process_lightdata(light, default_transitiontime);
|
|
|
|
}
|
2023-04-29 12:40:14 +02:00
|
|
|
} else {
|
|
|
|
// light is off
|
|
|
|
if (tc_enabled == TIMING_CONTROL_DISABLED)
|
|
|
|
{
|
|
|
|
process_lightdata(light, default_transitiontime);
|
|
|
|
}
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
|
|
|
|
2023-04-25 08:18:36 +02:00
|
|
|
// start alerting for every light
|
2023-04-29 12:40:14 +02:00
|
|
|
if (server.hasArg("alert"))
|
|
|
|
{
|
|
|
|
if (light_state[light])
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
current_bri[light] = 0;
|
|
|
|
} else {
|
|
|
|
current_bri[light] = 255;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-27 16:40:27 +02:00
|
|
|
} // process all lights
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
if (server.hasArg("resettc"))
|
|
|
|
{ // reqrite the tc config and reboot
|
2023-04-24 20:26:49 +02:00
|
|
|
tc_write_default();
|
|
|
|
ESP.reset();
|
|
|
|
}
|
|
|
|
|
2023-05-01 18:37:33 +02:00
|
|
|
if (server.hasArg("reset"))
|
|
|
|
{
|
2023-04-24 20:26:49 +02:00
|
|
|
ESP.reset();
|
|
|
|
}
|
|
|
|
|
2023-05-11 11:48:07 +02:00
|
|
|
// ***** Generate static HTML page ***** //
|
2023-05-02 09:04:21 +02:00
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
String tmp1 = genHMTLTop();
|
|
|
|
|
|
|
|
String tmp2 = genLightControlHTML();
|
|
|
|
|
|
|
|
String tmp3 = getIndexHTMLMiddle();
|
|
|
|
|
|
|
|
String tmp4 = genConfigHTML();
|
|
|
|
|
|
|
|
String tmp5 = genHMTLBottom();
|
|
|
|
|
|
|
|
server.send(200, "text/html", tmp1 + tmp2 + tmp3 + tmp4 + tmp5);
|
|
|
|
|
2023-05-02 09:04:21 +02:00
|
|
|
});
|
2023-05-01 19:23:31 +02:00
|
|
|
|
2023-05-02 09:04:21 +02:00
|
|
|
server.on("/reset", []()
|
2023-05-02 13:46:25 +02:00
|
|
|
{ // trigger manual reset
|
2023-05-02 09:04:21 +02:00
|
|
|
server.send(200, "text/html", "reset");
|
|
|
|
delay(1000);
|
|
|
|
ESP.restart();
|
|
|
|
});
|
2023-05-01 19:23:31 +02:00
|
|
|
|
2023-05-02 09:04:21 +02:00
|
|
|
server.onNotFound(handleNotFound);
|
|
|
|
}
|
2023-05-02 08:03:14 +02:00
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
//********************************//
|
|
|
|
|
|
|
|
String genHMTLTop()
|
|
|
|
{
|
|
|
|
return replacePlaceholder(getIndexHTMLTop());
|
|
|
|
}
|
|
|
|
|
|
|
|
String genHMTLBottom()
|
|
|
|
{
|
|
|
|
return replacePlaceholder(getIndexHTMLBottom());
|
|
|
|
}
|
|
|
|
|
|
|
|
String genConfigHTML()
|
|
|
|
{
|
|
|
|
// +++++ Generate config part of the page +++++
|
|
|
|
return replacePlaceholder(getConfigHTML());
|
|
|
|
}
|
|
|
|
|
2023-05-04 18:24:41 +02:00
|
|
|
String genTCEditHTML()
|
|
|
|
{
|
|
|
|
return replacePlaceholder(getTCDataEditHTML());
|
|
|
|
}
|
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
String genLightControlHTML()
|
|
|
|
{
|
|
|
|
String http_content = "";
|
|
|
|
// +++++ Generate lights part of the HTML page +++++
|
|
|
|
// Light control
|
|
|
|
for (uint8 light_num = 0; light_num < LIGHTS_COUNT; light_num++)
|
|
|
|
{
|
|
|
|
// Generate lights part of the HTML page
|
|
|
|
String tmp_light_content = getLightControlHTML();
|
|
|
|
|
|
|
|
// on/off buttons and slider
|
|
|
|
tmp_light_content.replace("{{LIGHT_NUMBER}}", (String)(light_num + 1));
|
|
|
|
tmp_light_content.replace("{{LIGHT_NUMBER_DEC}}", (String)light_num);
|
|
|
|
|
|
|
|
// add the lights code to the html output string
|
|
|
|
http_content += tmp_light_content;
|
|
|
|
}
|
|
|
|
return http_content;
|
|
|
|
}
|
|
|
|
|
|
|
|
//********************************//
|
|
|
|
|
|
|
|
String replacePlaceholder(String http_content)
|
2023-05-02 09:04:21 +02:00
|
|
|
{
|
2023-05-01 19:23:31 +02:00
|
|
|
|
2023-05-03 11:51:37 +02:00
|
|
|
http_content.replace("{{LIGHT_NAME}}", (String)LIGHT_NAME);
|
2023-05-01 19:23:31 +02:00
|
|
|
|
2023-05-02 09:04:21 +02:00
|
|
|
http_content.replace("{{LIGHT_COUNT}}", (String)LIGHTS_COUNT);
|
2023-05-01 18:37:33 +02:00
|
|
|
|
2023-05-02 09:04:21 +02:00
|
|
|
int tc_val = EEPROM.read(EEPROM_TIMING_CONTROL_ENABLED_ADDRESS);
|
|
|
|
if (tc_val == TIMING_CONTROL_ENABLED)
|
|
|
|
{
|
|
|
|
http_content.replace("{{TC_LINK_PRIMARY_ON}}", "pure-button-primary");
|
2023-05-03 14:05:04 +02:00
|
|
|
|
2023-05-02 09:04:21 +02:00
|
|
|
} else {
|
|
|
|
http_content.replace("{{TC_LINK_PRIMARY_ON}}", "");
|
|
|
|
}
|
|
|
|
if (tc_val == TIMING_CONTROL_DISABLED)
|
|
|
|
{
|
|
|
|
http_content.replace("{{TC_LINK_PRIMARY_OFF}}", "pure-button-primary");
|
2023-05-03 14:05:04 +02:00
|
|
|
|
2023-05-02 09:04:21 +02:00
|
|
|
} else {
|
|
|
|
http_content.replace("{{TC_LINK_PRIMARY_OFF}}", "");
|
|
|
|
}
|
2023-05-01 19:23:31 +02:00
|
|
|
|
2023-05-02 09:04:21 +02:00
|
|
|
http_content.replace("{{TRANSITION_TIME}}", (String)default_transitiontime);
|
2023-05-01 19:23:31 +02:00
|
|
|
|
2023-05-02 09:04:21 +02:00
|
|
|
int ls_val = EEPROM.read(EEPROM_LAST_STATE_STARTUP_ADDRESS);
|
|
|
|
if (ls_val == LAST_STATE_STARTUP_LIGHT_LAST_STATE)
|
|
|
|
{
|
|
|
|
http_content.replace("{{STARTUP_SELECTED_LS_0}}", "selected=\"selected\"");
|
|
|
|
} else {
|
|
|
|
http_content.replace("{{STARTUP_SELECTED_LS_0}}", "");
|
|
|
|
}
|
2023-05-01 19:23:31 +02:00
|
|
|
|
2023-05-02 09:04:21 +02:00
|
|
|
if (ls_val == LAST_STATE_STARTUP_LIGHT_ON_STATE)
|
|
|
|
{
|
|
|
|
http_content.replace("{{STARTUP_SELECTED_ON_1}}", "selected=\"selected\"");
|
|
|
|
} else {
|
|
|
|
http_content.replace("{{STARTUP_SELECTED_ON_1}}", "");
|
|
|
|
}
|
2023-05-01 19:23:31 +02:00
|
|
|
|
2023-05-02 09:04:21 +02:00
|
|
|
if (ls_val == LAST_STATE_STARTUP_LIGHT_OFF_STATE)
|
|
|
|
{
|
|
|
|
http_content.replace("{{STARTUP_SELECTED_OFF_2}}", "selected=\"selected\"");
|
|
|
|
} else {
|
|
|
|
http_content.replace("{{STARTUP_SELECTED_OFF_2}}", "");
|
|
|
|
}
|
2023-05-01 19:23:31 +02:00
|
|
|
|
2023-05-02 09:04:21 +02:00
|
|
|
// scene
|
|
|
|
int sc_val = EEPROM.read(EEPROM_SCENE_ADDRESS);
|
|
|
|
if (sc_val == SCENE_RELEAX)
|
|
|
|
{
|
|
|
|
http_content.replace("{{SCENE_SELECTED_RELAX_0}}", "selected=\"selected\"");
|
|
|
|
} else {
|
|
|
|
http_content.replace("{{SCENE_SELECTED_RELAX_0}}", "");
|
|
|
|
}
|
|
|
|
if (sc_val == SCENE_BRIGHT)
|
|
|
|
{
|
|
|
|
http_content.replace("{{SCENE_SELECTED_BRIGHT_1}}", "selected=\"selected\"");
|
|
|
|
} else {
|
|
|
|
http_content.replace("{{SCENE_SELECTED_BRIGHT_1}}", "");
|
|
|
|
}
|
|
|
|
if (sc_val == SCENE_NIGHTLY)
|
|
|
|
{
|
|
|
|
http_content.replace("{{SCENE_SELECTED_NIGHT_2}}", "selected=\"selected\"");
|
|
|
|
} else {
|
|
|
|
http_content.replace("{{SCENE_SELECTED_NIGHT_2}}", "");
|
|
|
|
}
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-05-02 09:04:21 +02:00
|
|
|
// Wifi settings
|
2023-05-02 13:46:25 +02:00
|
|
|
http_content.replace("{{WIFI_SSID}}", WiFi.SSID());
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-05-02 09:04:21 +02:00
|
|
|
// Network settings
|
|
|
|
uint8_t dip = EEPROM.read(EEPROM_DYNAMIC_IP_ADDRESS);
|
|
|
|
if (dip)
|
|
|
|
{
|
2023-05-02 13:46:25 +02:00
|
|
|
http_content.replace("{{DIP_LINK_ON_PRIMARY}}", "pure-button-primary");
|
|
|
|
http_content.replace("{{DIP_LINK_OFF_PRIMARY}}", "");
|
2023-05-02 09:04:21 +02:00
|
|
|
} else {
|
2023-05-02 13:46:25 +02:00
|
|
|
http_content.replace("{{DIP_LINK_OFF_PRIMARY}}", "pure-button-primary");
|
|
|
|
http_content.replace("{{DIP_LINK_ON_PRIMARY}}", "");
|
2023-05-02 09:04:21 +02:00
|
|
|
}
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
// network config
|
|
|
|
http_content.replace("{{WIFI_CFG_IP}}", WiFi.localIP().toString());
|
|
|
|
http_content.replace("{{WIFI_CFG_GW}}", WiFi.gatewayIP().toString());
|
|
|
|
http_content.replace("{{WIFI_CFG_NM}}", WiFi.subnetMask().toString());
|
|
|
|
http_content.replace("{{WIFI_CFG_DNS}}", WiFi.dnsIP().toString());
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
// add the current ip address to the page
|
2023-05-02 09:04:21 +02:00
|
|
|
http_content.replace("{{IP_ADDRESS}}", WiFi.localIP().toString());
|
|
|
|
|
|
|
|
// set the pwm values
|
|
|
|
http_content.replace("{{PWM_MIN}}", (String)PWM_MIN);
|
|
|
|
http_content.replace("{{PWM_MAX}}", (String)PWM_MAX);
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-05-02 09:04:21 +02:00
|
|
|
return http_content;
|
|
|
|
}
|
2023-05-01 19:23:31 +02:00
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
//********************************//
|
|
|
|
|
|
|
|
String loadSPIFFSFile(String fname)
|
2023-05-02 09:04:21 +02:00
|
|
|
{
|
2023-05-02 13:46:25 +02:00
|
|
|
File file = SPIFFS.open(fname, "r");
|
|
|
|
if (!file)
|
2023-05-02 09:04:21 +02:00
|
|
|
{
|
2023-05-02 13:46:25 +02:00
|
|
|
Serial.println("Failed to open file " + fname);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
String contents = file.readString();
|
|
|
|
file.close();
|
|
|
|
return contents;
|
|
|
|
}
|
2023-05-02 08:03:14 +02:00
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
//********************************//
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
String getIndexHTMLTop()
|
|
|
|
{
|
|
|
|
// load file
|
|
|
|
return loadSPIFFSFile("/index_template_top.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
String getIndexHTMLMiddle()
|
|
|
|
{
|
|
|
|
// load file
|
|
|
|
return loadSPIFFSFile("/index_template_middle.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
String getIndexHTMLBottom()
|
|
|
|
{
|
|
|
|
// load file
|
|
|
|
return loadSPIFFSFile("/index_template_bottom.html");
|
|
|
|
}
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
//********************************//
|
2023-04-24 20:26:49 +02:00
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
String getConfigHTML()
|
|
|
|
{
|
|
|
|
// load file
|
|
|
|
return loadSPIFFSFile("/config_template.html");
|
2023-04-24 20:26:49 +02:00
|
|
|
}
|
2023-05-02 13:46:25 +02:00
|
|
|
|
|
|
|
//********************************//
|
|
|
|
|
2023-05-04 18:24:41 +02:00
|
|
|
String getTCDataEditHTML()
|
|
|
|
{
|
|
|
|
// load file
|
|
|
|
return loadSPIFFSFile("/tc_data_edit.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
//********************************//
|
|
|
|
|
2023-05-02 13:46:25 +02:00
|
|
|
String getLightControlHTML()
|
|
|
|
{
|
|
|
|
// load file
|
|
|
|
return loadSPIFFSFile("/light_control_template.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
//********************************//
|
|
|
|
|
|
|
|
String formatBytes(size_t bytes)
|
|
|
|
{
|
|
|
|
if (bytes < 1024)
|
|
|
|
{
|
|
|
|
return String(bytes) + " B";
|
|
|
|
} else if (bytes < (1024 * 1024))
|
|
|
|
{
|
|
|
|
return String(bytes / 1024.0) + " KB";
|
|
|
|
} else if (bytes < (1024 * 1024 * 1024))
|
|
|
|
{
|
|
|
|
return String(bytes / 1024.0 / 1024.0) + " MB";
|
|
|
|
} else {
|
|
|
|
return String(bytes / 1024.0 / 1024.0 / 1024.0) + " GB";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//********************************//
|
2023-05-11 16:48:59 +02:00
|
|
|
|
|
|
|
void test_pwm_main()
|
|
|
|
{
|
|
|
|
if (test_pwm == false)
|
|
|
|
{
|
|
|
|
return;
|
2023-05-11 18:17:08 +02:00
|
|
|
} else if ((test_pwm_lastcheck_ms + PWM_TEST_INTERVA_MS) <= millis())
|
2023-05-11 16:48:59 +02:00
|
|
|
{
|
|
|
|
test_pwm_lastcheck_ms = millis();
|
|
|
|
|
|
|
|
switch (test_pwm_state)
|
|
|
|
{
|
|
|
|
// ----------------------- //
|
|
|
|
case TEST_PWM_STATE_INIT:
|
|
|
|
// disable the lights
|
|
|
|
for (uint8_t i = 0; i < LIGHTS_COUNT; i++)
|
|
|
|
{
|
|
|
|
light_state[i] = false;
|
|
|
|
bri[i] = 0;
|
|
|
|
current_bri[i] = 0;
|
|
|
|
current_pwm[i] = 0;
|
|
|
|
transitiontime[i] = 0;
|
|
|
|
process_lightdata(i, transitiontime[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
light_state[0] = true;
|
|
|
|
test_pwm_state = TEST_PWM_STATE_CH1_INC;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// ----------------------- //
|
|
|
|
case TEST_PWM_STATE_CH1_INC:
|
|
|
|
|
2023-05-11 18:17:08 +02:00
|
|
|
if (bri[0] < 255)
|
2023-05-11 16:48:59 +02:00
|
|
|
{
|
|
|
|
bri[0] += TEST_PWM_CHG_CNT;
|
|
|
|
transitiontime[0] = 1;
|
|
|
|
process_lightdata(0, transitiontime[0]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
test_pwm_state = TEST_PWM_STATE_CH1_DEC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TEST_PWM_STATE_CH1_DEC:
|
|
|
|
|
2023-05-11 18:17:08 +02:00
|
|
|
if (bri[0] > 0)
|
2023-05-11 16:48:59 +02:00
|
|
|
{
|
|
|
|
bri[0] -= TEST_PWM_CHG_CNT;
|
|
|
|
transitiontime[0] = 1;
|
|
|
|
process_lightdata(0, transitiontime[0]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
light_state[0] = false;
|
2023-05-11 18:17:08 +02:00
|
|
|
bri[0] = 0;
|
|
|
|
current_bri[0] = 0;
|
|
|
|
current_pwm[0] = 0;
|
2023-05-11 16:48:59 +02:00
|
|
|
transitiontime[0] = 0;
|
2023-05-11 18:17:08 +02:00
|
|
|
process_lightdata(0, transitiontime[0]);
|
|
|
|
|
2023-05-11 16:48:59 +02:00
|
|
|
light_state[1] = true;
|
|
|
|
test_pwm_state = TEST_PWM_STATE_CH2_INC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// ----------------------- //
|
|
|
|
case TEST_PWM_STATE_CH2_INC:
|
|
|
|
|
2023-05-11 18:17:08 +02:00
|
|
|
if (bri[1] < 255)
|
2023-05-11 16:48:59 +02:00
|
|
|
{
|
|
|
|
bri[1] += TEST_PWM_CHG_CNT;
|
|
|
|
transitiontime[1] = 1;
|
|
|
|
process_lightdata(1, transitiontime[1]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
test_pwm_state = TEST_PWM_STATE_CH2_DEC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TEST_PWM_STATE_CH2_DEC:
|
|
|
|
|
2023-05-11 18:17:08 +02:00
|
|
|
if (bri[1] > 0)
|
2023-05-11 16:48:59 +02:00
|
|
|
{
|
|
|
|
bri[1] -= TEST_PWM_CHG_CNT;
|
|
|
|
transitiontime[1] = 1;
|
|
|
|
process_lightdata(1, transitiontime[1]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
light_state[1] = false;
|
2023-05-11 18:17:08 +02:00
|
|
|
bri[1] = 0;
|
|
|
|
current_bri[1] = 0;
|
|
|
|
current_pwm[1] = 0;
|
2023-05-11 16:48:59 +02:00
|
|
|
transitiontime[1] = 0;
|
2023-05-11 18:17:08 +02:00
|
|
|
process_lightdata(1, transitiontime[1]);
|
|
|
|
|
2023-05-11 16:48:59 +02:00
|
|
|
light_state[2] = true;
|
|
|
|
test_pwm_state = TEST_PWM_STATE_CH3_INC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// ----------------------- //
|
|
|
|
case TEST_PWM_STATE_CH3_INC:
|
|
|
|
|
2023-05-11 18:17:08 +02:00
|
|
|
if (bri[2] < 255)
|
2023-05-11 16:48:59 +02:00
|
|
|
{
|
|
|
|
bri[2] += TEST_PWM_CHG_CNT;
|
|
|
|
transitiontime[2] = 1;
|
|
|
|
process_lightdata(2, transitiontime[2]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
test_pwm_state = TEST_PWM_STATE_CH3_DEC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TEST_PWM_STATE_CH3_DEC:
|
|
|
|
|
2023-05-11 18:17:08 +02:00
|
|
|
if (bri[2] > 0)
|
2023-05-11 16:48:59 +02:00
|
|
|
{
|
|
|
|
bri[2] -= TEST_PWM_CHG_CNT;
|
|
|
|
transitiontime[2] = 1;
|
|
|
|
process_lightdata(2, transitiontime[2]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2023-05-11 18:17:08 +02:00
|
|
|
light_state[2] = false;
|
|
|
|
bri[2] = 0;
|
|
|
|
current_bri[2] = 0;
|
|
|
|
current_pwm[2] = 0;
|
2023-05-11 16:48:59 +02:00
|
|
|
transitiontime[2] = 0;
|
2023-05-11 18:17:08 +02:00
|
|
|
process_lightdata(2, transitiontime[2]);
|
|
|
|
|
2023-05-11 16:48:59 +02:00
|
|
|
light_state[3] = true;
|
|
|
|
test_pwm_state = TEST_PWM_STATE_CH4_INC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// ----------------------- //
|
|
|
|
case TEST_PWM_STATE_CH4_INC:
|
|
|
|
|
2023-05-11 18:17:08 +02:00
|
|
|
if (bri[3] < 255)
|
2023-05-11 16:48:59 +02:00
|
|
|
{
|
|
|
|
bri[3] += TEST_PWM_CHG_CNT;
|
|
|
|
transitiontime[3] = 1;
|
|
|
|
process_lightdata(3, transitiontime[3]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
test_pwm_state = TEST_PWM_STATE_CH4_DEC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TEST_PWM_STATE_CH4_DEC:
|
|
|
|
|
2023-05-11 18:17:08 +02:00
|
|
|
if (bri[3] > 0)
|
2023-05-11 16:48:59 +02:00
|
|
|
{
|
|
|
|
bri[3] -= TEST_PWM_CHG_CNT;
|
|
|
|
transitiontime[3] = 1;
|
|
|
|
process_lightdata(3, transitiontime[3]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
test_pwm = false;
|
|
|
|
tc_enabled = tc_enabled_old;
|
2023-05-11 19:37:17 +02:00
|
|
|
|
2023-05-11 16:48:59 +02:00
|
|
|
for (uint8_t i = 0; i < LIGHTS_COUNT; i++)
|
|
|
|
{
|
|
|
|
light_state[i] = false;
|
|
|
|
bri[i] = 0;
|
|
|
|
current_bri[i] = 0;
|
|
|
|
current_pwm[i] = 0;
|
|
|
|
transitiontime[i] = 0;
|
|
|
|
process_lightdata(i, transitiontime[i]);
|
|
|
|
}
|
2023-05-11 18:21:55 +02:00
|
|
|
|
2023-05-11 19:37:17 +02:00
|
|
|
tc_reset();
|
2023-05-11 18:21:55 +02:00
|
|
|
tc_update_main(); // load the tc if required
|
|
|
|
|
2023-05-11 18:17:08 +02:00
|
|
|
test_pwm_state = TEST_PWM_STATE_INIT;
|
2023-05-11 16:48:59 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// ----------------------- //
|
|
|
|
default:
|
|
|
|
test_pwm_state = TEST_PWM_STATE_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
Serial.println("---");
|
|
|
|
for (uint8_t i = 0; i < LIGHTS_COUNT; i++)
|
|
|
|
{
|
|
|
|
Serial.println("light_state[" + (String)i + "] = " + (String)light_state[i]);
|
|
|
|
Serial.println("bri[" + (String)i + "] = " + (String)bri[i]);
|
|
|
|
Serial.println("current_bri[" + (String)i + "] = " + (String)current_bri[i]);
|
|
|
|
Serial.println("current_pwm[" + (String)i + "] = " + (String)current_pwm[i]);
|
|
|
|
Serial.println("transitiontime[" + (String)i + "] = " + (String)transitiontime[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//********************************//
|