aboutsummaryrefslogtreecommitdiff
path: root/puzzle
diff options
context:
space:
mode:
Diffstat (limited to 'puzzle')
-rw-r--r--puzzle/smoketest/CMakeLists.txt7
-rw-r--r--puzzle/smoketest/main.cpp67
2 files changed, 12 insertions, 62 deletions
diff --git a/puzzle/smoketest/CMakeLists.txt b/puzzle/smoketest/CMakeLists.txt
index 08e828b..b71825f 100644
--- a/puzzle/smoketest/CMakeLists.txt
+++ b/puzzle/smoketest/CMakeLists.txt
@@ -10,8 +10,8 @@ add_compile_definitions(DEBUG)
# arduino
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/lib/Arduino-CMake-Toolchain/Arduino-toolchain.cmake)
-set(ARDUINO_BOARD "Arduino Mega or Mega 2560 [avr.mega]")
-#set(ARDUINO_BOARD "Arduino Uno [avr.uno]")
+# set(ARDUINO_BOARD "Arduino Mega or Mega 2560 [avr.mega]")
+set(ARDUINO_BOARD "Arduino Uno [avr.uno]")
# freertos
add_library(freertos_config INTERFACE)
@@ -19,7 +19,7 @@ target_include_directories(freertos_config SYSTEM INTERFACE .)
set(FREERTOS_PORT GCC_ATMEGA)
set(FREERTOS_HEAP 4)
-project(pb_mod_vault C CXX)
+project(pb_mod_smoketest C CXX)
add_subdirectory(lib/pbdrv)
add_subdirectory(lib/FreeRTOS-Kernel)
@@ -35,7 +35,6 @@ target_link_libraries(main PUBLIC
target_link_arduino_libraries(main PUBLIC
core
Wire
- TM1637
)
target_enable_arduino_upload(main)
diff --git a/puzzle/smoketest/main.cpp b/puzzle/smoketest/main.cpp
index b125254..dc15e5f 100644
--- a/puzzle/smoketest/main.cpp
+++ b/puzzle/smoketest/main.cpp
@@ -3,75 +3,26 @@
#include "lib/pbdrv/pb-mod.h"
#define EXTERNAL_LED_PIN 13
-#define BUTTON_PIN 10 // Define the pin where the external button is connected
+#define BUTTON_PIN 10 // Define the pin where the external button is connected
-// Puzzle state
-pb_global_state_t puzzleState = PB_GS_NOINIT;
-
-unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
-unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
-int lastButtonState = HIGH; // the previous reading from the input pin
-int buttonState = HIGH; // the current state of the button
+pb_global_state_t state = PB_GS_NOINIT;
void setup() {
- Serial.begin(115200);
pinMode(EXTERNAL_LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
- digitalWrite(EXTERNAL_LED_PIN, LOW); // Ensure the external LED is off initially
-
- Serial.println("System initialized.");
-}
-
-void led_blink(int time){
- digitalWrite(EXTERNAL_LED_PIN, HIGH);
- delay(time);
- digitalWrite(EXTERNAL_LED_PIN, LOW);
- delay(time);
}
pb_global_state_t pb_hook_mod_state_read() {
- return puzzleState;
-}
-
-void pb_hook_mod_state_write(pb_global_state_t state) {
- puzzleState = state;
+ return state;
}
-void pb_hook_ev_main_state_update(pb_global_state_t state){
- Serial.println("WE IN BOISS");
-}
-
-void checkButtonPress() {
- int reading = digitalRead(BUTTON_PIN); // read the current state of the button
-
- if (reading != lastButtonState) {
- Serial.println("Button pressed, changing state to SOLVED.");
- pb_hook_mod_state_write(PB_GS_SOLVED);
- lastDebounceTime = millis(); // reset debouncing timer
- }
-
- if ((millis() - lastDebounceTime) > debounceDelay) {
- lastButtonState = reading; // update the last state for next comparison
- }
+void pb_hook_mod_state_write(pb_global_state_t _state) {
+ state = _state;
}
void loop() {
- switch(puzzleState) {
- case PB_GS_PLAYING:
- digitalWrite(EXTERNAL_LED_PIN, LOW); // LED is off in PLAYING state
- checkButtonPress();
- break;
- case PB_GS_SOLVED:
- Serial.println("STATE = PB_GS_SOLVED");
- digitalWrite(EXTERNAL_LED_PIN, HIGH); // LED is on in SOLVED state
- break;
- case PB_GS_NOINIT:
- Serial.println("STATE = PB_GS_NOINIT");
- led_blink(100); // Blink LED rapidly in NOINIT state
- break;
- case PB_GS_IDLE:
- Serial.println("STATE = PB_GS_IDLE");
- led_blink(500); // Blink LED slowly in IDLE state
- break;
- }
+ digitalWrite(EXTERNAL_LED_PIN, state == PB_GS_PLAYING);
+
+ if (!digitalRead(BUTTON_PIN)) return;
+ state = PB_GS_SOLVED;
}