diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 0b13bc8..27f4b32 100755 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -21,6 +21,7 @@ RUN apt-get update \ python3-setuptools \ srecord \ udev \ + socat \ xz-utils \ && apt-get autoremove -y \ && apt-get clean -y \ diff --git a/lib/Gui/BTEGui.cpp b/lib/Domain/BTEGui.cpp similarity index 100% rename from lib/Gui/BTEGui.cpp rename to lib/Domain/BTEGui.cpp diff --git a/lib/Gui/BTEGui.hpp b/lib/Domain/BTEGui.hpp similarity index 97% rename from lib/Gui/BTEGui.hpp rename to lib/Domain/BTEGui.hpp index 1fdfada..52868f5 100644 --- a/lib/Gui/BTEGui.hpp +++ b/lib/Domain/BTEGui.hpp @@ -19,9 +19,7 @@ #include #include -#if defined(AVR) -#include -#else +#if not defined(AVR) #include #endif diff --git a/lib/Game/Game.cpp b/lib/Domain/Game.cpp similarity index 100% rename from lib/Game/Game.cpp rename to lib/Domain/Game.cpp diff --git a/lib/Game/Game.hpp b/lib/Domain/Game.hpp similarity index 100% rename from lib/Game/Game.hpp rename to lib/Domain/Game.hpp diff --git a/lib/Gun/Gun.cpp b/lib/Domain/Gun.cpp similarity index 100% rename from lib/Gun/Gun.cpp rename to lib/Domain/Gun.cpp diff --git a/lib/Gun/Gun.hpp b/lib/Domain/Gun.hpp similarity index 100% rename from lib/Gun/Gun.hpp rename to lib/Domain/Gun.hpp diff --git a/lib/Gun/IGunHal.hpp b/lib/Domain/IGunHal.hpp similarity index 100% rename from lib/Gun/IGunHal.hpp rename to lib/Domain/IGunHal.hpp diff --git a/lib/Gui/ITargetGui.hpp b/lib/Domain/ITargetGui.hpp similarity index 100% rename from lib/Gui/ITargetGui.hpp rename to lib/Domain/ITargetGui.hpp diff --git a/lib/Player/Player.cpp b/lib/Domain/Player.cpp similarity index 100% rename from lib/Player/Player.cpp rename to lib/Domain/Player.cpp diff --git a/lib/Player/Player.hpp b/lib/Domain/Player.hpp similarity index 100% rename from lib/Player/Player.hpp rename to lib/Domain/Player.hpp diff --git a/lib/Gui/TestGui.hpp b/lib/Native/TestGui.hpp similarity index 93% rename from lib/Gui/TestGui.hpp rename to lib/Native/TestGui.hpp index ec4c63b..e277d5c 100644 --- a/lib/Gui/TestGui.hpp +++ b/lib/Native/TestGui.hpp @@ -16,7 +16,7 @@ */ #pragma once #include -#include +#include class TestGui : public ITargetGui { @@ -28,7 +28,7 @@ class TestGui : public ITargetGui { void hitTarget(ITargetGui::TARGET target) override { targetState |= (1 << target); } bool isTargetHit(ITargetGui::TARGET target) override { - return (targetState & (1 << target) == (1 << target)); + return ( (targetState & (1 << target)) == (1 << target)); } void setCurrentPlayer(uint8_t playerId) override {} diff --git a/platformio.ini b/platformio.ini index 8e86062..fc298af 100755 --- a/platformio.ini +++ b/platformio.ini @@ -5,7 +5,7 @@ lib_compat_mode=off ; these libraries are for AVR and simulation ; targets only, so a reset of this property ; is needed in the `native` configuration -lib_deps = +lib_deps = #upload_protocol=custom #upload_flags = @@ -41,7 +41,7 @@ upload_command = avrdude -vv -pm328p -c avrisp -P/dev/ttyS0 $UPLOAD_FLAGS -U fla test_ignore = cross/* build_flags = -DNATIVE debug_test = noarch/test_gun - build_src_filter = ${env.src_filter} - - + build_src_filter = ${env.src_filter} - - [env:native_debug] lib_deps = ${env.lib_deps} @@ -51,21 +51,22 @@ upload_command = avrdude -vv -pm328p -c avrisp -P/dev/ttyS0 $UPLOAD_FLAGS -U fla debug_build_flags = -Og -ggdb3 -g3 -DNATIVE -UAVR test_ignore = cross/* debug_test = noarch/test_gun - build_src_filter = ${env.src_filter} - - + build_src_filter = ${env.src_filter} - - [env:cross] lib_deps = ${env.lib_deps} test_framework = unity platform = atmelavr + framework = arduino board = ATmega328P build_type = release test_ignore = native/* build_flags = -O0 - build_src_filter = ${env.src_filter} - + build_src_filter = ${env.src_filter} - [env:target] lib_deps = - ${env.lib_deps} + ${env.lib_deps} SerialCommands framework = arduino platform = atmelavr @@ -74,7 +75,9 @@ upload_command = avrdude -vv -pm328p -c avrisp -P/dev/ttyS0 $UPLOAD_FLAGS -U fla board_build.f_cpu = 16000000L build_type = release build_flags = -DAVR - build_src_filter = ${env.src_filter} - - + test_ignore = + native/* + build_src_filter = ${env.src_filter} - - [env:gun] lib_deps = @@ -82,4 +85,7 @@ upload_command = avrdude -vv -pm328p -c avrisp -P/dev/ttyS0 $UPLOAD_FLAGS -U fla board = attiny84 build_type = release build_flags = -DAVR - build_src_filter = ${env.src_filter} - - \ No newline at end of file + test_ignore = + native/* + noarch/* + build_src_filter = ${env.src_filter} - - \ No newline at end of file diff --git a/src/consoleApp.cpp b/src/ConsoleTargets.cpp similarity index 100% rename from src/consoleApp.cpp rename to src/ConsoleTargets.cpp diff --git a/src/gun.cpp b/src/GunApp.cpp similarity index 96% rename from src/gun.cpp rename to src/GunApp.cpp index 12653ea..f47a32b 100644 --- a/src/gun.cpp +++ b/src/GunApp.cpp @@ -1,23 +1,23 @@ -/* - * - * Copyright (c) 2023 Aurelien 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 . - */ - -int main(void) -{ - while (1) - { - } -} +/* + * + * Copyright (c) 2023 Aurelien 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 . + */ + +int main(void) +{ + while (1) + { + } +} diff --git a/src/target.cpp b/src/TargetApp.cpp similarity index 96% rename from src/target.cpp rename to src/TargetApp.cpp index 513f1af..18a914e 100644 --- a/src/target.cpp +++ b/src/TargetApp.cpp @@ -1,177 +1,178 @@ -/* - * - * Copyright (c) 2023 Aurelien 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 . - */ - -#include -#include -#include - -#define TARGET_A_PIN A0 -#define TARGET_Z_PIN A1 -#define TARGET_E_PIN A2 -#define TARGET_R_PIN A3 -#define TARGET_T_PIN A4 - -#define LED_PIN 9 - -char serial_command_buffer_[32]; -SerialCommands serial_commands_(&Serial, serial_command_buffer_, - sizeof(serial_command_buffer_), "|", " "); -void cmd_unrecognized(SerialCommands *sender, const char *cmd); -void cmd_resetTargets(SerialCommands *sender); -void cmd_setThreshold(SerialCommands *sender); -void cmd_nextRound(SerialCommands *sender); -void cmd_changePlayer(SerialCommands *sender); - -SerialCommand cmd_nextRound_("N", &cmd_nextRound); -SerialCommand cmd_resetTargets_("R", &cmd_resetTargets); -SerialCommand cmd_setThreshold_("T", &cmd_setThreshold); -SerialCommand cmd_changePlayer_("P", &cmd_changePlayer); - -void serialPrintInfo(uint16_t value); -void ledOn(); -void ledOff(); - -// laser detection threshold -uint16_t threshold; - -// ambient light ADC value -uint16_t reference; - -BTEGui gui; -Game game(&gui); - -void setup() { - - pinMode(LED_PIN, OUTPUT); - ledOff(); - - pinMode(TARGET_A_PIN, INPUT); - pinMode(TARGET_Z_PIN, INPUT); - pinMode(TARGET_E_PIN, INPUT); - pinMode(TARGET_R_PIN, INPUT); - pinMode(TARGET_T_PIN, INPUT); - - serial_commands_.SetDefaultHandler(cmd_unrecognized); - serial_commands_.AddCommand(&cmd_resetTargets_); - serial_commands_.AddCommand(&cmd_setThreshold_); - serial_commands_.AddCommand(&cmd_nextRound_); - serial_commands_.AddCommand(&cmd_changePlayer_); - - analogRead(TARGET_A_PIN); - analogRead(TARGET_Z_PIN); - analogRead(TARGET_E_PIN); - analogRead(TARGET_R_PIN); - analogRead(TARGET_T_PIN); - - reference = 0; - - reference += analogRead(TARGET_A_PIN); - reference += analogRead(TARGET_Z_PIN); - reference += analogRead(TARGET_E_PIN); - reference += analogRead(TARGET_R_PIN); - reference += analogRead(TARGET_T_PIN); - reference /= 5; - - // initial value sent by GUI at startup - threshold = 500; - - Serial.begin(115200); - - game.reset(); - serial_commands_.ReadSerial(); -} - -static void _recordHit() { - game.recordSucceededShoot(); - ledOn(); - delay(100); - ledOff(); -} - -static void _checkHit(uint16_t value, ITargetGui::TARGET target) { - if (value > threshold) { - if (!gui.isTargetHit(target)) { - gui.hitTarget(target); - _recordHit(); - } - } -} - -void loop() { - - uint16_t value1 = analogRead(A0); - uint16_t value2 = analogRead(A1); - uint16_t value3 = analogRead(A2); - uint16_t value4 = analogRead(A3); - uint16_t value5 = analogRead(A4); - - _checkHit(value1, ITargetGui::TARGET::One); - _checkHit(value2, ITargetGui::TARGET::Two); - _checkHit(value3, ITargetGui::TARGET::Three); - _checkHit(value4, ITargetGui::TARGET::Four); - _checkHit(value5, ITargetGui::TARGET::Five); - - serial_commands_.ReadSerial(); - delay(5); -} - -void serialPrintInfo(uint16_t value) { - if (value > 0) { - Serial.print(F("HV: ")); - Serial.println(value); - } -} -void cmd_unrecognized(SerialCommands *sender, const char *cmd) { - sender->GetSerial()->print("Unrecognized command ["); - sender->GetSerial()->print(cmd); - sender->GetSerial()->println("]"); -} -void cmd_setThreshold(SerialCommands *sender) { - uint16_t value = atoi(sender->Next()); - if (value > 0 && value != threshold) { - threshold = value; - Serial.print(F("VThresh: ")); - Serial.println(threshold); - Serial.print(F("Vref: ")); - Serial.println(reference); - } -} -void cmd_changePlayer(SerialCommands *sender) { - uint8_t playerId = (uint8_t)atoi(sender->Next()); - game.changeCurrentPlayerTo(playerId); -} -void cmd_resetTargets(SerialCommands *sender) { - - (void)sender; - game.reset(); - serialPrintInfo(0); - ledOn(); - delay(200); - ledOff(); - delay(200); - ledOn(); - delay(200); - ledOff(); -} -void cmd_nextRound(SerialCommands *sender) { - gui.resetTargets(); - game.nextRound(); - gui.setCurrentPlayer(game.currentPlayer->id); -} - -void ledOff() { digitalWrite(LED_PIN, HIGH); } +/* + * + * Copyright (c) 2023 Aurelien 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 . + */ + +#include +#include + +#include + +#define TARGET_A_PIN A0 +#define TARGET_Z_PIN A1 +#define TARGET_E_PIN A2 +#define TARGET_R_PIN A3 +#define TARGET_T_PIN A4 + +#define LED_PIN 9 + +char serial_command_buffer_[32]; +SerialCommands serial_commands_(&Serial, serial_command_buffer_, + sizeof(serial_command_buffer_), "|", " "); +void cmd_unrecognized(SerialCommands *sender, const char *cmd); +void cmd_resetTargets(SerialCommands *sender); +void cmd_setThreshold(SerialCommands *sender); +void cmd_nextRound(SerialCommands *sender); +void cmd_changePlayer(SerialCommands *sender); + +SerialCommand cmd_nextRound_("N", &cmd_nextRound); +SerialCommand cmd_resetTargets_("R", &cmd_resetTargets); +SerialCommand cmd_setThreshold_("T", &cmd_setThreshold); +SerialCommand cmd_changePlayer_("P", &cmd_changePlayer); + +void serialPrintInfo(uint16_t value); +void ledOn(); +void ledOff(); + +// laser detection threshold +uint16_t threshold; + +// ambient light ADC value +uint16_t reference; + +BTEGui gui; +Game game(&gui); + +void setup() { + + pinMode(LED_PIN, OUTPUT); + ledOff(); + + pinMode(TARGET_A_PIN, INPUT); + pinMode(TARGET_Z_PIN, INPUT); + pinMode(TARGET_E_PIN, INPUT); + pinMode(TARGET_R_PIN, INPUT); + pinMode(TARGET_T_PIN, INPUT); + + serial_commands_.SetDefaultHandler(cmd_unrecognized); + serial_commands_.AddCommand(&cmd_resetTargets_); + serial_commands_.AddCommand(&cmd_setThreshold_); + serial_commands_.AddCommand(&cmd_nextRound_); + serial_commands_.AddCommand(&cmd_changePlayer_); + + analogRead(TARGET_A_PIN); + analogRead(TARGET_Z_PIN); + analogRead(TARGET_E_PIN); + analogRead(TARGET_R_PIN); + analogRead(TARGET_T_PIN); + + reference = 0; + + reference += analogRead(TARGET_A_PIN); + reference += analogRead(TARGET_Z_PIN); + reference += analogRead(TARGET_E_PIN); + reference += analogRead(TARGET_R_PIN); + reference += analogRead(TARGET_T_PIN); + reference /= 5; + + // initial value sent by GUI at startup + threshold = 500; + + Serial.begin(115200); + + game.reset(); + serial_commands_.ReadSerial(); +} + +static void _recordHit() { + game.recordSucceededShoot(); + ledOn(); + delay(100); + ledOff(); +} + +static void _checkHit(uint16_t value, ITargetGui::TARGET target) { + if (value > threshold) { + if (!gui.isTargetHit(target)) { + gui.hitTarget(target); + _recordHit(); + } + } +} + +void loop() { + + uint16_t value1 = analogRead(A0); + uint16_t value2 = analogRead(A1); + uint16_t value3 = analogRead(A2); + uint16_t value4 = analogRead(A3); + uint16_t value5 = analogRead(A4); + + _checkHit(value1, ITargetGui::TARGET::One); + _checkHit(value2, ITargetGui::TARGET::Two); + _checkHit(value3, ITargetGui::TARGET::Three); + _checkHit(value4, ITargetGui::TARGET::Four); + _checkHit(value5, ITargetGui::TARGET::Five); + + serial_commands_.ReadSerial(); + delay(5); +} + +void serialPrintInfo(uint16_t value) { + if (value > 0) { + Serial.print(F("HV: ")); + Serial.println(value); + } +} +void cmd_unrecognized(SerialCommands *sender, const char *cmd) { + sender->GetSerial()->print("Unrecognized command ["); + sender->GetSerial()->print(cmd); + sender->GetSerial()->println("]"); +} +void cmd_setThreshold(SerialCommands *sender) { + uint16_t value = atoi(sender->Next()); + if (value > 0 && value != threshold) { + threshold = value; + Serial.print(F("VThresh: ")); + Serial.println(threshold); + Serial.print(F("Vref: ")); + Serial.println(reference); + } +} +void cmd_changePlayer(SerialCommands *sender) { + uint8_t playerId = (uint8_t)atoi(sender->Next()); + game.changeCurrentPlayerTo(playerId); +} +void cmd_resetTargets(SerialCommands *sender) { + + (void)sender; + game.reset(); + serialPrintInfo(0); + ledOn(); + delay(200); + ledOff(); + delay(200); + ledOn(); + delay(200); + ledOff(); +} +void cmd_nextRound(SerialCommands *sender) { + gui.resetTargets(); + game.nextRound(); + gui.setCurrentPlayer(game.currentPlayer->id); +} + +void ledOff() { digitalWrite(LED_PIN, HIGH); } void ledOn() { digitalWrite(LED_PIN, LOW); } \ No newline at end of file diff --git a/test/noarch/test_BTEGui/BTEGui.cpp b/test/native/test_BTEGui/BTEGui.cpp similarity index 99% rename from test/noarch/test_BTEGui/BTEGui.cpp rename to test/native/test_BTEGui/BTEGui.cpp index 5cb09ef..072e834 100644 --- a/test/noarch/test_BTEGui/BTEGui.cpp +++ b/test/native/test_BTEGui/BTEGui.cpp @@ -16,7 +16,6 @@ */ #include -#include #include #include #include