#include #include #include #include // interrupts? as per: https://github.com/FastLED/FastLED/issues/306 #define FASTLED_ALLOW_INTERRUPTS 0 #include #include "lampServer.h" #include "patterns.h" #include #include "OmWebServer.h" #include "OminoInteractiveWifiSetup.h" extern "C" { #include "user_interface.h" } OmWebServer ows; #define LEDS_PIN D3 #define LEDS_COUNT 24 CRGB leds[LEDS_COUNT]; // +---------------------------- // | Forwards the declarations // | void handleRequest0(); const char *handleRequest1(const char *request); #define SHOW() noInterrupts(); FastLED.show(); interrupts(); SimpleThrob t; void connectionStatus(const char *ssid, bool trying, bool failure, bool success) { if(success) { lampControl.lampIp = ows.getIp(); lampControl.lampPort = ows.getPort(); lampControl.ssid = ows.getSsid(); String bonjourName = "Lamp-";// + system_get_chip_id(); MDNS.begin(bonjourName.c_str()); Serial.printf("(*) Bonjour address: http://%s.local\n", bonjourName.c_str()); } } void setup() { pinMode(BUILTIN_LED, OUTPUT); digitalWrite(BUILTIN_LED, 1); t.init0(LEDS_COUNT, leds); t.init(); FastLED.addLeds(leds,LEDS_COUNT); FastLED.setBrightness(255); for(int ix = 0; ix < LEDS_COUNT; ix++) leds[ix] = CRGB(ix*2,0,0); delay(200); SHOW(); delay(200); Serial.begin(115200); Serial.print("\n\n\n\n\nHello Lamp\n"); ows.addWifi("Idea Fab Labs", "vortexrings"); ows.addWifi("omino warp", "0123456789"); ows.setHandler(handleRequest1); ows.setStatusCallback(connectionStatus); ows.setStatusLedPin(BUILTIN_LED); ows.begin(); for(int ix = 0; ix < LEDS_COUNT; ix++) leds[ix] = CRGB(0,0,ix*2); SHOW(); lampSetup(); digitalWrite(BUILTIN_LED, 1); } const char *handleRequest1(const char *request) { lampControl.clientIp = ows.getClientIp(); lampControl.clientPort = ows.getClientPort(); static char s[6500]; handleRequest(s, sizeof(s), request); return s; } int v255(int x) { int v = x * 255 / 100; return v; } int v255c(int x) { int v = x * x * 255 / 10000; if(x && !v) v = 1; return v; } void loop() { { static String ssid; static String password; bool wifiWasUsed = interactiveWebSetup(ssid, password); if(ssid.length()) { ows.addWifi(ssid, password); } if(wifiWasUsed) { ows.begin(); } } ows.tick(); t.p.color1 = CHSV(v255(lampControl.h1), v255(lampControl.s1), v255c(lampControl.b1)); t.p.color2 = CHSV(v255(lampControl.h2), v255(lampControl.s2), v255c(lampControl.b2)); t.p.p1 = lampControl.p1; t.p.p2 = lampControl.p2; t.p.p3 = lampControl.p3; t.tick(); SHOW(); lampControl.millis = millis(); lampControl.freeBytes = system_get_free_heap_size(); lampControl.frames++; delay(12); }