theoretically done display fw
This commit is contained in:
parent
45e0794fe3
commit
c4d7d1cc50
4
final_project/.gitignore
vendored
Normal file
4
final_project/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
*.map
|
||||
*.o
|
||||
*.out
|
||||
*-bak
|
@ -13,7 +13,9 @@
|
||||
|
||||
typedef enum {
|
||||
COMMS_CMD_CLR = 0U, //! Clears LCD and all file names
|
||||
COMMS_CMD_ADD_FILE, //! Adds a file to the list of files to display, data is 1 byte for ID, 1 byte for strlen, n bytes for string
|
||||
COMMS_CMD_NUM, //! sends the total number of songs to choose from
|
||||
COMMS_CMD_QUERY_NAME, //! Queries for the name of a given song ID
|
||||
COMMS_CMD_REPLY_NAME, //! Responds with the name of the given song ID
|
||||
COMMS_CMD_SELECT_FILE, //! selects a file from the given list to play, data is 1 byte for id
|
||||
COMMS_CMD_PLAY, //! Starts playing file
|
||||
COMMS_CMD_PAUSE //! pauses playing file
|
||||
@ -21,51 +23,44 @@ typedef enum {
|
||||
|
||||
/** @brief Inline function to send commands and values.
|
||||
*/
|
||||
inline void comms_send_command(comms_cmd_t cmd) {
|
||||
inline void comms_send(comms_cmd_t cmd) {
|
||||
while (! (UCSRA & (1 << UDRE)));
|
||||
UDR = cmd;
|
||||
}
|
||||
|
||||
/** @brief Adds a file to the list on the LCD side.
|
||||
*/
|
||||
inline void comms_add_file(uint8_t id, char* filename) {
|
||||
uint8_t len = strlen(filename);
|
||||
|
||||
comms_send_command(COMMS_CMD_ADD_FILE);
|
||||
comms_send_command((comms_cmd_t) id);
|
||||
|
||||
uint8_t i = 0;
|
||||
while (i < len) {
|
||||
comms_send_command((comms_cmd_t) filename[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief Selects a file from the list on the DAC side.
|
||||
*
|
||||
* If another song is playing, this will stop
|
||||
* that song from playing and select the new one.
|
||||
*/
|
||||
inline void comms_select_file(uint8_t id) {
|
||||
comms_send_command(COMMS_CMD_SELECT_FILE);
|
||||
comms_send_command((comms_cmd_t) id);
|
||||
comms_send(COMMS_CMD_SELECT_FILE);
|
||||
comms_send((comms_cmd_t) id);
|
||||
}
|
||||
|
||||
/** @brief Queries for the name of the given song ID.
|
||||
*/
|
||||
inline void comms_query_name(uint8_t id) {
|
||||
comms_send(COMMS_CMD_QUERY_NAME);
|
||||
comms_send(id);
|
||||
}
|
||||
|
||||
/** @brief Clears the LCD list of files.
|
||||
*/
|
||||
inline void comms_clear() {
|
||||
comms_send_command(COMMS_CMD_CLR);
|
||||
comms_send(COMMS_CMD_CLR);
|
||||
}
|
||||
|
||||
/** @brief Starts playing song.
|
||||
*/
|
||||
inline void comms_play() {
|
||||
comms_send_command(COMMS_CMD_PLAY);
|
||||
comms_send(COMMS_CMD_PLAY);
|
||||
}
|
||||
|
||||
/** @brief Pauses playing song.
|
||||
*/
|
||||
inline void comms_pause() {
|
||||
comms_send_command(COMMS_CMD_PLAY);
|
||||
comms_send(COMMS_CMD_PLAY);
|
||||
}
|
||||
|
||||
#endif
|
@ -9,7 +9,7 @@ typedef enum {
|
||||
FIFO_EMPTY
|
||||
} fifo_err_t;
|
||||
|
||||
#define FIFO_LEN 50
|
||||
#define FIFO_LEN 20
|
||||
#define FIFO_TYPE uint8_t
|
||||
|
||||
/** @brief Initialises FIFO
|
||||
|
@ -1,52 +1,20 @@
|
||||
#include "main.h"
|
||||
|
||||
/* ---- Global Flags ---- */
|
||||
int16_t display_song = -1; //! ID of the song currently being displayed, -1 if song list is not initialised
|
||||
int16_t selected_song = -1; //! ID of the selected song. -1 if no song is selected.
|
||||
bool update_display = false; //! flag on whether or not to update display
|
||||
int8_t display_song = -1; //! ID of the song currently being displayed, -1 if song list is not initialised
|
||||
int8_t last_displayed_song = -1;
|
||||
int8_t selected_song = -1; //! ID of the selected song. -1 if no song is selected.
|
||||
bool update_display = false; //! flag on whether or not to update display
|
||||
|
||||
struct {
|
||||
char* names[MAX_SONGS]; //! array of all song names, names are allocated on heap
|
||||
uint8_t num_songs; //! Number of songs loaded into display memory
|
||||
bool playing; //! Whether the currently selected song is playing
|
||||
char name[SONG_NAME_LEN + 1]; //! array of all song names, names are allocated on heap
|
||||
uint8_t num_songs; //! Number of songs loaded into display memory
|
||||
bool playing; //! Whether the currently selected song is playing
|
||||
} songs;
|
||||
|
||||
/** @brief Adds song to list of songs
|
||||
*
|
||||
* Allocates a new piece of memory for the name.
|
||||
|
||||
/** @brief Handles right button press
|
||||
*/
|
||||
/*
|
||||
void add_song(char* name) {
|
||||
// Error out on too many songs
|
||||
if (songs.num_songs == MAX_SONGS) {
|
||||
lcd_gotoxy(0,0);
|
||||
lcd_puts("Too many songs!");
|
||||
while(1);
|
||||
}
|
||||
|
||||
// Allocate memory to store name, and increase number
|
||||
uint8_t name_len = strlen(name);
|
||||
songs.names[songs.num_songs] = malloc(name_len);
|
||||
songs.num_songs++;
|
||||
}
|
||||
*/
|
||||
|
||||
/** @brief Clears list of songs
|
||||
*
|
||||
* Frees all memory used for name storage
|
||||
*/
|
||||
/*
|
||||
void clear_songs() {
|
||||
// Free all memory
|
||||
for (uint8_t i = 0; i < songs.num_songs; i++) {
|
||||
free(songs.names[i]);
|
||||
}
|
||||
|
||||
songs.num_songs = 0;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void handle_left_press() {
|
||||
if (songs.num_songs == 0) {
|
||||
lcd_clrscr();
|
||||
@ -60,6 +28,8 @@ void handle_left_press() {
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief Handles left button press
|
||||
*/
|
||||
void handle_right_press() {
|
||||
if (songs.num_songs == 0) {
|
||||
lcd_clrscr();
|
||||
@ -120,6 +90,21 @@ int main() {
|
||||
while (1) {
|
||||
// Handle incoming messages
|
||||
if (fifo_pop(&incoming_cmd) == FIFO_SUCCESS) {
|
||||
switch (incoming_cmd) {
|
||||
// Clear songs, so there are none to display
|
||||
case (COMMS_CMD_CLR):
|
||||
songs.num_songs = 0;
|
||||
display_song = -1;
|
||||
break;
|
||||
// change number of songs
|
||||
case (COMMS_CMD_NUM):
|
||||
while(fifo_pop((FIFO_TYPE*) &songs.num_songs) != FIFO_SUCCESS);
|
||||
break;
|
||||
default:
|
||||
lcd_clrscr();
|
||||
lcd_puts("Incorrect command!");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -143,16 +128,44 @@ int main() {
|
||||
|
||||
// Update display periodically
|
||||
if (update_display) {
|
||||
// check if song has changed
|
||||
if (last_displayed_song != display_song) {
|
||||
comms_query_name(display_song);
|
||||
|
||||
char tmp_chr;
|
||||
|
||||
// Wait for command to come in
|
||||
while (fifo_pop((FIFO_TYPE*) &tmp_chr) != FIFO_SUCCESS);
|
||||
|
||||
// TODO add error handling here
|
||||
|
||||
// Wait for length info to come in
|
||||
while (fifo_pop((FIFO_TYPE*) &tmp_chr) != FIFO_SUCCESS);
|
||||
uint8_t len = tmp_chr;
|
||||
|
||||
// Read in string
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
// Hold until fifo returns successfully
|
||||
while(fifo_pop((FIFO_TYPE*) &songs.name[i]) != FIFO_SUCCESS);
|
||||
}
|
||||
}
|
||||
lcd_clrscr();
|
||||
lcd_gotoxy(0,0);
|
||||
lcd_puts(songs.names[display_song]);
|
||||
lcd_gotoxy(0, 1);
|
||||
//char tmp_string[17];
|
||||
//sprintf(tmp_string, "%1d %2d/%2d",
|
||||
// display_song, display_song, songs.num_songs);
|
||||
//lcd_puts(tmp_string);
|
||||
|
||||
if (display_song != -1) {
|
||||
lcd_puts(songs.name);
|
||||
lcd_gotoxy(0, 1);
|
||||
lcd_putc('1' + display_song);
|
||||
lcd_gotoxy(13,1);
|
||||
lcd_putc('1' + display_song);
|
||||
lcd_putc('/');
|
||||
lcd_putc('0' + songs.num_songs);
|
||||
|
||||
} else {
|
||||
lcd_puts("No song!");
|
||||
}
|
||||
|
||||
update_display = false;
|
||||
last_displayed_song = display_song;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "comms.h"
|
||||
#include "periph.h"
|
||||
|
||||
#define MAX_SONGS 16
|
||||
#define SONG_NAME_LEN 16
|
||||
|
||||
/* ---- Globally available flags ---- */
|
||||
extern bool update_display;
|
||||
|
Loading…
Reference in New Issue
Block a user