From 0e0f83905bb3ee79f4917927479cdaf710e8ac07 Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 9 Oct 2025 21:43:08 -0400 Subject: Complete input and led part of project --- project/Core/Src/Project/project.c | 96 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) (limited to 'project/Core/Src/Project/project.c') diff --git a/project/Core/Src/Project/project.c b/project/Core/Src/Project/project.c index d029e0b..379f380 100644 --- a/project/Core/Src/Project/project.c +++ b/project/Core/Src/Project/project.c @@ -6,3 +6,99 @@ */ #include "project.h" +#include "LED.h" +#include "systick.h" +#include +#include "hw4.h" +#include + +#define PLAYING_STATE (1) +#define PAUSED_STATE (2) +#define STOPPED_STATE (3) + +void handle_input(char buffer[], uint8_t *state); +void help(); +void next(); +void play(); +void pause(); +void pause_loop(); +void stop(); + +void project_run() { + char buffer[8]; + char* cur = buffer; + uint8_t state = STOPPED_STATE; + + help(); + for (;;) { + if (state == PAUSED_STATE) + pause_loop(); + char ch = read_and_print_char_nonblocking(); + if (!ch) + continue; + if (ch == '\r') { + *cur = 0; + handle_input(buffer, &state); + cur = buffer; + continue; + } + *cur++ = ch; + } +} + +void handle_input(char buffer[], uint8_t *state) { + if (!strcmp(buffer, "HELP")) { + help(); + } + else if (!strcmp(buffer, "NEXT")) { + next(); + } + else if (!strcmp(buffer, "PLAY")) { + play(); + *state = PLAYING_STATE; + } + else if (!strcmp(buffer, "PAUSE")) { + pause(); + *state = PAUSED_STATE; + } + else if (!strcmp(buffer, "STOP")) { + stop(); + *state = STOPPED_STATE; + } + else { + printf("Unknown command \"%s\"\n\r", buffer); + } +} + +void help() { + printf("\r***REMOTE LED CONTROL MENU***\r\n"); + printf("Available User Commands:\r\n"); + printf("NEXT - Show next song info\r\n"); + printf("PLAY - Play the song (LED on)\r\n"); + printf("PAUSE - Pause the song (LED flash)\r\n"); + printf("STOP - Stop the song (LED off)\r\n"); +} + +void next() { + // TODO +} + +void play() { + LED_On(); +} + +void pause() { + init_systick(); +} + +void pause_loop() { + if (check_systick()) { + LED_Toggle(); + } +} + +void stop() { + LED_Off(); +} + + -- cgit v1.2.3