Added device types and vest mini app
All checks were successful
Deploy Docs / build-and-deploy (push) Successful in 22s
All checks were successful
Deploy Docs / build-and-deploy (push) Successful in 22s
This commit is contained in:
@@ -12,7 +12,7 @@ int main(void)
|
||||
lasertag_utils_init();
|
||||
|
||||
/* Initialize and start BLE management for provisioning */
|
||||
int rc = ble_mgmt_init();
|
||||
int rc = ble_mgmt_init(LT_TYPE_LEADER);
|
||||
if (rc) {
|
||||
LOG_ERR("BLE initialization failed (err %d)", rc);
|
||||
return rc;
|
||||
@@ -20,6 +20,14 @@ int main(void)
|
||||
LOG_INF("BLE Management initialized successfully.");
|
||||
}
|
||||
|
||||
/* Start BLE advertising */
|
||||
rc = ble_mgmt_adv_start();
|
||||
if (rc) {
|
||||
LOG_ERR("BLE advertising start failed (err %d)", rc);
|
||||
} else {
|
||||
LOG_INF("BLE advertising started.");
|
||||
}
|
||||
|
||||
/* Initialize and start OpenThread stack */
|
||||
rc = thread_mgmt_init();
|
||||
if (rc) {
|
||||
|
||||
13
firmware/apps/vest/CMakeLists.txt
Normal file
13
firmware/apps/vest/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
# Tell Zephyr to look into our libs folder for extra modules
|
||||
list(APPEND ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/../../libs)
|
||||
|
||||
# Set board root to find custom board overlays in firmware/boards
|
||||
set(BOARD_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(lasertag_vest)
|
||||
|
||||
# Define application source files
|
||||
target_sources(app PRIVATE src/main.c)
|
||||
41
firmware/apps/vest/prj.conf
Normal file
41
firmware/apps/vest/prj.conf
Normal file
@@ -0,0 +1,41 @@
|
||||
# Console and Logging
|
||||
CONFIG_LOG=y
|
||||
|
||||
# Shell and Built-in Commands
|
||||
CONFIG_SHELL=y
|
||||
CONFIG_KERNEL_SHELL=y
|
||||
CONFIG_DEVICE_SHELL=y
|
||||
CONFIG_REBOOT=y
|
||||
|
||||
# --- STACK SIZE UPDATES (Fixes the Hard Fault) ---
|
||||
CONFIG_MAIN_STACK_SIZE=4096
|
||||
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
|
||||
CONFIG_BT_RX_STACK_SIZE=2048
|
||||
|
||||
# Storage and Settings (NVS)
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_MAP=y
|
||||
CONFIG_NVS=y
|
||||
CONFIG_SETTINGS=y
|
||||
|
||||
# Network and OpenThread
|
||||
CONFIG_NETWORKING=y
|
||||
CONFIG_NET_L2_OPENTHREAD=y
|
||||
CONFIG_OPENTHREAD=y
|
||||
CONFIG_OPENTHREAD_FTD=y
|
||||
CONFIG_OPENTHREAD_SHELL=y
|
||||
|
||||
# --- CoAP & UDP Features ---
|
||||
CONFIG_OPENTHREAD_COAP=y
|
||||
CONFIG_OPENTHREAD_MANUAL_START=y
|
||||
|
||||
# Bluetooth
|
||||
CONFIG_BT=y
|
||||
CONFIG_BT_PERIPHERAL=y
|
||||
CONFIG_BT_DEVICE_NAME="Lasertag-Device"
|
||||
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
|
||||
|
||||
# Enable Lasertag Shared Modules
|
||||
CONFIG_LASERTAG_UTILS=y
|
||||
CONFIG_THREAD_MGMT=y
|
||||
CONFIG_BLE_MGMT=y
|
||||
46
firmware/apps/vest/src/main.c
Normal file
46
firmware/apps/vest/src/main.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <lasertag_utils.h>
|
||||
#include <thread_mgmt.h>
|
||||
#include <ble_mgmt.h>
|
||||
|
||||
LOG_MODULE_REGISTER(vest_app, CONFIG_LOG_DEFAULT_LEVEL);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* Initialize shared project logic and NVS */
|
||||
lasertag_utils_init();
|
||||
|
||||
/* Initialize and start BLE management for provisioning */
|
||||
int rc = ble_mgmt_init(LT_TYPE_VEST);
|
||||
if (rc) {
|
||||
LOG_ERR("BLE initialization failed (err %d)", rc);
|
||||
return rc;
|
||||
} else {
|
||||
LOG_INF("BLE Management initialized successfully.");
|
||||
}
|
||||
|
||||
/* Start BLE advertising */
|
||||
rc = ble_mgmt_adv_start();
|
||||
if (rc) {
|
||||
LOG_ERR("BLE advertising start failed (err %d)", rc);
|
||||
} else {
|
||||
LOG_INF("BLE advertising started.");
|
||||
}
|
||||
|
||||
/* Initialize and start OpenThread stack */
|
||||
rc = thread_mgmt_init();
|
||||
if (rc) {
|
||||
LOG_ERR("Thread initialization failed (err %d)", rc);
|
||||
} else {
|
||||
LOG_INF("Leader Application successfully started with Thread Mesh.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
/* Main loop - handle high-level game logic here */
|
||||
k_sleep(K_MSEC(1000));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
# Zephyr mitteilen, dass unsere Libs Teil des Projekts sind
|
||||
# Tell Zephyr that our libs are part of the project
|
||||
list(APPEND ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/../../libs)
|
||||
|
||||
# Set board root to find custom board overlays in firmware/boards
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
#include <openthread/thread.h>
|
||||
#include <openthread/coap.h>
|
||||
|
||||
/* Unsere neue Library */
|
||||
/* Our new library */
|
||||
#include "game_logic.h"
|
||||
|
||||
LOG_MODULE_REGISTER(weapon_app, LOG_LEVEL_INF);
|
||||
|
||||
/* Spiel-Kontext */
|
||||
/* Game context */
|
||||
static struct game_ctx game;
|
||||
|
||||
/* Forward Declarations */
|
||||
@@ -19,15 +19,15 @@ static void on_button_changed(uint32_t button_state, uint32_t has_changed);
|
||||
|
||||
static void on_game_state_change(enum game_state new_state)
|
||||
{
|
||||
LOG_INF("APP: Spielstatus geändert -> %d", new_state);
|
||||
LOG_INF("APP: Game state changed -> %d", new_state);
|
||||
|
||||
switch (new_state) {
|
||||
case GAME_STATE_RUNNING:
|
||||
dk_set_led_on(DK_LED1); // LED an wenn Spiel läuft
|
||||
dk_set_led_on(DK_LED1); // LED on when game is running
|
||||
break;
|
||||
case GAME_STATE_FINISHED:
|
||||
dk_set_led_off(DK_LED1);
|
||||
// Blinken oder ähnliches
|
||||
// Blink or similar
|
||||
break;
|
||||
default:
|
||||
dk_set_led_off(DK_LED1);
|
||||
@@ -37,46 +37,46 @@ static void on_game_state_change(enum game_state new_state)
|
||||
|
||||
static void on_hit_received(uint16_t shooter_id)
|
||||
{
|
||||
LOG_WARN("APP: AUA! Getroffen von Spieler %d. Leben: %d", shooter_id, game.health);
|
||||
LOG_WARN("APP: OUCH! Hit by player %d. Health: %d", shooter_id, game.health);
|
||||
|
||||
// Visuelles Feedback: LED 2 blinkt kurz
|
||||
dk_set_led_on(DK_LED2);
|
||||
k_msleep(200);
|
||||
dk_set_led_off(DK_LED2);
|
||||
|
||||
// TODO: Hier später CoAP Nachricht an Leader senden!
|
||||
// TODO: Send CoAP message to leader later!
|
||||
// send_hit_report_to_leader(...);
|
||||
}
|
||||
|
||||
static void on_shot_fired(void)
|
||||
{
|
||||
LOG_INF("APP: PENG! Schuss abgefeuert.");
|
||||
// TODO: Hier IR-Protokoll senden (NEC/RC5)
|
||||
LOG_INF("APP: BANG! Shot fired.");
|
||||
// TODO: Send IR protocol here (NEC/RC5)
|
||||
}
|
||||
|
||||
/* --- Hardware Callbacks --- */
|
||||
|
||||
static void on_button_changed(uint32_t button_state, uint32_t has_changed)
|
||||
{
|
||||
// Button 1: Schießen
|
||||
// Button 1: Shoot
|
||||
if ((has_changed & DK_BTN1_MSK) && (button_state & DK_BTN1_MSK)) {
|
||||
if (game.current_state == GAME_STATE_RUNNING) {
|
||||
on_shot_fired();
|
||||
} else {
|
||||
LOG_INF("Schuss blockiert - Spiel läuft nicht.");
|
||||
LOG_INF("Shot blocked - game not running.");
|
||||
}
|
||||
}
|
||||
|
||||
// Button 2: Treffer simulieren (Self-Hit Test)
|
||||
// Button 2: Simulate hit (Self-Hit Test)
|
||||
if ((has_changed & DK_BTN2_MSK) && (button_state & DK_BTN2_MSK)) {
|
||||
LOG_INF("Simuliere Treffer durch Spieler 99...");
|
||||
LOG_INF("Simulating hit by player 99...");
|
||||
struct game_hit_packet hit_packet;
|
||||
|
||||
// Wir tun so, als hätte der IR-Sensor Spieler 99 erkannt
|
||||
// Pretend the IR sensor detected player 99
|
||||
if (game_logic_register_hit(99, &hit_packet)) {
|
||||
// Wenn Treffer gültig war (Spiel läuft, wir leben noch), haben wir jetzt ein Paket
|
||||
// das wir via Thread versenden könnten.
|
||||
LOG_INF("Treffer registriert! Damage: %d", hit_packet.damage);
|
||||
// If hit was valid (game running, we're still alive), we now have a packet
|
||||
// that we could send via Thread.
|
||||
LOG_INF("Hit registered! Damage: %d", hit_packet.damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,18 +89,18 @@ void main(void)
|
||||
|
||||
int err = dk_buttons_init(on_button_changed);
|
||||
if (err) {
|
||||
LOG_ERR("Buttons konnten nicht initialisiert werden (err %d)", err);
|
||||
LOG_ERR("Buttons could not be initialized (err %d)", err);
|
||||
}
|
||||
|
||||
// Game Logic Setup
|
||||
game.on_state_change = on_game_state_change;
|
||||
game.on_hit_received = on_hit_received;
|
||||
|
||||
// Initialisiere als Spieler mit ID aus Kconfig (oder NVS später)
|
||||
// Initialize as player with ID from Kconfig (or NVS later)
|
||||
game_logic_init(&game, CONFIG_LASERTAG_PLAYER_ID_DEFAULT);
|
||||
|
||||
// Zum Testen setzen wir den Status manuell auf RUNNING,
|
||||
// bis wir das Start-Signal vom Leader via Thread empfangen.
|
||||
// For testing, we manually set the status to RUNNING,
|
||||
// until we receive the start signal from the leader via Thread.
|
||||
struct game_state_packet fake_start = {.state = GAME_STATE_RUNNING};
|
||||
game_logic_handle_state_update(&fake_start);
|
||||
|
||||
|
||||
@@ -15,6 +15,6 @@ CONFIG_LASERTAG_GAME_LOGIC=y
|
||||
CONFIG_LASERTAG_ROLE_PLAYER=y
|
||||
CONFIG_LASERTAG_PLAYER_ID_DEFAULT=2
|
||||
|
||||
# Optional: Shell für Debugging
|
||||
# Optional: Shell for debugging
|
||||
CONFIG_SHELL=y
|
||||
CONFIG_OPENTHREAD_SHELL=y
|
||||
Reference in New Issue
Block a user