Tripple click checked on core 0

This commit is contained in:
Lukas Bachschwell 2018-04-28 13:37:51 +02:00
parent 5645bb8846
commit ccbb719c9b
3 changed files with 63 additions and 9 deletions

View File

@ -16,6 +16,7 @@ framework = arduino
src_filter = +<remote.cpp> src_filter = +<remote.cpp>
monitor_baud = 115200 monitor_baud = 115200
upload_speed = 921600
[env:receiver] [env:receiver]
@ -26,6 +27,7 @@ framework = arduino
src_filter = +<receiver.cpp> src_filter = +<receiver.cpp>
monitor_baud = 115200 monitor_baud = 115200
upload_speed = 921600
lib_deps = lib_deps =
# Using a library name # Using a library name

View File

@ -223,9 +223,6 @@ void checkVoltage() {
Serial.print("Voltage: "); Serial.print("Voltage: ");
Serial.println(batteryVoltage); Serial.println(batteryVoltage);
digitalWrite(voltageEnable, LOW); // change to low digitalWrite(voltageEnable, LOW); // change to low
delay(5);
Serial.print("VoltageOFF: ");
Serial.println(analogRead(voltagePin));
} }
void setup() { void setup() {
@ -238,6 +235,7 @@ void setup() {
display.setFont(ArialMT_Plain_16); display.setFont(ArialMT_Plain_16);
pinMode(voltageEnable, OUTPUT); pinMode(voltageEnable, OUTPUT);
pinMode(fanRelais, OUTPUT);
// Init escs, min and max value similar as Traxxas TQI 1100, 1900 // Init escs, min and max value similar as Traxxas TQI 1100, 1900
// chanel, minAngel, maxAngel, minPulseWidth, maxPulseWidth // chanel, minAngel, maxAngel, minPulseWidth, maxPulseWidth
@ -246,7 +244,6 @@ void setup() {
sensors.begin(); sensors.begin();
pinMode(fanRelais, OUTPUT);
//Set device in AP mode to begin with //Set device in AP mode to begin with
WiFi.mode(WIFI_AP); WiFi.mode(WIFI_AP);

View File

@ -11,6 +11,8 @@
#include "accel.h" #include "accel.h"
TaskHandle_t clickTaskHandle;
#define B_VOLT 0 #define B_VOLT 0
#define B_VOLT_D 1 #define B_VOLT_D 1
#define B_TEMP 2 #define B_TEMP 2
@ -22,6 +24,11 @@ uint8_t boardData[6] = {0, 0, 0, 0, 0, 0};
bool connected = false; bool connected = false;
uint8_t clickCounter = 0;
bool lastTriggerState = false;
long lastClick = 0;
#define clickDiff 250
// Defining variables for OLED display // Defining variables for OLED display
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2 (U8G2_R2, /* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16); U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2 (U8G2_R2, /* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16);
char displayBuffer[20]; char displayBuffer[20];
@ -35,6 +42,9 @@ unsigned long lastDataRotation;
bool changeSettings = false; bool changeSettings = false;
bool changeSelectedSetting = false; bool changeSelectedSetting = false;
bool beginnerMode = false;
bool steeringMode = false;
bool settingsLoopFlag = false; bool settingsLoopFlag = false;
bool settingsChangeFlag = false; bool settingsChangeFlag = false;
bool settingsChangeValueFlag = false; bool settingsChangeValueFlag = false;
@ -278,10 +288,15 @@ bool inRange(int val, int minimum, int maximum) {
// Return true if trigger is activated, false otherwice // Return true if trigger is activated, false otherwice
bool triggerActive() { bool triggerActive() {
if (digitalRead(triggerPin) == LOW) if (digitalRead(triggerPin) == LOW) {
return true; vTaskDelay(pdMS_TO_TICKS(0.1));
else if (digitalRead(triggerPin) == LOW) return true;
return false; } else {
vTaskDelay(pdMS_TO_TICKS(0.1));
if (digitalRead(triggerPin) == HIGH) return false;
}
return false; // biased to false
} }
void calculateThrottlePosition() { void calculateThrottlePosition() {
@ -352,6 +367,36 @@ int getStrength(int points){
return averageRSSI; 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 //############ End Hardware Helpers
//############ Drawing Functions //############ Drawing Functions
@ -550,6 +595,7 @@ void drawSettingsMenu() {
} }
*/ */
} }
void controlSettingsMenu() { void controlSettingsMenu() {
/* /*
if (triggerActive()) { if (triggerActive()) {
@ -668,6 +714,15 @@ void setup() {
// setup other pins // setup other pins
pinMode(triggerPin, INPUT_PULLUP); pinMode(triggerPin, INPUT_PULLUP);
xTaskCreatePinnedToCore(
checkClicks,
"click task",
1000,
NULL,
1,
&clickTaskHandle,
0);
initAccel(); initAccel();
Serial.println("ESPNowSkate Sender"); Serial.println("ESPNowSkate Sender");