commit bc45337d9d90625785b2817f3d8f7047703124ea Author: Juergen Jung Date: Sat Jan 28 23:29:51 2017 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5dac9f5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.pioenvs +.piolibdeps +.clang_complete +.gcc-flags.json diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2c4ff5c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,65 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choice one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/data/homie/config.json b/data/homie/config.json new file mode 100644 index 0000000..96f453c --- /dev/null +++ b/data/homie/config.json @@ -0,0 +1,16 @@ +{ + "name": "Homie CTDO Schild", + "device_id": "schild2", + "wifi": { + "ssid": "Nudel", + "password": "Unser WLAN ist sicher!" + }, + "mqtt": { + "host": "192.168.1.80", + "port": 1883, + "auth": false + }, + "ota": { + "enabled": false + } +} diff --git a/data/homie/ui_bundle.gz b/data/homie/ui_bundle.gz new file mode 100644 index 0000000..26f2d21 Binary files /dev/null and b/data/homie/ui_bundle.gz differ diff --git a/lib/readme.txt b/lib/readme.txt new file mode 100644 index 0000000..dbadc3d --- /dev/null +++ b/lib/readme.txt @@ -0,0 +1,36 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +More information about PlatformIO Library Dependency Finder +- http://docs.platformio.org/page/librarymanager/ldf.html diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..c67b50e --- /dev/null +++ b/platformio.ini @@ -0,0 +1,28 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[env:d1_mini] +platform = espressif8266 +board = d1_mini +framework = arduino + +;upload_port = /dev/tty.wchusbserial410 +;upload_speed = 921600 +upload_port = schild.local +upload_flags = --auth=ctdo2342 + + +lib_deps = + https://github.com/marvinroger/homie-esp8266.git + ArduinoJson + Bounce2 + ESPAsyncTCP + AsyncMqttClient + Adafruit NeoPixel diff --git a/src/schild.ino b/src/schild.ino new file mode 100644 index 0000000..5ecb8be --- /dev/null +++ b/src/schild.ino @@ -0,0 +1,188 @@ +#include + +#include +#include +#include + +#define PIN D1 +#define NUMPIXELS 30 + +uint16_t i=0,j=0,wait = 50; +unsigned long lastCall = 0; +byte wPos = 0; + +Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); + +HomieNode stripNode("strip", "strip"); + +String effect = "none"; + +// Input a value 0 to 255 to get a color value. +// The colours are a transition r - g - b - back to r. +uint32_t wheel(byte wheelPos) { + wheelPos = 255 - wheelPos; + if(wheelPos < 85) { + return pixels.Color(255 - wheelPos * 3, 0, wheelPos * 3); + } + if(wheelPos < 170) { + wheelPos -= 85; + return pixels.Color(0, wheelPos * 3, 255 - wheelPos * 3); + } + wheelPos -= 170; + return pixels.Color(wheelPos * 3, 255 - wheelPos * 3, 0); +} + +bool onSetPixel(const HomieRange& range, const String& value){ + if(!range.isRange){ + for(int i=0;i NUMPIXELS-1) { + return false; + } + effect == "none"; + pixels.setPixelColor(range.index, value.toInt()); + pixels.show(); + stripNode.setProperty("pixel_" + String(range.index)).send(value); +} + +bool onSetBrightness(const HomieRange& range, const String& value){ + long brightness= value.toInt(); + if (brightness < 0 || brightness > 255) { + return false; + } + pixels.setBrightness(brightness); + pixels.show(); + stripNode.setProperty("brightness").send(value); +} + +bool onSetEffect(const HomieRange& range, const String& value){ + effect = value; + i=0,j=0,wait=50; + stripNode.setProperty("effect").send(value); +} + +bool onSetClear(const HomieRange& range, const String& value){ + effect = "none"; + pixels.clear(); + pixels.show(); + stripNode.setProperty("clear").send(value); +} + + +void loopHandler() { + if (effect == "none"){ + return; + } + else if (effect == "larson") { + int SpeedDelay = 20; + int ReturnDelay = 50; + int EyeSize = 5; + for(int i = 0; i < pixels.numPixels()-EyeSize-2; i++) { + pixels.clear(); + pixels.show(); + pixels.setPixelColor(i, 255/10, 0, 0); + for(int j = 1; j <= EyeSize; j++) { + //pixels.setPixelColor(i+j, 255, 0, 0); + pixels.setPixelColor(i+j, wheel(wPos++)); + } + pixels.setPixelColor(i+EyeSize+1, 255/10, 0, 0); + pixels.show(); + delay(SpeedDelay); + } + delay(wait); + + for(int i = pixels.numPixels()-EyeSize-2; i > 0; i--) { + pixels.clear(); + pixels.show(); + pixels.setPixelColor(i, 255/10, 0, 0); + for(int j = 1; j <= EyeSize; j++) { + //pixels.setPixelColor(i+j, 255, 0, 0); + pixels.setPixelColor(i+j, wheel(wPos++)); + } + pixels.setPixelColor(i+EyeSize+1, 255/10, 0, 0); + pixels.show(); + delay(SpeedDelay); + } + delay(wait); + } + else if (effect == "randomfade") { + if(lastCall + wait > millis()){ + return; + } + lastCall = millis(); + for(int i=0;i= millis()){ + return; + } + if(j<256) { + if(i