diff options
| author | Christian Krinitsin <mail@krinitsin.com> | 2025-03-26 20:47:12 +0100 |
|---|---|---|
| committer | Christian Krinitsin <mail@krinitsin.com> | 2025-03-26 20:47:12 +0100 |
| commit | 32a24182ad8cd2fc3a9125cb8f70de3b9c22f9a4 (patch) | |
| tree | f2d3a9a1696d50ae28e88e9ba94684bf5ffee5d3 /firmware/src | |
| parent | 6b3fb653f8b342d8ecfc093a000e9f6fa479c644 (diff) | |
| download | tetris-console-32a24182ad8cd2fc3a9125cb8f70de3b9c22f9a4.tar.gz tetris-console-32a24182ad8cd2fc3a9125cb8f70de3b9c22f9a4.zip | |
add preliminary public apis
Diffstat (limited to 'firmware/src')
| -rw-r--r-- | firmware/src/game/game_state.cpp | 9 | ||||
| -rw-r--r-- | firmware/src/inputs/button.cpp | 18 | ||||
| -rw-r--r-- | firmware/src/inputs/input.cpp | 69 | ||||
| -rw-r--r-- | firmware/src/main.cpp | 23 | ||||
| -rw-r--r-- | firmware/src/ui/ui.cpp | 21 |
5 files changed, 124 insertions, 16 deletions
diff --git a/firmware/src/game/game_state.cpp b/firmware/src/game/game_state.cpp new file mode 100644 index 0000000..219c627 --- /dev/null +++ b/firmware/src/game/game_state.cpp @@ -0,0 +1,9 @@ +#include "game/game_state.h" + +namespace game { + +GameState::GameState() {} + +void GameState::update(const inputs::Input& input) {} + +} diff --git a/firmware/src/inputs/button.cpp b/firmware/src/inputs/button.cpp new file mode 100644 index 0000000..ed02e32 --- /dev/null +++ b/firmware/src/inputs/button.cpp @@ -0,0 +1,18 @@ +#include "inputs/button.h" + +namespace inputs { + +Button::Button(uint8_t pin) + : pin { pin } +{ +} + +void Button::init() {} + +bool Button::is_pressed() +{ + // TODO + return false; +} + +} diff --git a/firmware/src/inputs/input.cpp b/firmware/src/inputs/input.cpp new file mode 100644 index 0000000..6f4109b --- /dev/null +++ b/firmware/src/inputs/input.cpp @@ -0,0 +1,69 @@ +#include "inputs/input.h" + +namespace inputs { + +Input::Input( + uint8_t down_pin, + uint8_t up_pin, + uint8_t right_pin, + uint8_t left_pin, + uint8_t a_pin, + uint8_t b_pin, + uint8_t pause_pin) + : down { down_pin } + , up { up_pin } + , right { right_pin } + , left { left_pin } + , a { a_pin } + , b { b_pin } + , pause { pause_pin } +{ +} + +void Input::init() +{ + down.init(); + up.init(); + left.init(); + right.init(); + a.init(); + b.init(); + pause.init(); +} + +bool Input::down_pressed() +{ + return down.is_pressed(); +} + +bool Input::up_pressed() +{ + return up.is_pressed(); +} + +bool Input::left_pressed() +{ + return left.is_pressed(); +} + +bool Input::right_pressed() +{ + return right.is_pressed(); +} + +bool Input::a_pressed() +{ + return a.is_pressed(); +} + +bool Input::b_pressed() +{ + return b.is_pressed(); +} + +bool Input::pause_pressed() +{ + return pause.is_pressed(); +} + +} diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index c512327..cb41c45 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -1,31 +1,22 @@ #include <Arduino.h> +#include "game/game_state.h" #include "inputs/input.h" +#include "ui/ui.h" game::GameState state {}; -ui::UI ui { /* pins */ }; -inputs::Input input { /* pins */ }; +ui::UI screen { 0, 0, 0 }; // TODO: add correct pins +inputs::Input input { 0, 0, 0, 0, 0, 0, 0 }; // TODO: add correct pins void setup() { - state.init(); input.init(); - ui.init(); + screen.init(); } void loop() { delay(1); - - if (input.down_pressed()) { - // TODO - } - - // update game state - // render game state - - // every second - // automatically move down - // update game state - // render game state + state.update(input); + screen.render_screen(state); } diff --git a/firmware/src/ui/ui.cpp b/firmware/src/ui/ui.cpp new file mode 100644 index 0000000..af27b37 --- /dev/null +++ b/firmware/src/ui/ui.cpp @@ -0,0 +1,21 @@ +#include "ui/ui.h" +#include "game/game_state.h" + +namespace ui { + +UI::UI(int8_t tft_cs, int8_t tft_rst, int8_t tft_dc) + : tft { tft_cs, tft_rst, tft_dc } +{ +} + +void UI::init() +{ + tft.initR(INITR_BLACKTAB); +} + +void UI::render_screen(const game::GameState& state) +{ + // TODO +} + +} |