mirror of
https://github.com/sweetlilmre/tapuino.git
synced 2026-07-27 19:55:41 +00:00
code optimizations
first complete attempt at manual naming
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
#define LCD_BIT_DATA1 5 // 4 bit data, bit 1
|
||||
#define LCD_BIT_DATA2 6 // 4 bit data, bit 2
|
||||
#define LCD_BIT_DATA3 7 // 4 bit data, bit 3
|
||||
// dimension config
|
||||
// LCD dimensions config
|
||||
#define LCD_NUM_LINES 2 // number of display lines on the LCD
|
||||
#define MAX_LCD_LINE_LEN 16 // max number of characters on a line
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#define TICKER_HOLD 5 // ticker begin and end hold time in SPINNER_RATE units
|
||||
#define KEY_REPEAT_START 500 // milliseconds, granularity 10ms
|
||||
#define KEY_REPEAT_NEXT 300 // milliseconds, granularity 10ms
|
||||
#define REC_FINALIZE_TIME 5000 // milliseconds, granularity 10ms
|
||||
#define REC_FINALIZE_TIME 2000 // milliseconds, granularity 10ms
|
||||
|
||||
// TWI for pullups
|
||||
#define TWI_PORT PORTC
|
||||
|
||||
+24
-20
@@ -16,7 +16,6 @@ uint8_t g_ticker_enabled = 0;
|
||||
uint8_t g_ticker_index = 0;
|
||||
uint8_t g_ticker_hold = TICKER_HOLD;
|
||||
uint8_t g_ticker_end_hold = TICKER_HOLD;
|
||||
FILINFO* g_ticker_file_info = NULL;
|
||||
|
||||
uint8_t backslashChar[8] = {
|
||||
0b00000,
|
||||
@@ -29,7 +28,7 @@ uint8_t backslashChar[8] = {
|
||||
0b00000
|
||||
};
|
||||
|
||||
void filename_ticker(uint32_t cur_tick) {
|
||||
void filename_ticker(FILINFO* pfile_info, uint32_t cur_tick) {
|
||||
static uint32_t last_tick = 0;
|
||||
char* ticker_string;
|
||||
|
||||
@@ -45,7 +44,7 @@ void filename_ticker(uint32_t cur_tick) {
|
||||
}
|
||||
|
||||
g_ticker_index++;
|
||||
ticker_string = g_ticker_file_info->lfname[0] ? g_ticker_file_info->lfname : g_ticker_file_info->fname;
|
||||
ticker_string = pfile_info->lfname[0] ? pfile_info->lfname : pfile_info->fname;
|
||||
if ((strlen(ticker_string) - g_ticker_index) < (MAX_LCD_LINE_LEN - 1)) {
|
||||
if (g_ticker_end_hold) {
|
||||
g_ticker_index--;
|
||||
@@ -57,7 +56,7 @@ void filename_ticker(uint32_t cur_tick) {
|
||||
g_ticker_hold = g_ticker_end_hold = TICKER_HOLD;
|
||||
}
|
||||
lcd_status(&ticker_string[g_ticker_index]);
|
||||
if (g_ticker_file_info->fattrib & AM_DIR) {
|
||||
if (pfile_info->fattrib & AM_DIR) {
|
||||
lcd_show_dir();
|
||||
}
|
||||
}
|
||||
@@ -66,10 +65,9 @@ void filename_ticker(uint32_t cur_tick) {
|
||||
void display_filename(FILINFO* pfile_info) {
|
||||
char* ticker_string;
|
||||
|
||||
g_ticker_file_info = pfile_info;
|
||||
ticker_string = g_ticker_file_info->lfname[0] ? g_ticker_file_info->lfname : g_ticker_file_info->fname;
|
||||
ticker_string = pfile_info->lfname[0] ? pfile_info->lfname : pfile_info->fname;
|
||||
lcd_status(ticker_string);
|
||||
if (g_ticker_file_info->fattrib & AM_DIR) {
|
||||
if (pfile_info->fattrib & AM_DIR) {
|
||||
lcd_show_dir();
|
||||
}
|
||||
g_ticker_index = 0;
|
||||
@@ -77,29 +75,23 @@ void display_filename(FILINFO* pfile_info) {
|
||||
g_ticker_enabled = strlen(ticker_string) > (MAX_LCD_LINE_LEN - 1);
|
||||
}
|
||||
|
||||
void lcd_busy_spinner() {
|
||||
int i;
|
||||
for (i = 0; i < 100; i++) {
|
||||
lcd_spinner(0, 100);
|
||||
_delay_ms(20);
|
||||
}
|
||||
}
|
||||
|
||||
void lcd_spinner(int32_t cur_tick, int perc) {
|
||||
void lcd_spinner_internal(uint32_t cur_tick, int8_t perc, uint16_t rate) {
|
||||
static uint8_t indicators[] = {'|', '/', '-', 1};
|
||||
static uint8_t pos = 0;
|
||||
static int32_t last_tick = 0;
|
||||
if (cur_tick - last_tick < (SPINNER_RATE / 10)) {
|
||||
static uint32_t last_tick = 0;
|
||||
if (cur_tick - last_tick < (rate / 10)) {
|
||||
return;
|
||||
}
|
||||
|
||||
last_tick = cur_tick;
|
||||
lcd_setCursor(MAX_LCD_LINE_LEN - 7, 0);
|
||||
if (perc < 0) {
|
||||
sprintf(g_char_buffer, " %c%c", MOTOR_IS_OFF() ? 'm' : 'M', indicators[pos++]);
|
||||
strncpy_P(g_char_buffer, S_MAX_BLANK_LINE, 7);
|
||||
} else {
|
||||
sprintf(g_char_buffer, "%3d%% %c%c", perc, MOTOR_IS_OFF() ? 'm' : 'M', indicators[pos++]);
|
||||
sprintf(g_char_buffer, "%3d%% ", perc);
|
||||
}
|
||||
g_char_buffer[5] = MOTOR_IS_OFF() ? 'm' : 'M';
|
||||
g_char_buffer[6] = indicators[pos++];
|
||||
lcd_print(g_char_buffer);
|
||||
|
||||
if (pos > 3) {
|
||||
@@ -107,6 +99,18 @@ void lcd_spinner(int32_t cur_tick, int perc) {
|
||||
}
|
||||
}
|
||||
|
||||
void lcd_spinner(uint32_t cur_tick, int8_t perc) {
|
||||
lcd_spinner_internal(cur_tick, perc, SPINNER_RATE);
|
||||
}
|
||||
|
||||
void lcd_busy_spinner() {
|
||||
uint8_t i;
|
||||
for (i = 0; i < 100; i++) {
|
||||
lcd_spinner_internal(i, 100, 0);
|
||||
_delay_ms(20);
|
||||
}
|
||||
}
|
||||
|
||||
void lcd_show_dir() {
|
||||
lcd_setCursor(MAX_LCD_LINE_LEN - 1, 1);
|
||||
|
||||
|
||||
+2
-2
@@ -3,10 +3,10 @@
|
||||
|
||||
void lcd_setup();
|
||||
|
||||
void filename_ticker(uint32_t cur_tick);
|
||||
void filename_ticker(FILINFO* pfile_info, uint32_t cur_tick);
|
||||
void display_filename(FILINFO* pfile_info);
|
||||
void lcd_busy_spinner();
|
||||
void lcd_spinner(int32_t wait, int perc);
|
||||
void lcd_spinner(uint32_t wait, int8_t perc);
|
||||
void lcd_show_dir();
|
||||
void lcd_title(char* msg);
|
||||
void lcd_title_P(const char* msg);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ff.h"
|
||||
#include "config.h"
|
||||
@@ -24,6 +25,19 @@
|
||||
int g_num_files = 0;
|
||||
int g_cur_file_index = 0;
|
||||
|
||||
uint8_t get_cur_command() {
|
||||
// this order of operations is very important
|
||||
// first get an 'atomic' read of g_cur_command into a local
|
||||
uint8_t cur_command = g_cur_command;
|
||||
// then compare the _local_ against a non-IDLE command
|
||||
if (cur_command != COMMAND_IDLE) {
|
||||
// and clear the global i.e. only if the global was non-idle at the time of read
|
||||
// this prevents clearing the global as a key is pressed and missing it
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
}
|
||||
return cur_command;
|
||||
}
|
||||
|
||||
void handle_play_mode(FILINFO* pfile_info) {
|
||||
lcd_title_P(S_SELECT_FILE);
|
||||
if (!get_file_at_index(pfile_info, g_cur_file_index)) {
|
||||
@@ -35,7 +49,7 @@ void handle_play_mode(FILINFO* pfile_info) {
|
||||
display_filename(pfile_info);
|
||||
|
||||
while (1) {
|
||||
switch(g_cur_command)
|
||||
switch(get_cur_command())
|
||||
{
|
||||
case COMMAND_SELECT:
|
||||
{
|
||||
@@ -56,7 +70,6 @@ void handle_play_mode(FILINFO* pfile_info) {
|
||||
get_file_at_index(pfile_info, g_cur_file_index);
|
||||
display_filename(pfile_info);
|
||||
}
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
break;
|
||||
}
|
||||
case COMMAND_ABORT:
|
||||
@@ -74,7 +87,6 @@ void handle_play_mode(FILINFO* pfile_info) {
|
||||
// back to main menu
|
||||
return;
|
||||
}
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
break;
|
||||
}
|
||||
case COMMAND_NEXT:
|
||||
@@ -84,7 +96,6 @@ void handle_play_mode(FILINFO* pfile_info) {
|
||||
}
|
||||
get_file_at_index(pfile_info, g_cur_file_index);
|
||||
display_filename(pfile_info);
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
break;
|
||||
}
|
||||
case COMMAND_PREVIOUS:
|
||||
@@ -94,27 +105,25 @@ void handle_play_mode(FILINFO* pfile_info) {
|
||||
}
|
||||
get_file_at_index(pfile_info, g_cur_file_index);
|
||||
display_filename(pfile_info);
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
filename_ticker(get_timer_tick());
|
||||
filename_ticker(pfile_info, get_timer_tick());
|
||||
}
|
||||
}
|
||||
|
||||
void handle_record_mode_auto(FILINFO* pfile_info) {
|
||||
void handle_record_mode_ready(char* pfile_name) {
|
||||
lcd_title_P(S_READY_RECORD);
|
||||
lcd_status_P(S_PRESS_START);
|
||||
|
||||
while (1) {
|
||||
switch(g_cur_command)
|
||||
switch(get_cur_command())
|
||||
{
|
||||
case COMMAND_SELECT:
|
||||
{
|
||||
record_file(NULL);
|
||||
record_file(pfile_name);
|
||||
lcd_title_P(S_READY_RECORD);
|
||||
lcd_status_P(S_PRESS_START);
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
break;
|
||||
}
|
||||
case COMMAND_ABORT:
|
||||
@@ -126,7 +135,7 @@ void handle_record_mode_auto(FILINFO* pfile_info) {
|
||||
}
|
||||
}
|
||||
|
||||
void handle_manual_filename(FILINFO* pfile_info) {
|
||||
uint8_t handle_manual_filename(FILINFO* pfile_info) {
|
||||
uint8_t cur_char_pos = 0;
|
||||
uint8_t cursor_pos = 0;
|
||||
uint8_t max_chars = strlen_P(S_FILENAME_CHARS);
|
||||
@@ -134,25 +143,31 @@ void handle_manual_filename(FILINFO* pfile_info) {
|
||||
lcd_title_P(S_ENTER_FILENAME);
|
||||
lcd_status(S_MAX_BLANK_LINE);
|
||||
lcd_cursor();
|
||||
lcd_blink();
|
||||
lcd_setCursor(0, 1);
|
||||
|
||||
// start with a nicely terminated string!
|
||||
pfile_info->lfname[0] = 0;
|
||||
memset(pfile_info->lfname, 0, pfile_info->lfsize);
|
||||
|
||||
while (1) {
|
||||
switch(g_cur_command)
|
||||
switch(get_cur_command())
|
||||
{
|
||||
case COMMAND_SELECT:
|
||||
{
|
||||
if (cursor_pos < MAX_LCD_LINE_LEN) {
|
||||
if (cursor_pos < (MAX_LCD_LINE_LEN - 1)) {
|
||||
cur_char = pgm_read_byte(S_FILENAME_CHARS + cur_char_pos);
|
||||
pfile_info->lfname[cursor_pos] = cur_char;
|
||||
cursor_pos++;
|
||||
lcd_setCursor(cursor_pos, 1);
|
||||
cur_char_pos = 0;
|
||||
}
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
break;
|
||||
}
|
||||
case COMMAND_SELECT_LONG:
|
||||
{
|
||||
strcat(pfile_info->lfname, ".tap");
|
||||
// exit to previous menu, with accept
|
||||
return 1;
|
||||
}
|
||||
case COMMAND_ABORT:
|
||||
{
|
||||
if (cursor_pos != 0) {
|
||||
@@ -167,15 +182,14 @@ void handle_manual_filename(FILINFO* pfile_info) {
|
||||
cur_char_pos++;
|
||||
}
|
||||
}
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
break;
|
||||
}
|
||||
case COMMAND_ABORT_LONG:
|
||||
{
|
||||
lcd_title_P(S_OPERATION_ABORTED);
|
||||
lcd_busy_spinner();
|
||||
// exit to previous menu
|
||||
return;
|
||||
// exit to previous menu, with cancel
|
||||
return 0;
|
||||
}
|
||||
case COMMAND_NEXT:
|
||||
{
|
||||
@@ -184,7 +198,6 @@ void handle_manual_filename(FILINFO* pfile_info) {
|
||||
lcd_write(cur_char);
|
||||
lcd_setCursor(cursor_pos, 1);
|
||||
pfile_info->lfname[cursor_pos] = cur_char;
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
break;
|
||||
}
|
||||
case COMMAND_PREVIOUS:
|
||||
@@ -197,7 +210,6 @@ void handle_manual_filename(FILINFO* pfile_info) {
|
||||
lcd_write(cur_char);
|
||||
lcd_setCursor(cursor_pos, 1);
|
||||
pfile_info->lfname[cursor_pos] = cur_char;
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -225,26 +237,25 @@ void handle_record_mode_select(FILINFO* pfile_info) {
|
||||
prev_mode = cur_mode;
|
||||
}
|
||||
|
||||
switch(g_cur_command)
|
||||
switch(get_cur_command())
|
||||
{
|
||||
case COMMAND_SELECT:
|
||||
{
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
switch(cur_mode)
|
||||
{
|
||||
case REC_MODE_AUTO:
|
||||
handle_record_mode_auto(pfile_info);
|
||||
handle_record_mode_ready(NULL);
|
||||
break;
|
||||
case REC_MODE_MANUAL:
|
||||
handle_manual_filename(pfile_info);
|
||||
handle_record_mode_auto(pfile_info);
|
||||
if (handle_manual_filename(pfile_info)) {
|
||||
handle_record_mode_ready(pfile_info->lfname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
lcd_title_P(S_SELECT_RECORD_MODE);
|
||||
}
|
||||
case COMMAND_ABORT:
|
||||
{
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
return;
|
||||
}
|
||||
case COMMAND_NEXT:
|
||||
@@ -254,7 +265,6 @@ void handle_record_mode_select(FILINFO* pfile_info) {
|
||||
} else {
|
||||
cur_mode++;
|
||||
}
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
break;
|
||||
}
|
||||
case COMMAND_PREVIOUS:
|
||||
@@ -264,7 +274,6 @@ void handle_record_mode_select(FILINFO* pfile_info) {
|
||||
} else {
|
||||
cur_mode--;
|
||||
}
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -298,16 +307,14 @@ uint8_t handle_select_mode() {
|
||||
prev_mode = cur_mode;
|
||||
}
|
||||
|
||||
switch(g_cur_command)
|
||||
switch(get_cur_command())
|
||||
{
|
||||
case COMMAND_SELECT:
|
||||
{
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
return cur_mode;
|
||||
}
|
||||
case COMMAND_ABORT:
|
||||
{
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
break;
|
||||
}
|
||||
case COMMAND_NEXT:
|
||||
@@ -317,7 +324,6 @@ uint8_t handle_select_mode() {
|
||||
} else {
|
||||
cur_mode++;
|
||||
}
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
break;
|
||||
}
|
||||
case COMMAND_PREVIOUS:
|
||||
@@ -327,7 +333,6 @@ uint8_t handle_select_mode() {
|
||||
} else {
|
||||
cur_mode--;
|
||||
}
|
||||
g_cur_command = COMMAND_IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "ff.h"
|
||||
#include "mmc.h"
|
||||
#include "diskio.h"
|
||||
#include "serial.h"
|
||||
//#include "serial.h"
|
||||
#include "comms.h"
|
||||
#include "lcd.h"
|
||||
#include "lcdutils.h"
|
||||
@@ -478,12 +478,12 @@ int tapuino_hardware_setup(void)
|
||||
|
||||
disk_timer_setup();
|
||||
|
||||
serial_init();
|
||||
serial_println_P(S_STARTINGINIT);
|
||||
sprintf((char*)g_fat_buffer, "%d", free_ram());
|
||||
serial_println((char*)g_fat_buffer);
|
||||
// serial_init();
|
||||
// serial_println_P(S_STARTINGINIT);
|
||||
// sprintf((char*)g_fat_buffer, "%d", free_ram());
|
||||
// serial_println((char*)g_fat_buffer);
|
||||
lcd_setup();
|
||||
serial_println_P(S_INITI2COK);
|
||||
// serial_println_P(S_INITI2COK);
|
||||
lcd_title_P(S_INIT);
|
||||
|
||||
// something (possibly) dodgy in the bootloader causes a fail on cold boot.
|
||||
|
||||
Reference in New Issue
Block a user