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:
@@ -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