Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New implementation for target host #13

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ jobs:
- name: Test project in native environment
run: pio test -e native

- name: Build console application
- name: Build native console application
run: pio run -e native

- name: Build 'target' cross application
run: pio run -e target

- name: Build 'gun' cross application
- name: Build cross Gun application
run: pio run -e gun

- name: Build cross Target application
run: pio run -e target

- name: Archive test console application
uses: actions/upload-artifact@v3
with:
Expand Down
22 changes: 11 additions & 11 deletions lib/Domain/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
// 5 rounds per player
static const uint8_t TOTAL_ROUNDS = 20;

Game::Game(ITargetGui *gui) {
this->gui = gui;
Game::Game(ITargetUi *ui) {
this->ui = ui;
currentRound = 0;
currentPlayer = &players[0];
}

void Game::recordSucceededShoot() {
currentPlayer->recordSucceededShoot();
gui->displayPlayerInfo(*currentPlayer);
ui->displayPlayerInfo(*currentPlayer);
}

/**
Expand All @@ -47,7 +47,7 @@ void Game::nextRound() {
currentPlayer = &players[nextPlayerId];

currentPlayer->startRound();
gui->displayPlayerInfo(*currentPlayer);
ui->displayPlayerInfo(*currentPlayer);
}

bool Game::isFinished() {
Expand All @@ -60,21 +60,21 @@ void Game::changeCurrentPlayerTo(uint8_t playerIndex) {
currentPlayer->endRound();
currentPlayer = &players[playerIndex];
currentPlayer->startRound();
gui->setCurrentPlayer(playerIndex);
gui->resetTargets();
gui->displayPlayerInfo(*currentPlayer);
ui->setCurrentPlayer(playerIndex);
ui->resetTargets();
ui->displayPlayerInfo(*currentPlayer);
}
}

void Game::reset() {
gui->restart();
ui->restart();
for (Player &player : players) {
player.reset();
gui->displayPlayerInfo(player);
ui->displayPlayerInfo(player);
}
currentRound = 0;
currentPlayer = &players[0];
currentPlayer->startRound();
gui->displayPlayerInfo(*currentPlayer);
gui->setCurrentPlayer(0);
ui->displayPlayerInfo(*currentPlayer);
ui->setCurrentPlayer(0);
}
6 changes: 3 additions & 3 deletions lib/Domain/Game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
#pragma once

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

#include <stdint.h>
Expand All @@ -26,7 +26,7 @@
*/
class Game {

ITargetGui *gui;
ITargetUi *ui;

public:
static const uint8_t PLAYER_COUNT = 4;
Expand All @@ -43,7 +43,7 @@ class Game {
uint8_t currentRound;
Player *currentPlayer;

Game(ITargetGui *);
Game(ITargetUi *ui);

void recordSucceededShoot();

Expand Down
22 changes: 15 additions & 7 deletions 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 All @@ -35,15 +35,15 @@ void BTEGui::_output(const char *message) {
#endif
}

void BTEGui::hitTarget(ITargetGui::TARGET target) {
void BTEGui::hitTarget(ITargetUi::TARGET target) {
targetState |= (1 << target);
char letter = TARGET_APP_LETTERS[(uint8_t)target];

sprintf(stringBuffer, "*%cR255G255B255*", letter);
_output(stringBuffer);
}

bool BTEGui::isTargetHit(ITargetGui::TARGET target) {
bool BTEGui::isTargetHit(ITargetUi::TARGET target) {
return ((targetState & (1 << target)) == (1 << target));
}

Expand Down Expand Up @@ -76,15 +76,23 @@ void BTEGui::displayPlayerInfo(const Player &player) {
_output(stringBuffer);
}

#if defined(AVR)
void BTEGui::log(const char *message) {
sprintf(stringBuffer, "%s", message);
_output(stringBuffer);
}
void BTEGui::log(uint8_t value) {
sprintf(stringBuffer, "%u", value);
_output(stringBuffer);
}

#if not defined(NATIVE)
static void sendApplication() {
Serial.println(F("*.kwl"));
Serial.println(F("clear_panel()"));
Serial.println(F("set_grid_size(21,10)"));

// current player
Serial.println(
F("add_text(4,8,xlarge,L,Current player: , 245, 240, 245,)"));
Serial.println(F("add_text(4,8,xlarge,L,Current player: , 245, 240, 245,)"));
Serial.println(F("add_text(10,8,xlarge,C,1,245,240,245,M)"));

// targets
Expand Down Expand Up @@ -118,7 +126,7 @@ static void sendApplication() {
Serial.println(F("add_button(19,5,25,N,|)"));

Serial.println(F("add_button(0,8,30,R,|)"));
Serial.println(F("add_slider(10,9,8,100,1024,500,T ,|,1)"));
Serial.println(F("add_slider(10,9,8,1,50,1,T ,|,1)"));

Serial.println(F("add_monitor(18,8,3,,1)"));
Serial.println(F("set_panel_notes(-,,,)"));
Expand Down
10 changes: 6 additions & 4 deletions 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 <ITargetGui.hpp>
#include <Target/ITargetUi.hpp>
#include <stdint.h>

#if not defined(AVR)
Expand All @@ -26,7 +26,7 @@
/**
* GUI for Bluetooth Electronics interface (Android)
*/
class BTEGui : public ITargetGui {
class BTEGui : public ITargetUi {
uint8_t targetState;

/* Bluetooth application uses a letter to identify which widget
Expand Down Expand Up @@ -60,9 +60,11 @@ class BTEGui : public ITargetGui {
#endif

void setCurrentPlayer(uint8_t playerId) override;
void hitTarget(ITargetGui::TARGET target) override;
bool isTargetHit(ITargetGui::TARGET target) override;
void hitTarget(ITargetUi::TARGET target) override;
bool isTargetHit(ITargetUi::TARGET target);
void resetTargets() override;
void displayPlayerInfo(const Player &player) override;
void restart() override;
void log(const char *) override;
void log(uint8_t value) override;
};
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;
};
39 changes: 15 additions & 24 deletions lib/Domain/ITargetGui.hpp → lib/Domain/Target/ITargetUi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,37 @@
*/
#pragma once

#include <stdint.h>
#include <Player.hpp>
#include <stdint.h>

class ITargetGui {
class ITargetUi {
public:

enum TARGET{
One = 0,
Two,
Three,
Four,
Five
};
enum TARGET { One = 0, Two, Three, Four, Five };

virtual ~ITargetGui() {}
virtual ~ITargetUi() {}

/**
* Tell GUI a target has been hit
*/
*/
virtual void hitTarget(TARGET) = 0;

/**
* Ask GUI if a target has been hit
*/
virtual bool isTargetHit(TARGET) = 0;

/**
* Reset target hit status
*/
*/
virtual void resetTargets() = 0;

virtual void setCurrentPlayer(uint8_t playerId) = 0;

/*
* Send player info : id, shoots and hit shoots
*
*
*/
virtual void displayPlayerInfo(const Player&) = 0;
* Send player info : id, shoots and hit shoots
*
*
*/
virtual void displayPlayerInfo(const Player &) = 0;

virtual void restart() = 0;


virtual void log(const char *) = 0;

virtual void log(uint8_t value) = 0;
};
Loading
Loading