diff --git a/sufst-controller/lapTimer.cpp b/sufst-controller/lapTimer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..076e80943b39977c96de0d1138110a677fe60908 --- /dev/null +++ b/sufst-controller/lapTimer.cpp @@ -0,0 +1,32 @@ +// +// Created by Sil on 01/08/2019. +// + +#include "lapTimer.h" +#include "wireless.h" + +void lapTimerISR() +{ + static uint8_t lapTimerPayload[6]; + + static uint32_t lastTriggeredMs = 0; + + uint32_t currentMs = millis(); + + if ((currentMs - lastTriggeredMs) >= LAP_TIMER_DEBOUNCE_MS) { + lapTimerPayload[0] = 0xFF; + + memcpy(&(lapTimerPayload[1]), currentMs, 4); + + lapTimerPayload[5] = 0xFF; + + wirelessWrite(lapTimerPayload, 6); + + lastTriggeredMs = millis(); + } +} + +void lapTimerBegin() +{ + attachInterrupt(digitalPinToInterrupt(LAP_TIMER_INT_PIN), lapTimerISR, FALLING); +} diff --git a/sufst-controller/lapTimer.h b/sufst-controller/lapTimer.h new file mode 100644 index 0000000000000000000000000000000000000000..cd63f94ae9664aacccdacfb07f622b6cbfa7d7a0 --- /dev/null +++ b/sufst-controller/lapTimer.h @@ -0,0 +1,15 @@ +// +// Created by Sil on 01/08/2019. +// + +#ifndef LAPTIMER_H +#define LAPTIMER_H + +#include "Arduino.h" + +#define LAP_TIMER_INT_PIN 21 +#define LAP_TIMER_DEBOUNCE_MS 1000 + +void lapTimerBegin(); + +#endif //LAPTIMER_H diff --git a/sufst-controller/sufst-controller.ino b/sufst-controller/sufst-controller.ino index df4ac30685d0b1f84a72b152258458c192fe7371..fe7b2e6215ba039b87497ce8933d910c64482b9f 100644 --- a/sufst-controller/sufst-controller.ino +++ b/sufst-controller/sufst-controller.ino @@ -2,7 +2,8 @@ #include "ecuCan.h" #include "can.h" #include "dashController.h" -// #include "wireless.h" +#include "wireless.h" +#include "lapTimer.h" void setup() { @@ -15,10 +16,9 @@ void setup() // Serial.println("BEGIN"); dashBegin(); - sdBegin(); - canBegin(); + lapTimerBegin(); } void loop() @@ -28,6 +28,7 @@ void loop() /* * ALL PROCESSES *MUST* BE NON BLOCKING */ + canProcessRx(); dashControllerProcess(); sdProcess();