Added control line setup

Minor memory optimizations
This commit is contained in:
sweetlilmre
2014-10-04 15:44:33 +02:00
parent 4454fa50c5
commit f500906076
5 changed files with 26 additions and 21 deletions
+5
View File
@@ -53,6 +53,11 @@
#define MOTOR_PINS PIND
#define MOTOR_IS_OFF() (MOTOR_PINS & _BV(MOTOR_PIN))
#define CONTROL_PORT PORTD
#define CONTROL_DDR DDRD
#define CONTROL_PIN1 6
#define CONTROL_PIN2 7
#define KEYS_READ_PORT PORTC
#define KEYS_READ_DDR DDRC
#define KEYS_READ_PINS PINC
+16 -19
View File
@@ -1,5 +1,6 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <util/delay.h>
#include "tapuino.h"
@@ -17,6 +18,7 @@ static uint8_t g_ticker_enabled = 0;
static uint8_t g_ticker_index = 0;
static uint32_t g_last_tick = 0;
static uint32_t g_last_hold = 0;
static char* g_ticker_string = NULL;
uint8_t backslashChar[8] = {
0b00000,
@@ -30,10 +32,6 @@ uint8_t backslashChar[8] = {
};
void filename_ticker(FILINFO* pfile_info, uint32_t cur_tick) {
char* ticker_string;
if (g_ticker_enabled) {
if (!g_last_tick) g_last_tick = cur_tick;
@@ -49,9 +47,8 @@ void filename_ticker(FILINFO* pfile_info, uint32_t cur_tick) {
return;
}
ticker_string = pfile_info->lfname[0] ? pfile_info->lfname : pfile_info->fname;
// is the filename within screen bounds?
if ((strlen(ticker_string) - g_ticker_index) < MAX_LCD_LINE_LEN) {
if ((strlen(g_ticker_string) - g_ticker_index) < MAX_LCD_LINE_LEN) {
// how long do we hold at the end?
if (cur_tick - g_last_hold < (uint32_t) (g_ticker_hold_rate << 1)) {
return;
@@ -64,7 +61,7 @@ void filename_ticker(FILINFO* pfile_info, uint32_t cur_tick) {
g_ticker_index++;
}
lcd_status(&ticker_string[g_ticker_index]);
lcd_status(&g_ticker_string[g_ticker_index]);
if (pfile_info->fattrib & AM_DIR) {
lcd_show_dir();
}
@@ -72,20 +69,18 @@ void filename_ticker(FILINFO* pfile_info, uint32_t cur_tick) {
}
void display_filename(FILINFO* pfile_info) {
char* ticker_string;
ticker_string = pfile_info->lfname[0] ? pfile_info->lfname : pfile_info->fname;
lcd_status(ticker_string);
g_ticker_string = pfile_info->lfname[0] ? pfile_info->lfname : pfile_info->fname;
lcd_status(g_ticker_string);
if (pfile_info->fattrib & AM_DIR) {
lcd_show_dir();
}
g_ticker_enabled = strlen(ticker_string) > (MAX_LCD_LINE_LEN - 1);
g_ticker_enabled = strlen(g_ticker_string) > (MAX_LCD_LINE_LEN - 1);
g_ticker_index = 0;
g_last_tick = 0;
g_last_hold = 0;
}
void lcd_spinner_internal(uint32_t cur_tick, int8_t perc, uint16_t rate) {
void lcd_spinner_internal(uint32_t cur_tick, uint8_t perc, uint16_t rate) {
static uint8_t indicators[] = {'|', '/', '-', 1};
static uint8_t pos = 0;
if (cur_tick - g_last_tick < rate) {
@@ -94,10 +89,11 @@ void lcd_spinner_internal(uint32_t cur_tick, int8_t perc, uint16_t rate) {
g_last_tick = cur_tick;
lcd_setCursor(MAX_LCD_LINE_LEN - 7, 0);
if (perc < 0) {
strncpy_P(g_char_buffer, S_MAX_BLANK_LINE, 7);
} else {
sprintf(g_char_buffer, "%3d%% ", perc);
memset(g_char_buffer, 32, 7);
if (perc < 101) {
uint8_t off = perc < 10 ? 2 : perc < 100 ? 1 : 0;
itoa(perc, g_char_buffer + off, 10);
g_char_buffer[3] = '%';
}
g_char_buffer[5] = MOTOR_IS_OFF() ? 'm' : 'M';
g_char_buffer[6] = indicators[pos++];
@@ -116,7 +112,7 @@ void lcd_spinner(uint32_t cur_tick, int8_t perc) {
void lcd_busy_spinner() {
uint8_t i;
for (i = 0; i < 100; i++) {
lcd_spinner_internal(i, -1, 0);
lcd_spinner_internal(i, 101, 0);
_delay_ms(20);
}
}
@@ -128,7 +124,8 @@ void lcd_show_dir() {
void lcd_line(char* msg, int line, uint8_t usepgm) {
int len;
strncpy_P(g_char_buffer, S_MAX_BLANK_LINE, MAX_LCD_LINE_LEN);
memset(g_char_buffer, 32, MAX_LCD_LINE_LEN);
g_char_buffer[MAX_LCD_LINE_LEN] = 0;
lcd_setCursor(0, line);
if (usepgm) {
-1
View File
@@ -39,5 +39,4 @@ prog_char S_LOADING[] PROGMEM = "Loading:";
prog_char S_OPERATION_COMPLETE[] PROGMEM = "Complete!";
prog_char S_OPERATION_ABORTED[] PROGMEM = "Aborted!";
prog_char S_MAX_BLANK_LINE[] PROGMEM = " ";
prog_char S_TAP_MAGIC_C64[] PROGMEM = "C64-TAPE-RAW";
-1
View File
@@ -40,7 +40,6 @@ extern prog_char S_INVALID_TAP[];
extern prog_char S_LOADING[];
extern prog_char S_OPERATION_COMPLETE[];
extern prog_char S_OPERATION_ABORTED[];
extern prog_char S_MAX_BLANK_LINE[];
extern prog_char S_TAP_MAGIC_C64[];
#endif
+5
View File
@@ -505,6 +505,11 @@ int tapuino_hardware_setup(void)
MOTOR_DDR &= ~_BV(MOTOR_PIN);
MOTOR_PORT |= _BV(MOTOR_PIN);
// Control pins are output
CONTROL_DDR |= _BV(CONTROL_PIN1) | _BV(CONTROL_PIN2);
// default both LOW
CONTROL_PORT &= ~(_BV(CONTROL_PIN1) | _BV(CONTROL_PIN2));
// keys are all inputs, activate pullups
KEYS_READ_DDR &= ~_BV(KEY_SELECT_PIN);
KEYS_READ_PORT |= _BV(KEY_SELECT_PIN);