-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
268 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
/* | ||
* | ||
* Copyright (c) 2023 Aurélien Labrosse | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
class ITarget { | ||
|
||
public: | ||
enum State { Calibrating, Ready, Hit, Error }; | ||
|
||
virtual ~ITarget() {} | ||
|
||
/** | ||
* @brief transition to Ready state | ||
* | ||
*/ | ||
virtual void reset() = 0; | ||
|
||
/** | ||
* @brief transition to Calibration state | ||
* | ||
*/ | ||
virtual void calibrate() = 0; | ||
|
||
/** | ||
* @brief transition to Hit state | ||
* | ||
*/ | ||
virtual void hit() = 0; | ||
|
||
virtual uint16_t getLuminosity() = 0; | ||
|
||
virtual State getState() = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 Aurélien Labrosse | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#pragma once | ||
|
||
#include <Target/ITarget.hpp> | ||
#include <stdint.h> | ||
|
||
/** | ||
* @brief Target host is a device managing 5 targets | ||
* | ||
* 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 ITargetHost { | ||
|
||
|
||
public: | ||
|
||
virtual ~ITargetHost() {} | ||
|
||
virtual void reset() = 0; | ||
|
||
/** | ||
* Notification led on | ||
*/ | ||
virtual void ledOn() = 0; | ||
|
||
/** | ||
* Notification led off | ||
*/ | ||
virtual void ledOff() = 0; | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 Aurélien Labrosse | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#include <Arduino.h> | ||
#include <Target/LDRTarget.hpp> | ||
|
||
LDRTarget::LDRTarget(uint8_t luminosityPin) | ||
: ambiantLuminosity(0), luminosityPin(luminosityPin), state(Ready), | ||
threshold(0) {} | ||
|
||
void LDRTarget::reset() { state = Ready; } | ||
|
||
void LDRTarget::calibrate() { | ||
state = Calibrating; | ||
getLuminosity(); | ||
ambiantLuminosity = getLuminosity(); | ||
ambiantLuminosity += getLuminosity(); | ||
ambiantLuminosity += getLuminosity(); | ||
ambiantLuminosity += getLuminosity(); | ||
ambiantLuminosity /= 4; | ||
reset(); | ||
} | ||
|
||
boolean LDRTarget::check() { | ||
return (getLuminosity() > (ambiantLuminosity + threshold)); | ||
} | ||
|
||
void LDRTarget::hit() { state = Hit; } | ||
|
||
void LDRTarget::setThreshold(uint8_t threshold) { this->threshold = threshold; } | ||
|
||
uint16_t LDRTarget::getLuminosity() { | ||
return analogRead(luminosityPin); | ||
} | ||
|
||
ITarget::State LDRTarget::getState() { return state; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
/* | ||
* | ||
* Copyright (c) 2023 Aurélien Labrosse | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#pragma once | ||
#include <Target/ITarget.hpp> | ||
|
||
// forward declaration | ||
class TargetHost; | ||
|
||
class LDRTarget : public ITarget { | ||
|
||
uint16_t ambiantLuminosity; | ||
uint8_t luminosityPin; | ||
State state; | ||
uint8_t threshold; | ||
|
||
public: | ||
LDRTarget(uint8_t luminosityPin); | ||
|
||
void reset() override; | ||
void calibrate() override; | ||
void hit() override; | ||
uint16_t getLuminosity() override; | ||
State getState() override; | ||
|
||
/** | ||
* @brief Set the difference with ambiant luminosity level that triggers a hit | ||
* condition | ||
* | ||
* @param threshold | ||
*/ | ||
void setThreshold(uint8_t threshold); | ||
|
||
/** | ||
* @brief Check if target is in hit condition | ||
* | ||
*/ | ||
bool check(); | ||
}; |
Oops, something went wrong.