Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
arcadien committed Nov 30, 2023
1 parent bd4714f commit f98524f
Show file tree
Hide file tree
Showing 15 changed files with 268 additions and 184 deletions.
2 changes: 1 addition & 1 deletion lib/Domain/Game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
#pragma once

#include <ITargetUi.hpp>
#include <Target/ITargetUi.hpp>
#include <Player.hpp>

#include <stdint.h>
Expand Down
104 changes: 0 additions & 104 deletions lib/Domain/ITargetHost.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion lib/Domain/BTEGui.cpp → lib/Domain/Target/BTEGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <BTEGui.hpp>
#include <Target/BTEGui.hpp>

#if not defined(NATIVE)
#include <Arduino.h>
Expand Down
2 changes: 1 addition & 1 deletion lib/Domain/BTEGui.hpp → lib/Domain/Target/BTEGui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
#pragma once

#include <ITargetUi.hpp>
#include <Target/ITargetUi.hpp>
#include <stdint.h>

#if not defined(AVR)
Expand Down
50 changes: 50 additions & 0 deletions lib/Domain/Target/ITarget.hpp
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;
};
48 changes: 48 additions & 0 deletions lib/Domain/Target/ITargetHost.hpp
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.
49 changes: 49 additions & 0 deletions lib/Domain/Target/LDRTarget.cpp
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; }
53 changes: 53 additions & 0 deletions lib/Domain/Target/LDRTarget.hpp
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();
};
Loading

0 comments on commit f98524f

Please sign in to comment.