summaryrefslogtreecommitdiff
path: root/project/Core/Src/Project
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-10-09 21:43:08 -0400
committersowgro <tpoke.ferrari@gmail.com>2025-10-09 21:43:08 -0400
commit0e0f83905bb3ee79f4917927479cdaf710e8ac07 (patch)
treed7c1184e0d6732e671f2c72fc2fc7a10231b8fda /project/Core/Src/Project
parent003bf896a726b2e3496c7b429f648b8db9c36a3b (diff)
download340-repo-Sowgro-0e0f83905bb3ee79f4917927479cdaf710e8ac07.tar.gz
340-repo-Sowgro-0e0f83905bb3ee79f4917927479cdaf710e8ac07.tar.bz2
340-repo-Sowgro-0e0f83905bb3ee79f4917927479cdaf710e8ac07.zip
Complete input and led part of project
Diffstat (limited to '')
-rw-r--r--project/Core/Src/Project/project.c96
1 files changed, 96 insertions, 0 deletions
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 <stdio.h>
+#include "hw4.h"
+#include <string.h>
+
+#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();
+}
+
+