commit b6f8617a8c2accd0d6416f6cfc5604dc1f072484 Author: clerie Date: Sun Aug 23 22:09:56 2020 +0200 Init repository diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9f3806 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.pio +.vscode diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..7c486f1 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://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 +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose 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 +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be 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 +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..2e88788 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,32 @@ +; 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 +; https://docs.platformio.org/page/projectconf.html + +[platformio] +default_envs = leonardo + +[env] +framework = arduino + +[env:nodemcuv2] +platform = espressif8266 +board = nodemcuv2 +build_flags = + -D DIALING_PIN=D5 + -D PULSE_PIN=D6 + +[env:leonardo] +platform = atmelavr +board = leonardo +lib_deps = + Keyboard +build_flags = + -D FEATURE_KEYBOARD + -D DIALING_PIN=13 + -D PULSE_PIN=12 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..fecb614 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,118 @@ +#include +#ifdef FEATURE_KEYBOARD +#include +#endif + +int dialingPin = DIALING_PIN; +int pulsePin = PULSE_PIN; + +void setup() { + Serial.begin(9600); + #ifdef FEATURE_KEYBOARD + Keyboard.begin(); + #endif + pinMode(dialingPin, INPUT_PULLUP); + pinMode(pulsePin, INPUT_PULLUP); + Serial.println("Start Wählscheibe"); +} + +bool dialing = false; +bool pulse = false; + +bool dialingLast = false; +bool pulseLast = false; + +bool dialingVal = false; +bool pulseVal = false; + +bool dialingValLast = false; +bool pulseValLast = false; + +unsigned long dialingTimeOn = 0; +unsigned long dialingTimeOff = 0; +unsigned long pulseTimeOn = 0; +unsigned long pulseTimeOff = 0; + +int count = 0; + +void loop() { + dialingVal = digitalRead(dialingPin) == LOW; + pulseVal = digitalRead(pulsePin) == HIGH; + + // DIALING + // Schalter geschlossen UND vorher offen + if (dialingVal && !dialingValLast) { + dialingTimeOn = micros(); + } + + // Schalter offen UND seit mindestens einer Weile + if (dialingVal && ((micros() - dialingTimeOn) > 3000)) { + dialing = true; + } + + // Schalter offen UND vorher geschlossen + if (!dialingVal && dialingValLast) { + dialingTimeOff = micros(); + } + + // Schalter offen UND seit mindestens einer Weile + if (!dialingVal && ((micros() - dialingTimeOff) > 3000)) { + dialing = false; + } + + // PULSE + // Schalter geschlossen UND vorher offen + if (pulseVal && !pulseValLast) { + pulseTimeOn = micros(); + } + + // Schalter offen UND seit mindestens einer Weile + if (pulseVal && ((micros() - pulseTimeOn) > 3000)) { + pulse = true; + } + + // Schalter offen UND vorher geschlossen + if (!pulseVal && pulseValLast) { + pulseTimeOff = micros(); + } + + // Schalter offen UND seit mindestens einer Weile + if (!pulseVal && ((micros() - pulseTimeOff) > 3000)) { + pulse = false; + } + + // INTERPRET + if (dialing && !dialingLast) { + #ifdef DEBUG + Serial.println("Start dialing"); + #endif + count = 0; + } + + if (dialing) { + if (pulse && !pulseLast) { + #ifdef DEBUG + Serial.print("+"); + #endif + count++; + } + } + + if (!dialing && dialingLast) { + #ifdef DEBUG + Serial.println(""); + Serial.println("Stop dialing"); + #endif + unsigned int output = count % 10; + Serial.println(output); + #ifdef FEATURE_KEYBOARD + Keyboard.print(output); + #endif + } + + dialingLast = dialing; + pulseLast = pulse; + + dialingValLast = dialingVal; + pulseValLast = pulseVal; +} \ No newline at end of file