From ccbb719c9bc4a090870d7620435629972af314a4 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Sat, 28 Apr 2018 13:37:51 +0200 Subject: [PATCH] Tripple click checked on core 0 --- platformio.ini | 4 ++- src/receiver.cpp | 5 +--- src/remote.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/platformio.ini b/platformio.ini index ade5b98..29072f0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,7 +16,8 @@ framework = arduino src_filter = + monitor_baud = 115200 - +upload_speed = 921600 + [env:receiver] platform = espressif32 @@ -26,6 +27,7 @@ framework = arduino src_filter = + monitor_baud = 115200 +upload_speed = 921600 lib_deps = # Using a library name diff --git a/src/receiver.cpp b/src/receiver.cpp index 262a0bd..1a5824f 100644 --- a/src/receiver.cpp +++ b/src/receiver.cpp @@ -223,9 +223,6 @@ void checkVoltage() { Serial.print("Voltage: "); Serial.println(batteryVoltage); digitalWrite(voltageEnable, LOW); // change to low - delay(5); - Serial.print("VoltageOFF: "); - Serial.println(analogRead(voltagePin)); } void setup() { @@ -238,6 +235,7 @@ void setup() { display.setFont(ArialMT_Plain_16); pinMode(voltageEnable, OUTPUT); + pinMode(fanRelais, OUTPUT); // Init escs, min and max value similar as Traxxas TQI 1100, 1900 // chanel, minAngel, maxAngel, minPulseWidth, maxPulseWidth @@ -246,7 +244,6 @@ void setup() { sensors.begin(); - pinMode(fanRelais, OUTPUT); //Set device in AP mode to begin with WiFi.mode(WIFI_AP); diff --git a/src/remote.cpp b/src/remote.cpp index 36b13ee..b068a2d 100644 --- a/src/remote.cpp +++ b/src/remote.cpp @@ -11,6 +11,8 @@ #include "accel.h" +TaskHandle_t clickTaskHandle; + #define B_VOLT 0 #define B_VOLT_D 1 #define B_TEMP 2 @@ -22,6 +24,11 @@ uint8_t boardData[6] = {0, 0, 0, 0, 0, 0}; bool connected = false; +uint8_t clickCounter = 0; +bool lastTriggerState = false; +long lastClick = 0; +#define clickDiff 250 + // Defining variables for OLED display U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2 (U8G2_R2, /* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16); char displayBuffer[20]; @@ -35,6 +42,9 @@ unsigned long lastDataRotation; bool changeSettings = false; bool changeSelectedSetting = false; +bool beginnerMode = false; +bool steeringMode = false; + bool settingsLoopFlag = false; bool settingsChangeFlag = false; bool settingsChangeValueFlag = false; @@ -278,10 +288,15 @@ bool inRange(int val, int minimum, int maximum) { // Return true if trigger is activated, false otherwice bool triggerActive() { - if (digitalRead(triggerPin) == LOW) - return true; - else - return false; + if (digitalRead(triggerPin) == LOW) { + vTaskDelay(pdMS_TO_TICKS(0.1)); + if (digitalRead(triggerPin) == LOW) return true; + } else { + vTaskDelay(pdMS_TO_TICKS(0.1)); + if (digitalRead(triggerPin) == HIGH) return false; + } + + return false; // biased to false } void calculateThrottlePosition() { @@ -352,6 +367,36 @@ int getStrength(int points){ return averageRSSI; } +void checkClicks(void * parameter) { + for (;;) { + //Serial.print("Trig: "); Serial.print(triggerActive()); Serial.print(" LAST: "); Serial.println(lastTriggerState); + if(millis()-lastClick > clickDiff && clickCounter!=0) { + Serial.println("reset"); + clickCounter = 0; + } + + if(!triggerActive() && lastTriggerState) { + Serial.println("CLICK##################### "); + int timeSinceLastClick = millis()-lastClick; + lastClick = millis(); + + if(timeSinceLastClick < clickDiff) clickCounter++; + else clickCounter = 1; + if(clickCounter == 3) { + Serial.println("YEAH TRIPPLE"); + steeringMode = !steeringMode; + vTaskDelay(pdMS_TO_TICKS(2000)); + } + + lastClick = millis(); + lastTriggerState = false; + } else if(triggerActive()) { + lastTriggerState = true; + } + vTaskDelay(pdMS_TO_TICKS(20)); + } +} + //############ End Hardware Helpers //############ Drawing Functions @@ -550,6 +595,7 @@ void drawSettingsMenu() { } */ } + void controlSettingsMenu() { /* if (triggerActive()) { @@ -668,6 +714,15 @@ void setup() { // setup other pins pinMode(triggerPin, INPUT_PULLUP); + xTaskCreatePinnedToCore( + checkClicks, + "click task", + 1000, + NULL, + 1, + &clickTaskHandle, + 0); + initAccel(); Serial.println("ESPNowSkate Sender");