From 74b130df3ee6676b144f87c00ecca539ddbe4110 Mon Sep 17 00:00:00 2001 From: nrs1g15 <nrs1g15@soton.ac.uk> Date: Thu, 1 Aug 2019 22:38:05 +0100 Subject: [PATCH] lap timer --- sufst-controller/lapTimer.cpp | 32 +++++++++++++++++++++++++++ sufst-controller/lapTimer.h | 15 +++++++++++++ sufst-controller/sufst-controller.ino | 7 +++--- 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 sufst-controller/lapTimer.cpp create mode 100644 sufst-controller/lapTimer.h diff --git a/sufst-controller/lapTimer.cpp b/sufst-controller/lapTimer.cpp new file mode 100644 index 0000000..076e809 --- /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 0000000..cd63f94 --- /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 df4ac30..fe7b2e6 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(); -- GitLab