From bd4714ffb0d5715e69198a0ceb314346c66fc1e7 Mon Sep 17 00:00:00 2001 From: Aurelien Labrosse Date: Fri, 17 Nov 2023 22:50:51 +0100 Subject: [PATCH] wip --- lib/Domain/ITargetHost.hpp | 51 +++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/lib/Domain/ITargetHost.hpp b/lib/Domain/ITargetHost.hpp index 7afe92f..b014526 100644 --- a/lib/Domain/ITargetHost.hpp +++ b/lib/Domain/ITargetHost.hpp @@ -18,17 +18,60 @@ #include +enum TargetState { Calibrating, Ready, Hit }; +enum Color { None, Red, Green, Blue }; + +class ITargetHal { + + virtual uint16_t getLuminosity() = 0; + virtual void setLedColor(Color color) = 0; +}; + /** * A target is considered hit if its * luminosity value exceed (ambientValue + threshold) + * A target has a multicolor led: Off is ready, green is shot, blue is + * calibration, red is error */ -class Target { +class Target : public ITargetHal { + + TargetState state; + uint8_t luminosityPin; + public: uint16_t ambientValue; - bool isHit; - uint8_t pin; uint8_t index; - Target() : ambientValue(0), isHit(false), pin(0) {} + Target(uint8_t luminosityPin luminosityPin) + : ambientValue(0), luminosityPin(luminosityPin) { + ready(); + } + + TargetState getState() { return state; } + + void hit() { + state = Hit; + setLedColor(Green); + } + + void ready() { + state = Ready; + setLedColor(None); + } + + void calibrate() { + state = Calibrating; + setLedColor(Blue); + getLuminosity(); + ambientValue = getLuminosity(); + ambientValue += getLuminosity(); + ambientValue += getLuminosity(); + ambientValue += getLuminosity(); + ambientValue /= 4; + ready(); + } + + uint16_t getLuminosity() override { return analogRead(luminosityPin); } + void setLedColor(Color color) override{}; }; class ITargetHost {