diff options
Diffstat (limited to 'puzzle/smoketest')
-rw-r--r-- | puzzle/smoketest/CMakeLists.txt | 42 | ||||
-rw-r--r-- | puzzle/smoketest/FreeRTOSConfig.h | 52 | ||||
-rw-r--r-- | puzzle/smoketest/index.dox | 11 | ||||
l--------- | puzzle/smoketest/lib | 1 | ||||
-rw-r--r-- | puzzle/smoketest/main.cpp | 77 | ||||
-rw-r--r-- | puzzle/smoketest/makefile | 8 | ||||
-rw-r--r-- | puzzle/smoketest/mod.c | 6 |
7 files changed, 197 insertions, 0 deletions
diff --git a/puzzle/smoketest/CMakeLists.txt b/puzzle/smoketest/CMakeLists.txt new file mode 100644 index 0000000..08e828b --- /dev/null +++ b/puzzle/smoketest/CMakeLists.txt @@ -0,0 +1,42 @@ +cmake_minimum_required(VERSION 3.29) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_EXPORT_COMPILE_COMMANDS 1) + +# enable debug features +set(CMAKE_BUILD_TYPE Debug) +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]") + +# freertos +add_library(freertos_config INTERFACE) +target_include_directories(freertos_config SYSTEM INTERFACE .) +set(FREERTOS_PORT GCC_ATMEGA) +set(FREERTOS_HEAP 4) + +project(pb_mod_vault C CXX) + +add_subdirectory(lib/pbdrv) +add_subdirectory(lib/FreeRTOS-Kernel) + +add_executable(main + main.cpp + mod.c + ) + +target_link_libraries(main PUBLIC + pbdrv-mod + ) +target_link_arduino_libraries(main PUBLIC + core + Wire + TM1637 + ) + +target_enable_arduino_upload(main) + diff --git a/puzzle/smoketest/FreeRTOSConfig.h b/puzzle/smoketest/FreeRTOSConfig.h new file mode 100644 index 0000000..81c487f --- /dev/null +++ b/puzzle/smoketest/FreeRTOSConfig.h @@ -0,0 +1,52 @@ +#pragma once + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configMAX_PRIORITIES 32 +#define configMINIMAL_STACK_SIZE ((configSTACK_DEPTH_TYPE) 192) +#define configUSE_16_BIT_TICKS 1 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configUSE_QUEUE_SETS 0 +#define configUSE_TIME_SLICING 1 +#define configSTACK_DEPTH_TYPE uint16_t +#define configSUPPORT_STATIC_ALLOCATION 0 +#define configSUPPORT_DYNAMIC_ALLOCATION 1 +// #define configTOTAL_HEAP_SIZE (1024) +#define configTOTAL_HEAP_SIZE (1 * 1024) +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_DAEMON_TASK_STARTUP_HOOK 0 +#define configGENERATE_RUN_TIME_STATS 0 +#define configUSE_TRACE_FACILITY 0 +#define configUSE_STATS_FORMATTING_FUNCTIONS 0 +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH 92 + +#include <assert.h> +#define configASSERT(x) assert(x) + +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTaskGetCurrentTaskHandle 1 +#define INCLUDE_uxTaskGetStackHighWaterMark 1 +#define INCLUDE_xTaskGetIdleTaskHandle 1 +#define INCLUDE_eTaskGetState 1 +#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_xTaskAbortDelay 1 +#define INCLUDE_xTaskGetHandle 1 +#define INCLUDE_xTaskResumeFromISR 1 +#define INCLUDE_xQueueGetMutexHolder 1 + diff --git a/puzzle/smoketest/index.dox b/puzzle/smoketest/index.dox new file mode 100644 index 0000000..15eae1f --- /dev/null +++ b/puzzle/smoketest/index.dox @@ -0,0 +1,11 @@ +// vim:ft=doxygen +/** +\ingroup puz +\defgroup puz_vault Vault +\brief Vault puzzle module + +\par Setup +- Use the Arduino IDE library manager to install the "TM1637" library (by + Avishay Orpaz) and its dependencies + +*/ diff --git a/puzzle/smoketest/lib b/puzzle/smoketest/lib new file mode 120000 index 0000000..58677dd --- /dev/null +++ b/puzzle/smoketest/lib @@ -0,0 +1 @@ +../../lib
\ No newline at end of file diff --git a/puzzle/smoketest/main.cpp b/puzzle/smoketest/main.cpp new file mode 100644 index 0000000..b125254 --- /dev/null +++ b/puzzle/smoketest/main.cpp @@ -0,0 +1,77 @@ +#include <Arduino.h> +#include "lib/pbdrv/pb-types.h" +#include "lib/pbdrv/pb-mod.h" + +#define EXTERNAL_LED_PIN 13 +#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 + +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; +} + +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 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; + } +} diff --git a/puzzle/smoketest/makefile b/puzzle/smoketest/makefile new file mode 100644 index 0000000..6b8341b --- /dev/null +++ b/puzzle/smoketest/makefile @@ -0,0 +1,8 @@ +TARGET = $(BUILD_DIR)/main.elf + +include ../../lazy.mk + +export SERIAL_PORT ?= /dev/ttyACM0 +flash: upload; +upload: $(TARGET) + diff --git a/puzzle/smoketest/mod.c b/puzzle/smoketest/mod.c new file mode 100644 index 0000000..bae8a3d --- /dev/null +++ b/puzzle/smoketest/mod.c @@ -0,0 +1,6 @@ +#include "pb.h" +#include "pb-mod.h" + +const char * PB_MOD_NAME = "vault"; +const i2c_addr_t PB_MOD_ADDR = PB_ADDR_MOD_VAULT; + |