esp8266 ifdef
This commit is contained in:
parent
a228d986af
commit
2453e9d74b
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.bin
|
@ -1,6 +1,4 @@
|
||||
#include <WiFi.h>
|
||||
#include "time.h"
|
||||
|
||||
#include <TaskScheduler.h>
|
||||
|
||||
|
||||
@ -9,8 +7,17 @@
|
||||
#include <IotWebConfUsing.h>
|
||||
// UpdateServer includes
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
# include <ESP8266HTTPUpdateServer.h>
|
||||
#include <TZ.h>
|
||||
#define MYTZ TZ_Europe_Berlin
|
||||
#include <coredecls.h> // settimeofday_cb()
|
||||
//#include <Schedule.h>
|
||||
//#include <PolledTimeout.h>
|
||||
#include <sys/time.h> // struct timeval
|
||||
#include <sntp.h> // sntp_servermode_dhcp()
|
||||
#elif defined(ESP32)
|
||||
#include <WiFi.h>
|
||||
// For ESP32 IotWebConf provides a drop-in replacement for UpdateServer.
|
||||
# include <IotWebConfESP32HTTPUpdateServer.h>
|
||||
#endif
|
||||
@ -23,9 +30,15 @@
|
||||
Dark Resistance: 0.5 Mohm
|
||||
over a 56k voltage divider . Dark (0.5MOhm) , 10Lux (5-10kOhm)
|
||||
*/
|
||||
#ifdef ESP8266
|
||||
//#define LDR_PIN 4
|
||||
#define IOTWEBCONF_DEBUG_DISABLED
|
||||
#define DATA_PIN 5 //DMA RDX0/GPIO3 | Uart1 TXD1/GPIO2 | UART0 GPIO1
|
||||
#elif defined(ESP32)
|
||||
#define LDR_PIN A6
|
||||
#define NUM_LEDS 60
|
||||
#define DATA_PIN 17
|
||||
#endif
|
||||
#define NUM_LEDS 60
|
||||
#define SERIAL_BAUD 115200
|
||||
|
||||
#define RGBW
|
||||
@ -43,8 +56,13 @@ void brightnessAdjustmentCallback();
|
||||
#define MINIMAL_BRIGHTNESS 5
|
||||
#define LDR_SCALE 16
|
||||
#define colorSaturation 255
|
||||
//NeoPixelBrightnessBus<NeoGrbwFeature, Neo800KbpsMethod> strip(NUM_LEDS, DATA_PIN); //SK6812
|
||||
NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp32I2s1800KbpsMethod> strip(NUM_LEDS, DATA_PIN);
|
||||
#ifdef ESP8266
|
||||
NeoPixelBrightnessBus<NeoGrbwFeature, Neo800KbpsMethod> strip(NUM_LEDS);//RDX0 GPIO3
|
||||
//NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp8266AsyncUart0Sk6812Method> strip(NUM_LEDS);
|
||||
//NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp8266Uart0Sk6812Method> strip(NUM_LEDS);
|
||||
#elif defined(ESP32)
|
||||
NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp32I2s1800KbpsMethod> strip(NUM_LEDS, DATA_PIN); //ESP32
|
||||
#endif
|
||||
RgbwColor red(colorSaturation, 0, 0, 0);
|
||||
RgbwColor green(0, colorSaturation, 0, 0);
|
||||
RgbwColor blue(0, 0, colorSaturation, 0);
|
||||
@ -138,17 +156,19 @@ void transformHtmltoStrip(RgbColor outputColor, char* sInput) {
|
||||
|
||||
#endif
|
||||
|
||||
//NTP handler
|
||||
//const char* ntpServer = "pool.ntp.org";
|
||||
const long gmtOffset_sec = 3600; //ToDo changable from user
|
||||
const int daylightOffset_sec = 3600;
|
||||
struct tm timeinfo;
|
||||
|
||||
volatile int currentSec = 59;
|
||||
volatile int currentMin = 1;
|
||||
volatile int currentHour = 2;
|
||||
|
||||
#ifdef LDR_PIN
|
||||
// variable for storing the potentiometer value
|
||||
volatile unsigned int ldrValue = 0;
|
||||
#endif
|
||||
volatile int MAX_BRIGHTNESS = 200;
|
||||
|
||||
// WebPortal
|
||||
@ -286,12 +306,31 @@ CustomHtmlFormatProvider customHtmlFormatProvider;
|
||||
Task bootAnim(200, TASK_FOREVER, &bootAnimCallback);
|
||||
Task clockTick(1000, TASK_FOREVER, &clockTickCallback);
|
||||
Task ledRefresh(200, TASK_FOREVER, &ledRefreshCallback);
|
||||
#ifdef LDR_PIN
|
||||
Task brightness(10000, TASK_FOREVER, &brightnessAdjustmentCallback);
|
||||
#endif
|
||||
//Task iotwebconfLoop(200, TASK_FOREVER, &iotWebConf.doLoop);
|
||||
Scheduler runner;
|
||||
|
||||
#ifdef ESP8266
|
||||
bool getLocalTime(struct tm * info, uint32_t ms)
|
||||
{
|
||||
uint32_t start = millis();
|
||||
time_t now;
|
||||
while ((millis() - start) <= ms) {
|
||||
time(&now);
|
||||
localtime_r(&now, info);
|
||||
if (info->tm_year > (2016 - 1900)) {
|
||||
return true;
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
String printLocalTime() {
|
||||
if (!getLocalTime(&timeinfo)) {
|
||||
if (!getLocalTime(&timeinfo, 200)) {
|
||||
Serial.println("Failed to obtain time");
|
||||
return "";
|
||||
}
|
||||
@ -451,18 +490,26 @@ void syncNTP() {
|
||||
bootAnim.disable();
|
||||
ledRefresh.enable();
|
||||
clockTick.enable();
|
||||
#ifdef LDR_PIN
|
||||
brightness.enable();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
#ifdef LDR_PIN
|
||||
pinMode(LDR_PIN, INPUT_PULLUP);
|
||||
#endif
|
||||
pinMode(DATA_PIN, OUTPUT);
|
||||
|
||||
Serial.begin(SERIAL_BAUD);
|
||||
Serial.flush();
|
||||
Serial.print("\n\n\nCPU Frequency is: ");
|
||||
#ifdef ESP8266
|
||||
Serial.print(ESP.getCpuFreqMHz());
|
||||
#elif defined(ESP32)
|
||||
Serial.print(getCpuFrequencyMhz()); //Get CPU clock
|
||||
#endif
|
||||
Serial.println(" Mhz");
|
||||
Serial.print("MAC address: ");
|
||||
Serial.println(WiFi.macAddress()); //Get CPU clock
|
||||
@ -481,7 +528,9 @@ void setup() {
|
||||
runner.init();
|
||||
runner.addTask(ledRefresh);
|
||||
runner.addTask(clockTick);
|
||||
#ifdef LDR_PIN
|
||||
runner.addTask(brightness);
|
||||
#endif
|
||||
runner.addTask(bootAnim);
|
||||
bootAnim.enable();
|
||||
|
||||
@ -525,7 +574,9 @@ void ledRefreshCallback() {
|
||||
|
||||
// Scheduler
|
||||
void clockTickCallback() {
|
||||
#ifdef LDR_PIN
|
||||
ldrValue = (ldrValue + analogRead(LDR_PIN));
|
||||
#endif
|
||||
if (currentSec < 0) {
|
||||
currentSec = 59;
|
||||
currentMin--;
|
||||
@ -571,6 +622,7 @@ void bootAnimCallback() {
|
||||
strip.Show();
|
||||
}
|
||||
|
||||
#ifdef LDR_PIN
|
||||
void brightnessAdjustmentCallback() {
|
||||
//Serial.println(ldrValue);
|
||||
//brigthness begin
|
||||
@ -587,3 +639,4 @@ void brightnessAdjustmentCallback() {
|
||||
ldrValue = 0;
|
||||
strip.Show();
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user