~/Projects/AWTRIX2.0-Controller
git clone https://code.lsong.org/AWTRIX2.0-Controller
Commit
- Commit
- 0f9136c120c71c6e1e02014a178d110717c7df07
- Author
- Stephan Mühl <31169771+[email protected]>
- Date
- 2019-03-09 14:17:33 +0100 +0100
- Diffstat
.gitignore | 2 .vscode/extensions.json | 7 ++ .vscode/settings.json | 6 + platformio.ini | 1 src/AWTRIXController.cpp | 141 ++++++++++++++++++++++++++++++++--------- src/awtrix-conf.h | 11 ++
add OTA and gesturecontrol
diff --git a/.gitignore b/.gitignore index 2de98aba16f166d9f7a3db741d7a6254dd8e2eb4..2d479cb735ff4bb9cbc0b9d9580b131371f467cd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ .piolibdeps .vscode/.browse.c_cpp.db* .vscode/c_cpp_properties.json .vscode/launch.json +src/awtrix-conf.h +src/awtrix-conf.h diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000000000000000000000000000000000000..272828b56f5a72a210b9724db8d74101d5295fd4 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..0829a975ea020b2ac2f4a890917d67927530c5f6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "terminal.integrated.env.windows": { + "PATH": "C:\\Users\\Stephan\\.platformio\\penv\\Scripts;C:\\Users\\Stephan\\.platformio\\penv;C:\\Program Files\\Oculus\\Support\\oculus-runtime;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files (x86)\\Tesseract-OCR;C:\\OCR;C:\\Program Files\\PuTTY\\;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Program Files\\nodejs\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\Git\\mingw64\\bin;C:\\Program Files\\Git\\usr\\bin;C:\\Users\\Stephan\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\Stephan\\AppData\\Local\\GitHubDesktop\\bin;C:\\Users\\Stephan\\AppData\\Roaming\\npm;C:\\Users\\Stephan\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Program Files\\Oculus\\Support\\oculus-runtime;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files (x86)\\Tesseract-OCR;C:\\OCR;C:\\Program Files\\PuTTY\\;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Program Files\\nodejs\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\Git\\mingw64\\bin;C:\\Program Files\\Git\\usr\\bin;C:\\Users\\Stephan\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\Stephan\\AppData\\Local\\GitHubDesktop\\bin;C:\\Users\\Stephan\\AppData\\Roaming\\npm;C:\\Users\\Stephan\\AppData\\Local\\Programs\\Microsoft VS Code\\bin", + "PLATFORMIO_CALLER": "vscode" + } +} \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index dd41cb053cf70d20b78a96f07234efc5eb1001a3..3ebe54d2a4a9a187caf285765687567bd50c2068 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,6 +20,7 @@ PubSubClient Adafruit NeoPixel https://github.com/awtrix/Adafruit-GFX-Library https://github.com/awtrix/FastLED_NeoMatrix + https://github.com/awtrix/APDS-9960 ArduinoJson FastLED https://github.com/QuentinCG/Arduino-Light-Dependent-Resistor-Library/releases/download/1.0.0/LightDependentResistor_v1_0_0.zip diff --git a/src/AWTRIXController.cpp b/src/AWTRIXController.cpp index 685363a068f6a90c763b888028539c8e925cfb69..c590c5d8f4caab27bba9b4319d68da0b5448d828 100644 --- a/src/AWTRIXController.cpp +++ b/src/AWTRIXController.cpp @@ -1,9 +1,6 @@ -#include <ESP8266WebServer.h> #include <ESP8266HTTPUpdateServer.h> #include <ESP8266WiFi.h> #include <WiFiClient.h> -#include <ESP8266mDNS.h> -#include <DNSServer.h> #include <PubSubClient.h> #include <FS.h> #include <ArduinoJson.h> @@ -12,8 +8,10 @@ #include#include <FastLED_NeoMatrix.h> #include <Fonts/TomThumb.h> #include <LightDependentResistor.h> +#include <Wire.h> +#include <SparkFun_APDS9960.h> -String version = "0.36"; +String version = "0.4"; #include "awtrix-conf.h" @@ -33,22 +31,22 @@ WiFiClient espClient; PubSubClient client(espClient); #include <ESP8266WiFi.h> +#include <ESP8266HTTPUpdateServer.h> +#include <ESP8266HTTPUpdateServer.h> +#include <WiFiClient.h> -#include <ESP8266WiFi.h> #include <ESP8266WebServer.h> -LightDependentResistor photocell(LDR_PIN, LDR_RESISTOR, LDR_PHOTOCELL); +#include <ESP8266mDNS.h> unsigned long startTime = 0; unsigned long endTime = 0; unsigned long duration; -#include <ESP8266WebServer.h> +char *topics = "awtrixmatrix/"; #include <ESP8266mDNS.h> -#include <ESP8266WiFi.h> +char *topics = "awtrixmatrix/"; #include <DNSServer.h> -// ****** UTF8-Decoder: convert UTF8-string to extended ASCII ******* + static byte c1; // Last character buffer -// Convert a single Character from UTF8 to Extended ASCII -// Return "0" if a byte has to be ignored byte utf8ascii(byte ascii) { if ( ascii < 128 ) // Standard ASCII-set 0..0x7F handling { c1 = 0; @@ -59,11 +57,11 @@ byte last = c1; // get last char c1 = ascii; // remember actual character switch (last) // conversion depending on first UTF8-character { case 0xC2: return (ascii) - 34; break; - case 0xC3: return (ascii | 0xC0) - 34; break;// TomThumb extended characters off by 34 + case 0xC3: return (ascii | 0xC0) - 34; break; -#include <ESP8266mDNS.h> #include <ESP8266HTTPUpdateServer.h> +#include <FS.h> } - return (0); // otherwise: return zero, if character has to be ignored + return (0); } // convert String object from UTF8 String to Extended ASCII @@ -116,11 +114,6 @@ } return quality; } -void handleNotFound() -{ - server.sendHeader("Location", String("/update"), true); - server.send(302, "text/plain", ""); -} void callback(char *topic, byte *payload, unsigned int length) { @@ -233,7 +226,6 @@ else if (channel.equals("getLUX")) { StaticJsonBuffer<200> jsonBuffer; - #include <PubSubClient.h> } } @@ -243,7 +235,6 @@ { // Loop until we're reconnected while (!client.connected()) { - // Attempt to connect String clientId = "AWTRIXController-"; @@ -265,6 +256,68 @@ } } #include <ESP8266WebServer.h> +#include <ESP8266mDNS.h> +void interruptRoutine() { + isr_flag = 1; +} + +void handleGesture() { + if (apds.isGestureAvailable()) { + switch ( apds.readGesture() ) { + case DIR_UP: + client.publish("control", "UP"); + break; + case DIR_DOWN: + client.publish("control", "DOWN"); + break; + case DIR_LEFT: + client.publish("control", "LEFT"); + break; + case DIR_RIGHT: + client.publish("control", "RIGHT"); + break; + case DIR_NEAR: + client.publish("control", "NEAR"); + break; + case DIR_FAR: + client.publish("control", "FAR"); + break; + default: + client.publish("control", "NONE"); + } + } +} + +uint32_t Wheel(byte WheelPos, int pos) { + if(WheelPos < 85) { + return matrix->Color((WheelPos * 3)-pos, (255 - WheelPos * 3)-pos, 0); + } else if(WheelPos < 170) { + WheelPos -= 85; + return matrix->Color((255 - WheelPos * 3)-pos, 0, (WheelPos * 3)-pos); + } else { + WheelPos -= 170; + return matrix->Color(0, (WheelPos * 3)-pos, (255 - WheelPos * 3)-pos); + } +} + +void flashProgress(unsigned int progress, unsigned int total) { + matrix->setBrightness(100); + long num = 32 * 8 * progress / total; + for (unsigned char y = 0; y < 8; y++) { + for (unsigned char x = 0; x < 32; x++) { + if (num-- > 0) matrix->drawPixel(x, 8 - y - 1, Wheel((num*16) & 255,0)); + } + } + matrix->setCursor(0, 6); + + matrix->setTextColor(matrix->Color(255, 255, 255)); + matrix->print("FLASHING"); + + matrix->show(); +} + + +#include <ESP8266WebServer.h> s[k] = 0; { FastLED.addLeds<NEOPIXEL, MATRIX_PIN>(leds, NUMMATRIX).setCorrection(TypicalLEDStrip); @@ -274,8 +327,8 @@ matrix->begin(); matrix->setTextWrap(false); matrix->setBrightness(80); matrix->setFont(&TomThumb); +#endif #include <ESP8266WebServer.h> - quality = 0; matrix->print("WiFi..."); matrix->show(); while (WiFi.status() != WL_CONNECTED) @@ -284,44 +337,69 @@ delay(500); } #include <ESP8266WebServer.h> - quality = 2 * (rssi + 100); -#include <ESP8266WebServer.h> #include <ESP8266mDNS.h> photocell.setPhotocellPositionOnGround(false); matrix->clear(); - matrix->setCursor(0, 7); + matrix->setCursor(6, 6); matrix->print("Ready!"); matrix->show(); #include <ESP8266WebServer.h> -#include <FS.h> #include <ArduinoJson.h> +#include <ESP8266HTTPUpdateServer.h> //////////////////////// Don't touch ///////////////////////// +#include <ESP8266WiFi.h> + + +#if GESTURE + Wire.begin(APDS9960_SDA,APDS9960_SCL); + pinMode(APDS9960_INT, INPUT); + attachInterrupt(APDS9960_INT, interruptRoutine, FALLING); + apds.init(); + apds.enableGestureSensor(true); +#endif #include <ESP8266WebServer.h> +#include <ESP8266mDNS.h> +#endif #include <ArduinoJson.h> + updating = true; +#ifndef MATRIX_MODEV2 #include <ESP8266WebServer.h> + }); + ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { + flashProgress(progress, total); + }); #include <ESP8266WebServer.h> -#include <ArduinoJson.h> +#include <ESP8266mDNS.h> #include <ESP8266HTTPUpdateServer.h> +void utf8ascii(char* s) { #include <ESP8266WebServer.h> - String channel = s_topic.substring(last); +#include <ESP8266mDNS.h> } void loop() { + ArduinoOTA.handle(); + if (!updating) { if (!client.connected()) { reconnect(); +#ifndef MATRIX_MODEV2 #include <FS.h> -#include <ESP8266WebServer.h> +#ifndef MATRIX_MODEV2 #include <ArduinoJson.h> +#include <ESP8266HTTPUpdateServer.h> #include <PubSubClient.h> +FastLED_NeoMatrix *matrix = new FastLED_NeoMatrix(leds, 32, 8, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG); #include <ESP8266WebServer.h> + isr_flag = 0; + attachInterrupt(APDS9960_INT, interruptRoutine, FALLING); +#include <WiFiClient.h> #include <ESP8266mDNS.h> -//////////////////////// Don't touch ///////////////////////// + client.loop(); #include <FS.h> - MDNS.update(); + } } diff --git a/src/awtrix-conf.h b/src/awtrix-conf.h index 6c8ee6d9f7327599b8e509f555a64ff990768494..2c97847ffe8e861cf5e9f3967492404ca20705c8 100644 --- a/src/awtrix-conf.h +++ b/src/awtrix-conf.h @@ -1,8 +1,9 @@ //////////////////////////////////////////////////////////////// +char *awtrix_server = "192.168.178.39"; -///////////////////////// Config begin ///////////////////////// + // Wifi Config const char *ssid = "xxxxx"; -const char *password = "xxxxxx"; +const char *password = "xxxxx"; char *awtrix_server = "192.168.178.39"; /// LDR Config @@ -14,3 +15,9 @@ /// Matrix Config #define MATRIX_PIN D2 //uncomment following line to use Matrixtype 2 //#define MATRIX_MODEV2 + +// Gesture Config +#define GESTURE false +#define APDS9960_INT D6 +#define APDS9960_SDA D3 +#define APDS9960_SCL D1