diff --git a/lib/Bounce2/.gitignore b/lib/Bounce2/.gitignore deleted file mode 100644 index 3997bea..0000000 --- a/lib/Bounce2/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.db \ No newline at end of file diff --git a/lib/Bounce2/Bounce1.zip b/lib/Bounce2/Bounce1.zip deleted file mode 100644 index 4b6c0cd..0000000 Binary files a/lib/Bounce2/Bounce1.zip and /dev/null differ diff --git a/lib/Bounce2/Bounce2.cpp b/lib/Bounce2/Bounce2.cpp deleted file mode 100644 index 84f928e..0000000 --- a/lib/Bounce2/Bounce2.cpp +++ /dev/null @@ -1,125 +0,0 @@ -// Please read Bounce2.h for information about the liscence and authors - - -#include "Bounce2.h" - -static const uint8_t DEBOUNCED_STATE = 0b00000001; -static const uint8_t UNSTABLE_STATE = 0b00000010; -static const uint8_t CHANGED_STATE = 0b00000100; - - -Bounce::Bounce() - : previous_millis(0) - , interval_millis(10) - , state(0) - , pin(0) -{} - -void Bounce::attach(int pin) { - this->pin = pin; - state = 0; - if (readCurrentState()) { - setStateFlag(DEBOUNCED_STATE | UNSTABLE_STATE); - } -#ifdef BOUNCE_LOCK_OUT - previous_millis = 0; -#else - previous_millis = millis(); -#endif -} - -void Bounce::attach(int pin, int mode){ - setPinMode(pin, mode); - this->attach(pin); -} - -void Bounce::interval(uint16_t interval_millis) -{ - this->interval_millis = interval_millis; -} - -bool Bounce::update() -{ - - unsetStateFlag(CHANGED_STATE); -#ifdef BOUNCE_LOCK_OUT - - // Ignore everything if we are locked out - if (millis() - previous_millis >= interval_millis) { - bool currentState = readCurrentState(); - if ( currentState != getStateFlag(DEBOUNCED_STATE) ) { - previous_millis = millis(); - toggleStateFlag(DEBOUNCED_STATE); - setStateFlag(CHANGED_STATE); - } - } - - -#elif defined BOUNCE_WITH_PROMPT_DETECTION - // Read the state of the switch port into a temporary variable. - bool readState = readCurrentState(); - - - if ( readState != getStateFlag(DEBOUNCED_STATE) ) { - // We have seen a change from the current button state. - - if ( millis() - previous_millis >= interval_millis ) { - // We have passed the time threshold, so a new change of state is allowed. - // set the STATE_CHANGED flag and the new DEBOUNCED_STATE. - // This will be prompt as long as there has been greater than interval_misllis ms since last change of input. - // Otherwise debounced state will not change again until bouncing is stable for the timeout period. - toggleStateFlag(DEBOUNCED_STATE); - setStateFlag(CHANGED_STATE ); - } - } - - // If the readState is different from previous readState, reset the debounce timer - as input is still unstable - // and we want to prevent new button state changes until the previous one has remained stable for the timeout. - if ( readState != getStateFlag(UNSTABLE_STATE) ) { - // Update Unstable Bit to macth readState - toggleStateFlag(UNSTABLE_STATE); - previous_millis = millis(); - } - - -#else - // Read the state of the switch in a temporary variable. - bool currentState = readCurrentState(); - - - // If the reading is different from last reading, reset the debounce counter - if ( currentState != getStateFlag(UNSTABLE_STATE) ) { - previous_millis = millis(); - toggleStateFlag(UNSTABLE_STATE); - } else - if ( millis() - previous_millis >= interval_millis ) { - // We have passed the threshold time, so the input is now stable - // If it is different from last state, set the STATE_CHANGED flag - if (currentState != getStateFlag(DEBOUNCED_STATE) ) { - previous_millis = millis(); - toggleStateFlag(DEBOUNCED_STATE); - setStateFlag(CHANGED_STATE) ; - } - } - - -#endif - -return getStateFlag(CHANGED_STATE); - -} - -bool Bounce::read() -{ - return getStateFlag(DEBOUNCED_STATE); -} - -bool Bounce::rose() -{ - return getStateFlag(DEBOUNCED_STATE) && getStateFlag(CHANGED_STATE); -} - -bool Bounce::fell() -{ - return !getStateFlag(DEBOUNCED_STATE) && getStateFlag(CHANGED_STATE); -} diff --git a/lib/Bounce2/Bounce2.h b/lib/Bounce2/Bounce2.h deleted file mode 100644 index 8e6eebb..0000000 --- a/lib/Bounce2/Bounce2.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - The MIT License (MIT) - - Copyright (c) 2013 thomasfredericks - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - the Software, and to permit persons to whom the Software is furnished to do so, - subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * - Main code by Thomas O Fredericks (tof@t-o-f.info) - Previous contributions by Eric Lowry, Jim Schimpf and Tom Harkaway - * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#ifndef Bounce2_h -#define Bounce2_h - -#if defined(ARDUINO) && ARDUINO >= 100 -#include "Arduino.h" -#else -#include "WProgram.h" -#endif - -// Uncomment the following line for "LOCK-OUT" debounce method -//#define BOUNCE_LOCK_OUT - -// Uncomment the following line for "BOUNCE_WITH_PROMPT_DETECTION" debounce method -//#define BOUNCE_WITH_PROMPT_DETECTION - -#include - -/* -#ifndef _BV -#define _BV(n) (1<<(n)) -#endif -*/ - -class Bounce -{ - public: - // Create an instance of the bounce library - Bounce(); - - // Attach to a pin (and also sets initial state) - void attach(int pin); - - // Attach to a pin (and also sets initial state) and sets pin to mode (INPUT/INPUT_PULLUP/OUTPUT) - void attach(int pin, int mode); - - // Sets the debounce interval - void interval(uint16_t interval_millis); - - // Updates the pin - // Returns 1 if the state changed - // Returns 0 if the state did not change - bool update(); - - // Returns the updated pin state - bool read(); - - // Returns the falling pin state - bool fell(); - - // Returns the rising pin state - bool rose(); - - // Partial compatibility for programs written with Bounce version 1 - bool risingEdge() { return rose(); } - bool fallingEdge() { return fell(); } - Bounce(uint8_t pin, unsigned long interval_millis ) : Bounce() { - attach(pin); - interval(interval_millis); - } - - protected: - unsigned long previous_millis; - uint16_t interval_millis; - uint8_t state; - uint8_t pin; - virtual bool readCurrentState() { return digitalRead(pin); } - virtual void setPinMode(int pin, int mode) { -#if defined(ARDUINO_STM_NUCLEO_F103RB) || defined(ARDUINO_GENERIC_STM32F103C) - pinMode(pin, (WiringPinMode)mode); -#else - pinMode(pin, mode); -#endif - } - - private: - inline void setStateFlag(const uint8_t flag) {state |= flag;} - inline void unsetStateFlag(const uint8_t flag) {state &= ~flag;} - inline void toggleStateFlag(const uint8_t flag) {state ^= flag;} - inline bool getStateFlag(const uint8_t flag) {return((state & flag) != 0);} -}; - -#endif diff --git a/lib/Bounce2/BouncySwitch_lockout.png b/lib/Bounce2/BouncySwitch_lockout.png deleted file mode 100644 index d8313d4..0000000 Binary files a/lib/Bounce2/BouncySwitch_lockout.png and /dev/null differ diff --git a/lib/Bounce2/BouncySwitch_stable.png b/lib/Bounce2/BouncySwitch_stable.png deleted file mode 100644 index 080b609..0000000 Binary files a/lib/Bounce2/BouncySwitch_stable.png and /dev/null differ diff --git a/lib/Bounce2/INSTALL.txt b/lib/Bounce2/INSTALL.txt deleted file mode 100644 index 0bd2f8e..0000000 --- a/lib/Bounce2/INSTALL.txt +++ /dev/null @@ -1 +0,0 @@ -Put the "Bounce2" folder in your Arduino or Wiring "libraries" folder. diff --git a/lib/Bounce2/LICENSE b/lib/Bounce2/LICENSE deleted file mode 100644 index f945b53..0000000 --- a/lib/Bounce2/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013 thomasfredericks - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/lib/Bounce2/README.md b/lib/Bounce2/README.md deleted file mode 100644 index 211a035..0000000 --- a/lib/Bounce2/README.md +++ /dev/null @@ -1,37 +0,0 @@ -BOUNCE 2 -===================== - -Debouncing library for Arduino or Wiring - -by Thomas Ouellet Fredericks - -with contributions from: - -Eric Lowry, Jim Schimpf, Tom Harkaway and Joachim Krüger. - - -HAVE A QUESTION? -===================== -Please post your questions here : -http://forum.arduino.cc/index.php?topic=266132.0 - -DOWNLOAD -===================== - -Download the latest version (version 2) here : - -https://github.com/thomasfredericks/Bounce2/archive/master.zip - - -DOCUMENTATION -===================== - -The latest version (version 2) documentation can be found here : - -https://github.com/thomasfredericks/Bounce2/wiki - - -ABOUT BOUNCE 1 (ORIGINAL VERSION) -===================== - -The original version of Bounce (Bounce 1) is included but not supported anymore. diff --git a/lib/Bounce2/examples/bounce/bounce.ino b/lib/Bounce2/examples/bounce/bounce.ino deleted file mode 100644 index 2c75bda..0000000 --- a/lib/Bounce2/examples/bounce/bounce.ino +++ /dev/null @@ -1,48 +0,0 @@ - -/* - DESCRIPTION - ==================== - Simple example of the Bounce library that switches the debug LED when a button is pressed. - */ -// Include the Bounce2 library found here : -// https://github.com/thomasfredericks/Bounce2 -#include - -#define BUTTON_PIN 2 -#define LED_PIN 13 - -// Instantiate a Bounce object -Bounce debouncer = Bounce(); - -void setup() { - - // Setup the button with an internal pull-up : - pinMode(BUTTON_PIN,INPUT_PULLUP); - - // After setting up the button, setup the Bounce instance : - debouncer.attach(BUTTON_PIN); - debouncer.interval(5); // interval in ms - - //Setup the LED : - pinMode(LED_PIN,OUTPUT); - -} - -void loop() { - // Update the Bounce instance : - debouncer.update(); - - // Get the updated value : - int value = debouncer.read(); - - // Turn on or off the LED as determined by the state : - if ( value == LOW ) { - digitalWrite(LED_PIN, HIGH ); - } - else { - digitalWrite(LED_PIN, LOW ); - } - -} - - diff --git a/lib/Bounce2/examples/bounce2buttons/bounce2buttons.ino b/lib/Bounce2/examples/bounce2buttons/bounce2buttons.ino deleted file mode 100644 index 416d738..0000000 --- a/lib/Bounce2/examples/bounce2buttons/bounce2buttons.ino +++ /dev/null @@ -1,64 +0,0 @@ - -/* - DESCRIPTION - ==================== - Simple example of the Bounce library that switches the debug LED when - either of 2 buttons are pressed. - */ - -// Include the Bounce2 library found here : -// https://github.com/thomasfredericks/Bounce2 -#include - -#define BUTTON_PIN_1 2 -#define BUTTON_PIN_2 3 - - -#define LED_PIN 13 - -// Instantiate a Bounce object -Bounce debouncer1 = Bounce(); - -// Instantiate another Bounce object -Bounce debouncer2 = Bounce(); - -void setup() { - - // Setup the first button with an internal pull-up : - pinMode(BUTTON_PIN_1,INPUT_PULLUP); - // After setting up the button, setup the Bounce instance : - debouncer1.attach(BUTTON_PIN_1); - debouncer1.interval(5); // interval in ms - - // Setup the second button with an internal pull-up : - pinMode(BUTTON_PIN_2,INPUT_PULLUP); - // After setting up the button, setup the Bounce instance : - debouncer2.attach(BUTTON_PIN_2); - debouncer2.interval(5); // interval in ms - - - //Setup the LED : - pinMode(LED_PIN,OUTPUT); - -} - -void loop() { - // Update the Bounce instances : - debouncer1.update(); - debouncer2.update(); - - // Get the updated value : - int value1 = debouncer1.read(); - int value2 = debouncer2.read(); - - // Turn on the LED if either button is pressed : - if ( value1 == LOW || value2 == LOW ) { - digitalWrite(LED_PIN, HIGH ); - } - else { - digitalWrite(LED_PIN, LOW ); - } - -} - - diff --git a/lib/Bounce2/examples/bounce_multiple/bounce_multiple.ino b/lib/Bounce2/examples/bounce_multiple/bounce_multiple.ino deleted file mode 100644 index 25b92c7..0000000 --- a/lib/Bounce2/examples/bounce_multiple/bounce_multiple.ino +++ /dev/null @@ -1,56 +0,0 @@ -// Detect the falling edge of multiple buttons. -// Eight buttons with internal pullups. -// Toggles a LED when any button is pressed. -// Buttons on pins 2,3,4,5,6,7,8,9 - -// Include the Bounce2 library found here : -// https://github.com/thomasfredericks/Bounce2 -#include - -#define LED_PIN 13 - -#define NUM_BUTTONS 8 -const uint8_t BUTTON_PINS[NUM_BUTTONS] = {2, 3, 4, 5, 6, 7, 8, 9}; - -int ledState = LOW; - -Bounce * buttons = new Bounce[NUM_BUTTONS]; - -void setup() { - - for (int i = 0; i < NUM_BUTTONS; i++) { - buttons[i].attach( BUTTON_PINS[i] , INPUT_PULLUP ); //setup the bounce instance for the current button - buttons[i].interval(25); // interval in ms - } - - // Setup the LED : - pinMode(LED_PIN, OUTPUT); - digitalWrite(LED_PIN, ledState); - - -} - -void loop() { - - bool needToToggleLed = false; - - - for (int i = 0; i < NUM_BUTTONS; i++) { - // Update the Bounce instance : - buttons[i].update(); - // If it fell, flag the need to toggle the LED - if ( buttons[i].fell() ) { - needToToggleLed = true; - } - } - - // if a LED toggle has been flagged : - if ( needToToggleLed ) { - // Toggle LED state : - ledState = !ledState; - digitalWrite(LED_PIN, ledState); - } - - -} - diff --git a/lib/Bounce2/examples/change/change.ino b/lib/Bounce2/examples/change/change.ino deleted file mode 100644 index 0ece35b..0000000 --- a/lib/Bounce2/examples/change/change.ino +++ /dev/null @@ -1,48 +0,0 @@ - -// Detect the falling edge - -// Include the Bounce2 library found here : -// https://github.com/thomasfredericks/Bounce2 -#include - - -#define BUTTON_PIN 2 -#define LED_PIN 13 - -int ledState = LOW; - - -// Instantiate a Bounce object : -Bounce debouncer = Bounce(); - -void setup() { - - // Setup the button with an internal pull-up : - pinMode(BUTTON_PIN,INPUT_PULLUP); - - // After setting up the button, setup the Bounce instance : - debouncer.attach(BUTTON_PIN); - debouncer.interval(500); - - // Setup the LED : - pinMode(LED_PIN,OUTPUT); - digitalWrite(LED_PIN,ledState); - - -} - -void loop() { - - // Update the Bounce instance : - debouncer.update(); - - // Call code if Bounce fell (transition from HIGH to LOW) : - if ( debouncer.fell() ) { - - // Toggle LED state : - ledState = !ledState; - digitalWrite(LED_PIN,ledState); - - } -} - diff --git a/lib/Bounce2/examples/circuit-bounce-change-duration-retrigger.png b/lib/Bounce2/examples/circuit-bounce-change-duration-retrigger.png deleted file mode 100644 index 2e41148..0000000 Binary files a/lib/Bounce2/examples/circuit-bounce-change-duration-retrigger.png and /dev/null differ diff --git a/lib/Bounce2/examples/duration/duration.ino b/lib/Bounce2/examples/duration/duration.ino deleted file mode 100644 index f3189ad..0000000 --- a/lib/Bounce2/examples/duration/duration.ino +++ /dev/null @@ -1,53 +0,0 @@ -/* -DESCRIPTION -==================== -Reports through serial (57600 baud) the time since -a button press (transition from HIGH to LOW). - -*/ - -// Include the Bounce2 library found here : -// https://github.com/thomasfredericks/Bounce2 -#include - - -#define BUTTON_PIN 2 -#define LED_PIN 13 - -// Instantiate a Bounce object : -Bounce debouncer = Bounce(); - -unsigned long buttonPressTimeStamp; - -void setup() { - - Serial.begin(57600); - - // Setup the button with an internal pull-up : - pinMode(BUTTON_PIN,INPUT_PULLUP); - - // After setting up the button, setup the Bounce instance : - debouncer.attach(BUTTON_PIN); - debouncer.interval(5); - - // Setup the LED : - pinMode(LED_PIN,OUTPUT); - -} - -void loop() { - - // Update the Bounce instance : - debouncer.update(); - - // Call code if Bounce fell (transition from HIGH to LOW) : - if ( debouncer.fell() ) {; - - Serial.println( millis()-buttonPressTimeStamp ); - buttonPressTimeStamp = millis(); - - } - - -} - diff --git a/lib/Bounce2/examples/retrigger/retrigger.ino b/lib/Bounce2/examples/retrigger/retrigger.ino deleted file mode 100644 index dfc53fd..0000000 --- a/lib/Bounce2/examples/retrigger/retrigger.ino +++ /dev/null @@ -1,86 +0,0 @@ - -/* -DESCRIPTION -==================== -Example of the bounce library that shows how to retrigger an event when a button is held down. -In this case, the debug LED will blink every 500 ms as long as the button is held down. -Open the Serial Monitor (57600 baud) for debug messages. - -*/ - -// Include the Bounce2 library found here : -// https://github.com/thomasfredericks/Bounce2 -#include - - -#define BUTTON_PIN 2 -#define LED_PIN 13 - -// Instantiate a Bounce object -Bounce debouncer = Bounce(); - -int buttonState; -unsigned long buttonPressTimeStamp; - -int ledState; - -void setup() { - - Serial.begin(57600); - - // Setup the button - pinMode(BUTTON_PIN,INPUT); - // Activate internal pull-up - digitalWrite(BUTTON_PIN,HIGH); - - // After setting up the button, setup debouncer - debouncer.attach(BUTTON_PIN); - debouncer.interval(5); - - //Setup the LED - pinMode(LED_PIN,OUTPUT); - digitalWrite(LED_PIN,ledState); - -} - -void loop() { - // Update the debouncer and get the changed state - boolean changed = debouncer.update(); - - - - if ( changed ) { - // Get the update value - int value = debouncer.read(); - if ( value == HIGH) { - ledState = LOW; - digitalWrite(LED_PIN, ledState ); - - buttonState = 0; - Serial.println("Button released (state 0)"); - - } else { - ledState = HIGH; - digitalWrite(LED_PIN, ledState ); - - buttonState = 1; - Serial.println("Button pressed (state 1)"); - buttonPressTimeStamp = millis(); - - } - } - - if ( buttonState == 1 ) { - if ( millis() - buttonPressTimeStamp >= 500 ) { - buttonPressTimeStamp = millis(); - if ( ledState == HIGH ) ledState = LOW; - else if ( ledState == LOW ) ledState = HIGH; - digitalWrite(LED_PIN, ledState ); - Serial.println("Retriggering button"); - } - } - - -} - - diff --git a/lib/Bounce2/keywords.txt b/lib/Bounce2/keywords.txt deleted file mode 100644 index 22285fe..0000000 --- a/lib/Bounce2/keywords.txt +++ /dev/null @@ -1,29 +0,0 @@ -####################################### -# Syntax Coloring Map For Bounce2 -####################################### - -####################################### -# Datatypes (KEYWORD1) -####################################### - -Bounce KEYWORD1 - -####################################### -# Methods and Functions (KEYWORD2) -####################################### - -update KEYWORD2 -interval KEYWORD2 -read KEYWORD2 -attach KEYWORD2 -rose KEYWORD2 -fell KEYWORD2 - -####################################### -# Instances (KEYWORD2) -####################################### - -####################################### -# Constants (LITERAL1) -####################################### - diff --git a/lib/Bounce2/library.json b/lib/Bounce2/library.json deleted file mode 100644 index 327baa8..0000000 --- a/lib/Bounce2/library.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "Bounce2", - "keywords": "bounce, signal, input, ouput", - "description": "Debouncing library for Arduino or Wiring", - "repository": { - "type": "git", - "url": "https://github.com/thomasfredericks/Bounce2.git" - }, - "version": "2.41", - "exclude": [ - "*.png", - "*.zip" - ], - "frameworks": "arduino", - "platforms": "*" -} diff --git a/lib/Bounce2/library.properties b/lib/Bounce2/library.properties deleted file mode 100644 index ee9933d..0000000 --- a/lib/Bounce2/library.properties +++ /dev/null @@ -1,9 +0,0 @@ -name=Bounce2 -version=2.41 -author=Thomas O Fredericks with contributions fromEric Lowry, Jim Schimpf and Tom Harkaway -maintainer=Thomas O Fredericks -sentence=Debouncing library for Arduino and Wiring. -paragraph=Deboucing switches and toggles is important. -category=Signal Input/Output -url=https://github.com/thomasfredericks/Bounce2 -architectures=* diff --git a/lib/FT18_STW_INIT/FT18_STW_INIT.cpp b/lib/FT18_STW_INIT/FT18_STW_INIT.cpp index 6c19bc4..50dfc6c 100644 --- a/lib/FT18_STW_INIT/FT18_STW_INIT.cpp +++ b/lib/FT18_STW_INIT/FT18_STW_INIT.cpp @@ -1,7 +1,8 @@ -#include "Arduino.h" #include "FT18_STW_INIT.h" -#include "Bounce2.h" -#include "RotaryEncoder.h" + +#include +#include +#include volatile stw_data_type Stw_data = {0}; //alles mit 0 initialisieren volatile vehicle_data_type Vehicle_data = {0}; //alles mit 0 initialisieren @@ -9,7 +10,8 @@ bool enc1PinALast,enc1PinANow,enc2PinALast,enc2PinANow; int led[] = {led1,led2,led3,led4,led5,led6,led7,led8,led9,led10,led11,led12,led13,led14,led15,led16}; bool entprell; int buttons[] = {button1,button2,button3,button4,button5,button6,enc1PinS,enc2PinS}; -Bounce debouncer[8]; +constexpr size_t N_BUTTONS = sizeof(buttons)/sizeof(buttons[0]); +Bounce2::Button debouncer[N_BUTTONS]; double val = 0; double val2 = 0; RotaryEncoder encoder(enc1PinA,enc1PinB,1,1,50); @@ -23,110 +25,41 @@ void set_pins(){ for (int thisLed = 0; thisLed < sizeof(led)/sizeof(int); thisLed++) { pinMode(led[thisLed], OUTPUT); } - /*pinMode(button1, INPUT); - pinMode(button2, INPUT); - pinMode(button3, INPUT); - pinMode(button4, INPUT); - pinMode(button5, INPUT); - pinMode(button6, INPUT);*/ pinMode(enc1PinA, INPUT); pinMode(enc1PinB, INPUT); - //pinMode(enc1PinS, INPUT); pinMode(enc2PinA, INPUT); pinMode(enc2PinB, INPUT); - //pinMode(enc2PinS, INPUT); - //Stw_data.i=0; enc1PinALast=LOW; enc1PinANow=LOW; enc2PinALast=LOW; enc2PinANow=LOW; - for(int i = 0; i < 8; i++){ - pinMode(buttons[i], INPUT); - debouncer[i].attach(buttons[i]); + for(int i = 0; i < N_BUTTONS; i++){ + debouncer[i].attach(buttons[i], INPUT); debouncer[i].interval(10); } } void read_buttons(){ - /*entprell = digitalRead(button3); - delay(10); - if(digitalRead(button3)){ - Stw_data.Stw_auto_shift = entprell; + for (int i = 0; i < N_BUTTONS; i++) { + debouncer[i].update(); } - entprell = digitalRead(button2); - delay(10); - if(digitalRead(button2)){ - Stw_data.Stw_neutral = entprell; - } - entprell = digitalRead(button1); - delay(10); - if(digitalRead(button1)){ - Stw_data.buttonState1 = entprell; - } - entprell = digitalRead(button6); - delay(10); - if(digitalRead(button6)){ - Stw_data.Stw_shift_up = entprell; - } - entprell = digitalRead(button5); - delay(10); - if(digitalRead(button5)){ - Stw_data.Stw_shift_down = entprell; - } - entprell = digitalRead(button4); - delay(10); - if(digitalRead(button4)){ - Stw_data.buttonState4 = entprell; - } - entprell = digitalRead(enc1PinS); - delay(10); - if(digitalRead(enc1PinS)){ - Stw_data.buttonStateEnc1 = entprell; - } - entprell = digitalRead(enc2PinS); - delay(10); - if(digitalRead(enc2PinS)){ - Stw_data.buttonStateEnc2 = entprell; - }*/ - Stw_data.Stw_auto_shift = digitalRead(button3); - Stw_data.Stw_neutral = digitalRead(button2); + + // These are only used to send them out via CAN, so they only need to be + // high once. + Stw_data.Stw_neutral = debouncer[1].rose(); + Stw_data.Stw_auto_shift = debouncer[2].rose(); + Stw_data.Stw_shift_down = debouncer[4].rose(); + Stw_data.Stw_shift_up = debouncer[5].rose(); + + // These are also used for GUI, so if we set them only at rising edge, they + // might never be high when checked in the GUI. + // TODO: Rewrite so we can use debounced values here as well Stw_data.buttonState1 = digitalRead(button1); - Stw_data.Stw_shift_up = digitalRead(button6); - Stw_data.Stw_shift_down = digitalRead(button5); Stw_data.buttonState4 = digitalRead(button4); Stw_data.buttonStateEnc1 = digitalRead(enc1PinS); Stw_data.buttonStateEnc2 = digitalRead(enc2PinS); - - /*for(int i = 0;i < 8; i++){ - debouncer[i].update(); - } - debouncer[2].update(); - if(debouncer[2].fell()){ - Stw_data.Stw_auto_shift = HIGH; - } - if(debouncer[1].fell()){ - Stw_data.Stw_neutral = digitalRead(button2); - } - if(debouncer[0].fell()){ - Stw_data.buttonState1 = digitalRead(button1); - } - if(debouncer[5].fell()){ - Stw_data.Stw_shift_up = digitalRead(button6); - } - if(debouncer[4].fell()){ - Stw_data.Stw_shift_down = digitalRead(button5); - } - if(debouncer[3].fell()){ - Stw_data.buttonState4 = digitalRead(button4); - } - if(debouncer[6].fell()){ - Stw_data.buttonStateEnc1 = digitalRead(enc1PinS); - } - if(debouncer[7].fell()){ - Stw_data.buttonStateEnc2 = digitalRead(enc2PinS); - }*/ - } - +} + void read_rotary(){ int enc = encoder.readEncoder(); int enc2 = encoder2.readEncoder(); diff --git a/platformio.ini b/platformio.ini index 37a40e3..9df821e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,7 +12,9 @@ platform = atmelsam board = due framework = arduino -lib_deps = sebnil/DueFlashStorage@^1.0.0 +lib_deps = + sebnil/DueFlashStorage@^1.0.0 + thomasfredericks/Bounce2@^2.60 [env:combustion] src_filter = +<*> -<18estw.cpp> diff --git a/src/18stw.cpp b/src/18stw.cpp index 83fa4d4..2d7d799 100644 --- a/src/18stw.cpp +++ b/src/18stw.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include