Compare commits

...

2 Commits

5 changed files with 60 additions and 16 deletions

View File

@ -2,5 +2,4 @@
#define GPIO_GREEN 18 #define GPIO_GREEN 18
#define GPIO_BLUE 16 #define GPIO_BLUE 16
#define GPIO_COOLWHITE 15 #define GPIO_COOLWHITE 15
#define GPIO_WARMWHITE 19 #define GPIO_WARMWHITE 19
#define BOARD "ESP32"

5
include/esp32c3.h Normal file
View File

@ -0,0 +1,5 @@
#define GPIO_RED 5
#define GPIO_GREEN 6
#define GPIO_BLUE 7
#define GPIO_COOLWHITE 20
#define GPIO_WARMWHITE 21

View File

@ -2,5 +2,4 @@
#define GPIO_GREEN 12 #define GPIO_GREEN 12
#define GPIO_BLUE 15 #define GPIO_BLUE 15
#define GPIO_COOLWHITE 4 #define GPIO_COOLWHITE 4
#define GPIO_WARMWHITE 5 #define GPIO_WARMWHITE 5
#define BOARD "ESP8266"

View File

@ -10,12 +10,17 @@
[platformio] [platformio]
;default_envs = esp32doit-devkit-v1 ;default_envs = esp32doit-devkit-v1
default_envs = esp32-c3-devkitm-1
;default_envs = nodemcuv2 ;default_envs = nodemcuv2
default_envs = huzzah ;default_envs = huzzah
[common] [common]
build_flags = build_flags =
-D DEBUG=true -D DEBUG=true
-D BOARD_ESP32_DEV=1
-D BOARD_ESP32_C3=2
-D BOARD_ESP8266_DEV=3
-D BOARD_ESP8266_HUZZAH=4
lib_deps = lib_deps =
tzapu/WiFiManager@^2.0.17 tzapu/WiFiManager@^2.0.17
@ -24,26 +29,46 @@ platform = espressif32
board = esp32doit-devkit-v1 board = esp32doit-devkit-v1
framework = arduino framework = arduino
monitor_speed = 115200 monitor_speed = 115200
upload_protocol = espota ;upload_protocol = espota
upload_port = 192.168.2.217 ;upload_port = 192.168.2.217
;upload_port = COM7 upload_port = COM7
build_flags = build_flags =
-D JAJ_BOARD_TARGET=BOARD_ESP32_DEV
${common.build_flags} ${common.build_flags}
lib_deps = lib_deps =
${common.lib_deps} ${common.lib_deps}
lib_compat_mode = strict lib_compat_mode = strict
[env:esp32-c3-devkitm-1]
platform = espressif32
board = esp32-c3-devkitm-1
framework = arduino
monitor_speed = 115200
;upload_protocol = espota
;upload_port = 192.168.2.217
upload_port = COM9
board_build.flash_mode = dio
build_flags =
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
-D JAJ_BOARD_TARGET=BOARD_ESP32_C3
${common.build_flags}
lib_deps =
${common.lib_deps}
lib_compat_mode = strict
[env:nodemcuv2] [env:nodemcuv2]
platform = https://github.com/platformio/platform-espressif8266.git platform = https://github.com/platformio/platform-espressif8266.git
board = nodemcuv2 board = nodemcuv2
framework = arduino framework = arduino
upload_protocol = espota upload_protocol = espota
upload_port = 192.168.2.238 upload_port = 192.168.2.242
;upload_port = COM6 ;upload_port = COM6
upload_speed = 115200 upload_speed = 115200
monitor_speed = 115200 monitor_speed = 115200
build_flags = build_flags =
-D JAJ_BOARD_TARGET=BOARD_ESP8266_DEV
${common.build_flags} ${common.build_flags}
lib_deps = lib_deps =
${common.lib_deps} ${common.lib_deps}
@ -57,6 +82,7 @@ upload_port = COM6
upload_speed = 115200 upload_speed = 115200
monitor_speed = 115200 monitor_speed = 115200
build_flags = build_flags =
-D JAJ_BOARD_TARGET=BOARD_ESP8266_HUZZAH
${common.build_flags} ${common.build_flags}
lib_deps = lib_deps =
${common.lib_deps} ${common.lib_deps}

View File

