Commit f64295c3 authored by prp1u19's avatar prp1u19
Browse files

Stable version

parents
/* ruota.h
| | | Signal on | |
| Port | Pin | Schematic | Function |
|------+-----+-----------+-----------------------|
| E | 4 | ROTA | Rotary Encoder A |
| E | 5 | ROTB | Rotary Encoder B |
| E | 7 | SWC | Switch wheel "Centre" |
|------+-----+-----------+-----------------------|
| C | 2 | SWN | Switch wheel "North" |
| C | 3 | SWE | Switch wheel "East" |
| C | 4 | SWS | Switch wheel "South" |
| C | 5 | SWW | Switch wheel "West" |
|------+-----+-----------+-----------------------|
| B | 6 | CD | SD Card Detetcion |
*/
#define SWN PC2
#define SWE PC3
#define SWS PC4
#define SWW PC5
#define OS_CD PB6
#define SWC PE7
#define REPEAT_START 60 /* after 600ms */
#define REPEAT_NEXT 10 /* every 100ms */
void os_init_ruota(void);
int8_t os_enc_delta(void);
uint8_t get_switch_press( uint8_t switch_mask );
uint8_t get_switch_rpt( uint8_t switch_mask );
uint8_t get_switch_state( uint8_t switch_mask );
uint8_t get_switch_short( uint8_t switch_mask );
uint8_t get_switch_long( uint8_t switch_mask );
/*
* Author: prp1u19
* Date: May 11 2021
* This work is licensed under MIT license
*/
#include "os.h"
#include "string.h"
FIL File; /* FAT File */
int currentIndex = 0; // Current selected file/directory
int maxLines = 0; // The number of lines the buffer has
char buffer[20][20] = {'\0'}; // list of files
int counter = 0; // number of files
TCHAR cwd[30] = {'\0'}; // current working directory
DIR dir; // current open dir
// Render the file/directory names found in the buffer to the screen
void renderScreen() {
clear_screen();
for (int i = 0; i < counter; i++) {
if (currentIndex == i) {
display_string("-> ");
} else {
display_string(" ");
}
display_string(buffer[i]);
display_string("\n");
}
}
// Put the file/directory names from current directory in the buffer
void get_files(TCHAR* curent_dir) {
counter = 0;
f_mount(&FatFs, "", 0);
FRESULT status = f_opendir(&dir, curent_dir);
if (status == FR_OK) {
FILINFO file;
memset(buffer, 0, sizeof(buffer[0][0]) * 20 * 20);
while (f_readdir(&dir, &file) == FR_OK) {
if (file.fname[0] == 0) break;
for (uint8_t i = 0; i < strlen(file.fname); i++) {
buffer[counter][i] = file.fname[i];
}
counter++;
}
maxLines = counter;
renderScreen();
f_closedir(&dir);
}
}
// Check for physical inputs
int check_switches(int state) {
// Check if the middle button has been pressed
if (get_switch_short(_BV(SWC))) {
if (strlen(cwd) + strlen(buffer[currentIndex]) <= 30) {
TCHAR test[30] = {'\0'};
if (strcmp(buffer[currentIndex], "..") == 0) {
uint8_t len = strlen(cwd);
uint8_t index = 1;
for (uint8_t i = len - 1; i >= 0; i--) {
if (cwd[i] == '/') {
if (i - 1 < 0) {
index = 1;
} else {
index = i;
}
break;
}
}
strncpy(test, cwd, index);
} else if (strcmp(buffer[currentIndex], ".") == 0) {
strcpy(test, cwd);
} else {
strcpy(test, cwd);
if (test[strlen(cwd) -1] != '/') {
strcat(test, "/");
}
strcat(test, buffer[currentIndex]);
}
FRESULT status = f_opendir(&dir, test);
if (status == FR_OK) {
for (uint8_t i = 0; i < strlen(test); i++) {
cwd[i] = test[i];
}
cwd[strlen(test)] = 0x00;
get_files(test);
f_closedir(&dir);
}
}
}
// Scroll down and rerender
if (get_switch_short(_BV(SWN))) {
if (currentIndex > 0) {
currentIndex--;
}
renderScreen();
}
// Scroll up and rerender
if (get_switch_short(_BV(SWS))) {
if (currentIndex < maxLines - 1) {
currentIndex++;
}
renderScreen();
}
return state;
}
void main(void) {
os_init();
os_add_task( check_switches, 100, 1);
sei();
// Init default directory to '/'
cwd[0] = '/';
// get all files/directories from '/'
get_files("/");
for(;;){}
}
\ No newline at end of file
/* Author: Steve Gunn
* Licence: This work is licensed under the Creative Commons Attribution License.
* View this license at http://creativecommons.org/about/licenses/
*
*
* Feb 2015: Slightly modified for LaFortuna board, KPZ
*
* | PIN | Function | Connected to |
* |-----+---------------+----------------------------------------------|
* | PD2 | RX of USART 1 | to ORANGE wire --> TX on FTDI C232HM cable |
* | PD3 | TX of USART 1 | to YELLOW wire --> RX on FTDI C232HM cable |
* | G | Signal Ground | to BLACK wire --> ground on C232HM cable |
*
* Configure your serial terminal for:
* |-----------+------|
* | Baud rate | 9600 |
* |-----------+------|
* | Data bits | 8 |
* |-----------+------|
* | Stop bits | 1 |
* |-----------+------|
*
* Linux:
* ls -lh /dev/serial/by-id
* picocom /dev/ttyUSB0
*/
#ifndef DEBUG_H
#define DEBUG_H
#define __ASSERT_USE_STDERR
#include <assert.h>
#include <stdio.h>
#include <avr/io.h>
#define DEBUG_BAUD 9600
int uputchar1(char c, FILE *stream)
{
if (c == '\n') uputchar1('\r', stream);
while (!(UCSR1A & _BV(UDRE1)));
UDR1 = c;
return c;
}
int ugetchar1(FILE *stream)
{
while(!(UCSR1A & _BV(RXC1)));
return UDR1;
}
void init_debug_uart1(void)
{
/* Configure UART1 baud rate, one start bit, 8-bit, no parity and one stop bit */
UBRR1H = (F_CPU/(DEBUG_BAUD*16L)-1) >> 8;
UBRR1L = (F_CPU/(DEBUG_BAUD*16L)-1);
UCSR1B = _BV(RXEN1) | _BV(TXEN1);
UCSR1C = _BV(UCSZ10) | _BV(UCSZ11);
/* Setup new streams for input and output */
static FILE uout = FDEV_SETUP_STREAM(uputchar1, NULL, _FDEV_SETUP_WRITE);
static FILE uin = FDEV_SETUP_STREAM(NULL, ugetchar1, _FDEV_SETUP_READ);
/* Redirect all standard streams to UART1 */
stdout = &uout;
stderr = &uout;
stdin = &uin;
}
#endif /* DEBUG_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment