blob: 0c41e6dcfd2eb97378df6fb83569a4c01119f829 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*
* player_actions.c
* Code related to the player states and actions
*
* Created on: Oct 17, 2025
* Author: sowgro
*/
#include <parser.h>
#include <player.h>
#include <stdio.h>
#include <stm32l4xx.h>
#include "song.h"
#include "LED.h"
#include "systick.h"
static uint8_t state = STOPPED_STATE;
/**
* Returns the current player state to other files
*/
uint8_t player_get_state() {
return state;
}
/**
* Sets the current player state from other files
*/
void player_set_state(uint8_t newState) {
state = newState;
}
/**
* Prints the help message
*/
void player_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");
}
/**
* Advances the player to the next song.
*/
void player_next() {
static int current_song = -1;
current_song++;
if (current_song > 4)
current_song = 0;
void *song = get_song(current_song).p_song;
parse_song(song);
song_info_t song_info = parser_get_song_info();
printf("Song #%i\r\n", current_song + 1);
if (song_info.title)
printf("Title: %s\r\n", song_info.title);
if (song_info.copyright)
printf("Copyright: %s\r\n", song_info.copyright);
if (song_info.tempo)
printf("Tempo: %i\r\n", song_info.tempo);
}
/**
* Switches to the play state
*/
void player_play() {
state = PLAYING_STATE;
parser_play_init();
LED_On();
}
/**
* Switches to the pause state
*/
void player_pause() {
state = PAUSED_STATE;
}
/**
* Switches to the stop state
*/
void player_stop() {
state = STOPPED_STATE;
LED_Off();
}
/**
* Toggles the LED every second if in pause mode
*/
void player_loop() {
switch (state) {
case PAUSED_STATE:
if(!(systick_get_count() & 1023)) {
LED_Toggle();
}; break;
case PLAYING_STATE:
parser_play_loop(); break;
}
}
|