Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
arcadien committed Dec 10, 2023
1 parent 959a0d1 commit ce3a72e
Show file tree
Hide file tree
Showing 18 changed files with 256 additions and 249 deletions.
2 changes: 1 addition & 1 deletion lib/Cross/Gun/Atmega328pHal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* 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 <Contactor.hpp>
#include <Contactor/Contactor.hpp>
#include <Gun/Atmega328pHal.hpp>
#include <LowPower.h>
#include <avr/io.h>
Expand Down
5 changes: 5 additions & 0 deletions lib/Domain/Contactor/Contactor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
*/
#pragma once

/**
* Designed to manage hardware buttons and their different behaviour:
* - short press
* - long press
*/
class Contactor {

static const int LONG_PRESS = 2000;
Expand Down
69 changes: 0 additions & 69 deletions lib/Domain/Game.cpp

This file was deleted.

66 changes: 0 additions & 66 deletions lib/Domain/Game.hpp

This file was deleted.

22 changes: 22 additions & 0 deletions lib/Domain/Game/Basic5/Basic5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

/*
*
* 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 <Game/Basic5/Basic5.hpp>

Player *Basic5::getCurrentPlayer() {
return &this->player;
}
46 changes: 46 additions & 0 deletions lib/Domain/Game/Basic5/Basic5.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
*
* 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 <Game/IGame.hpp>
#include <Game/IGameUi.hpp>

/**
* This game has a single player, who have unlimited
* ammunition to shot the five targets.
*/
class Basic5 : public IGame {

IGameUi *ui;
Player player;

public:
Basic5(IGameUi *ui) : player(0) { this->ui = ui; }

~Basic5() {}

Player *getCurrentPlayer();

void restart() {
ui->restart();
player.restart();
}

void changeCurrentPlayerTo(uint8_t playerId) {
// only one player
}
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
*
* Copyright (c) 2023 Aurélien Labrosse
Expand All @@ -15,49 +16,66 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <TargetHost/BTEGui.hpp>
#include <Game/Basic5/Basic5Ui.hpp>

#if not defined(NATIVE)
#include <Arduino.h>
#endif

static char stringBuffer[64];

static const char *TARGET_TO_WHITE = "*%cR255G255B255*";
static const char *TARGET_TO_BLACK = "**%cR0G0B0*";

void Basic5Ui::restart() { sendUIDescriptionToBluetoothElectronics(); }
void Basic5Ui::displayTarget(const ITarget &target) {}
void Basic5Ui::displayPlayer(const Player &player) {}

/**
* Indirection to easy switch implementation
* and does not pollute main code
*/
void BTEGui::_output(const char *message) {
#if not defined(NATIVE)
Serial.println(stringBuffer);
#else
void Basic5Ui::_output(const char *message) {

#if defined(NATIVE)
out << message << "\n";
#else
Serial.println(message);
#endif
}

void BTEGui::updateTarget(ITarget* target) {
void Basic5Ui::log(const char *message) {
sprintf(stringBuffer, "%s", message);
_output(stringBuffer);
}
void Basic5Ui::log(uint8_t value) {
sprintf(stringBuffer, "%u", value);
_output(stringBuffer);
}

/*
void updateTarget(ITarget *target) {
char letter = TARGET_APP_LETTERS[(uint8_t)target];
sprintf(stringBuffer, "*%cR255G255B255*", letter);
sprintf(stringBuffer, TARGET_TO_WHITE, letter);
_output(stringBuffer);
}
void BTEGui::resetTargets() {
targetState = 0;
void resetTargets() {
for (char letter : TARGET_APP_LETTERS) {
sprintf(stringBuffer, "*%cR0G0B0*", letter);
sprintf(stringBuffer, TARGET_TO_BLACK, letter);
_output(stringBuffer);
}
}
void BTEGui::setCurrentPlayer(uint8_t playerId) {
void setCurrentPlayer(uint8_t playerId) {
if (playerId < 4) {
sprintf(stringBuffer, "*M%s*", PLAYER_COLORS[playerId]);
_output(stringBuffer);
}
}
void BTEGui::displayPlayerInfo(const Player &player) {
void displayPlayerInfo(const Player &player) {
uint8_t baseIndex = player.id * 2;
char totalLetter = PLAYER_DATA_APP_LETTERS[baseIndex];
Expand All @@ -70,18 +88,10 @@ void BTEGui::displayPlayerInfo(const Player &player) {
unsigned(player.getTotalHitCount()));
_output(stringBuffer);
}

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() {
void sendUIDescriptionToBluetoothElectronics() {
Serial.println(F("*.kwl"));
Serial.println(F("clear_panel()"));
Serial.println(F("set_grid_size(21,10)"));
Expand Down Expand Up @@ -129,19 +139,16 @@ static void sendApplication() {
Serial.println(F("*"));
}
#else
static void sendApplication() {}
#endif

void BTEGui::restart() {
sendApplication();
resetTargets();
void Basic5Ui::sendUIDescriptionToBluetoothElectronics() {
_output("Sent UI description over serial link");
}
#endif

const char *BTEGui::PLAYER_COLORS[] = {"Yellow", "Green", "Red", "Blue"};
const char BTEGui::TARGET_APP_LETTERS[5] = {'A', 'Z', 'E', 'R', 'T'};
const char BTEGui::PLAYER_DATA_APP_LETTERS[8] = {
const char *Basic5Ui::PLAYER_COLORS[] = {"Yellow", "Green", "Red", "Blue"};
const char Basic5Ui::TARGET_APP_LETTERS[5] = {'A', 'Z', 'E', 'R', 'T'};
const char Basic5Ui::PLAYER_DATA_APP_LETTERS[8] = {
'Q', 'W', // player 1
'S', 'X', // player 2
'D', 'C', // player 3
'F', 'V' // player 4
};
};
Loading

0 comments on commit ce3a72e

Please sign in to comment.