@ -2,10 +2,22 @@
#include <WiFiManager.h> #include <WiFiManager.h>
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
#include <esp32.h> #if (JAJ_BOARD_TARGET == BOARD_ESP32_C3)
#include <esp32c3.h>
#define BOARD "ESP32C3"
#elif (JAJ_BOARD_TARGET == BOARD_ESP32_DEV)
#include <esp32.h>
#define BOARD "ESP32"
#endif
#include <WiFi.h> #include <WiFi.h>
#include <HTTPClient.h> #include <HTTPClient.h>
#elif defined(ARDUINO_ARCH_ESP8266) #elif defined(ARDUINO_ARCH_ESP8266)
#if (JAJ_BOARD_TARGET == BOARD_ESP8266_HUZZAH)
#define BOARD "ESP8266-Huzzah"
#elif (JAJ_BOARD_TARGET == BOARD_ESP8266_DEV)
#define BOARD "ESP8266-DevKit"
#endif
#include <esp8266.h>
#include <esp8266.h> #include <esp8266.h>
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h> #include <ESP8266HTTPClient.h>
@ -51,6 +63,9 @@ extern const uint8_t gamma8[];
volatile bool blueInitState = false; volatile bool blueInitState = false;
volatile unsigned long blueToggleCount; volatile unsigned long blueToggleCount;
// nextStatusMillis is global so we can reset it inside the process message function if needed
unsigned long nextStatusMillis = 0;
// Struct for storing color value sets // Struct for storing color value sets
// Colors are obvious. restDuration is how long to rest on this color. // Colors are obvious. restDuration is how long to rest on this color.
struct colorTriplet { struct colorTriplet {
@ -126,7 +141,7 @@ void inline blueBlinkISR(void) {
#endif #endif
} }
unsigned long sendDeviceStatus() { void sendDeviceStatus() {
if ( DEBUG ) Serial.println("Sending device status"); if ( DEBUG ) Serial.println("Sending device status");
WiFiClient client; WiFiClient client;
HTTPClient http; HTTPClient http;
@ -145,7 +160,7 @@ unsigned long sendDeviceStatus() {
} }
} }
http.end(); http.end();
return millis(); nextStatusMillis = millis() + 600000; // 10 minutes
} }
// Set up our initial states and WiFi // Set up our initial states and WiFi
@ -190,6 +205,7 @@ void setup() {
#endif #endif
analogWrite(GPIO_BLUE, 0); analogWrite(GPIO_BLUE, 0);
sendDeviceStatus(); sendDeviceStatus();
nextStatusMillis = millis() + 600000; // 10 minutes
ArduinoOTA.onStart([]() { ArduinoOTA.onStart([]() {
analogWrite(GPIO_RED, 0); analogWrite(GPIO_RED, 0);
analogWrite(GPIO_GREEN, 0); analogWrite(GPIO_GREEN, 0);
@ -273,7 +289,7 @@ bool processMessage() {
memcpy(&messageTargetID, (char*)buff + 13, 4); memcpy(&messageTargetID, (char*)buff + 13, 4);
// If this packet isn't destined for ID=0 (all targets) or ID=TARGET_ID (our ID) then stop processing // If this packet isn't destined for ID=0 (all targets) or ID=TARGET_ID (our ID) then stop processing
if ( (myTargetID != 0 ) && (messageTargetID != 0) && (messageTargetID != myTargetID) ) { if ( (myTargetID != 0 ) && (messageTargetID != 0) && ((messageTargetID & myTargetID) == 0) ) {
if ( DEBUG ) Serial.println("Got packet for different ID! Mine=" + String(myTargetID) + " Target=" + String(messageTargetID)); if ( DEBUG ) Serial.println("Got packet for different ID! Mine=" + String(myTargetID) + " Target=" + String(messageTargetID));
return false; return false;
} }
@ -397,7 +413,7 @@ bool processMessage() {
if ( command == CMD_UPDATESTATUS ) { if ( command == CMD_UPDATESTATUS ) {
sendDeviceStatus(); sendDeviceStatus();
if ( DEBUG ) Serial.println("Status update requested"); if ( DEBUG ) Serial.println("Status update requested");
return true; return false;
} }
return false; return false;
@ -410,7 +426,6 @@ void loop() {
static short redLevel = 0, greenLevel = 0, blueLevel = 0; static short redLevel = 0, greenLevel = 0, blueLevel = 0;
static bool newColor = false; static bool newColor = false;
unsigned long nowMillis = millis(); unsigned long nowMillis = millis();
static unsigned long nextStatusMillis = millis() + 600000; // 10 minutes
static unsigned long nextRampMillis; static unsigned long nextRampMillis;
static unsigned long rampStartMillis; static unsigned long rampStartMillis;
static unsigned long restingEndMillis; static unsigned long restingEndMillis;
@ -431,7 +446,7 @@ void loop() {
} }
if ( nowMillis >= nextStatusMillis ) { if ( nowMillis >= nextStatusMillis ) {
nextStatusMillis = sendDeviceStatus() + 600000; // 10 minutes sendDeviceStatus();
} }
// Check to see if we have a new packet waiting and parse it out if we do // Check to see if we have a new packet waiting and parse it out if we do