add menu
This commit is contained in:
16
code/inc/menu.h
Normal file
16
code/inc/menu.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <stdint.h>
|
||||
|
||||
extern int8_t menu_val_timezone;
|
||||
extern uint8_t menu_val_format;
|
||||
|
||||
typedef enum {
|
||||
OFF,
|
||||
TIMEZONE,
|
||||
FORMAT,
|
||||
EXIT
|
||||
} menu_state_t;
|
||||
|
||||
void enter_menu(void);
|
||||
const char* get_menu_text(void);
|
||||
uint8_t get_menu_active(void);
|
||||
void menu_up_down(uint8_t up_down);
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "uart.h"
|
||||
#include "i2cmaster.h"
|
||||
#include "DS3231.h"
|
||||
#include "menu.h"
|
||||
|
||||
#define RX_INPUT_BUFFER_SIZE 92
|
||||
|
||||
@@ -27,6 +28,48 @@ const unsigned char number_Font[10] = {
|
||||
0b11111110, //8
|
||||
0b01111110 //9
|
||||
};
|
||||
const unsigned char character_Font[26] = {
|
||||
0b10111110, //A
|
||||
0b11110100, //b
|
||||
0b11100000, //c
|
||||
0b11100110, //d
|
||||
0b11111000, //e
|
||||
0b10111000, //F
|
||||
0b11011100, //G
|
||||
0b10110100, //h
|
||||
0b00000100, //i
|
||||
0b01000110, //J
|
||||
0b10111100, //K
|
||||
0b11010000, //L
|
||||
0b10011110, //M
|
||||
0b10100100, //n
|
||||
0b11100100, //o
|
||||
0b10111010, //P
|
||||
0b00111110, //q
|
||||
0b10100000, //r
|
||||
0b01111100, //S
|
||||
0b11110000, //t
|
||||
0b11000100, //u
|
||||
0b11000100, //v
|
||||
0b11010110, //W
|
||||
0b10110110, //X
|
||||
0b01110110, //Y
|
||||
0b11101010 //Z
|
||||
};
|
||||
const unsigned char character_minus = 0b00100000; //zeigt '-' an
|
||||
|
||||
void string_to_buffer(const char input_string[6]){
|
||||
for(uint8_t i=0; i < 6; i++){
|
||||
if(input_string[i] >= 0x41 && input_string[i] <= 0x5A)
|
||||
SR_Buffer[i] = character_Font[input_string[i] - 0x41];
|
||||
else if(input_string[i] >= 0x30 && input_string[i] <= 0x39)
|
||||
SR_Buffer[i] = number_Font[input_string[i] - 0x30];
|
||||
else if(input_string[i] == 0x2D)
|
||||
SR_Buffer[i] = character_minus;
|
||||
else
|
||||
SR_Buffer[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void clear_SR_Buffer(void) {
|
||||
for (uint8_t i = 0; i < 6; i++) {
|
||||
@@ -70,21 +113,29 @@ int8_t parse_nmea_gps(char input_string[RX_INPUT_BUFFER_SIZE], uint8_t output_bu
|
||||
|
||||
int main(void){
|
||||
setup();
|
||||
printf("Moin\n\r");
|
||||
|
||||
while(1){
|
||||
check_dip_switches();
|
||||
|
||||
uint8_t clock[3];
|
||||
cli();
|
||||
DS3231_read(clock);
|
||||
sei();
|
||||
for(uint8_t i=0; i < 3; i++){
|
||||
SR_Buffer[5-(2*i)] = number_Font[clock[i] & 0x0F];
|
||||
SR_Buffer[5-(2*i)-1] = number_Font[(clock[i] & 0xF0)>>4];
|
||||
if(get_menu_active()){
|
||||
PORTC &= ~DOT; // blink dots
|
||||
string_to_buffer(get_menu_text());
|
||||
_delay_ms(10);
|
||||
}
|
||||
else{
|
||||
uint8_t clock[3];
|
||||
cli();
|
||||
DS3231_read(clock);
|
||||
sei();
|
||||
for(uint8_t i=0; i < 3; i++){
|
||||
SR_Buffer[5-(2*i)] = number_Font[clock[i] & 0x0F];
|
||||
SR_Buffer[5-(2*i)-1] = number_Font[(clock[i] & 0xF0)>>4];
|
||||
}
|
||||
PORTC = (PORTC & (~DOT)) | (clock[0]%2) << 4; // blink dots
|
||||
_delay_ms(100);
|
||||
}
|
||||
PORTC = (PORTC & (~DOT)) | (clock[0]%2) << 4; // blink dots
|
||||
print_SR_Buffer();
|
||||
_delay_ms(100);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,17 +227,22 @@ void setup(){
|
||||
//Encoder rotate
|
||||
ISR(INT0_vect) {
|
||||
if (PIND & ENCODER_B) {
|
||||
printf("step-\n\r");
|
||||
OCR2A--;
|
||||
if(get_menu_active())
|
||||
menu_up_down(1);
|
||||
else
|
||||
OCR2A++;
|
||||
} else {
|
||||
OCR2A++;
|
||||
printf("step+\n\r");
|
||||
if(get_menu_active())
|
||||
menu_up_down(-1);
|
||||
else
|
||||
OCR2A--;
|
||||
}
|
||||
}
|
||||
|
||||
//Encoder Button
|
||||
ISR(INT1_vect) {
|
||||
printf("button\n\r");
|
||||
enter_menu();
|
||||
}
|
||||
|
||||
ISR(USART0_RX_vect)
|
||||
|
||||
113
code/src/menu.c
Normal file
113
code/src/menu.c
Normal file
@@ -0,0 +1,113 @@
|
||||
#include "menu.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
menu_state_t state = OFF;
|
||||
uint8_t selected = 0;
|
||||
|
||||
int8_t menu_val_timezone = -1;
|
||||
uint8_t menu_val_format = 24;
|
||||
|
||||
//void debug_menu(){
|
||||
// printf("state: %d\r\n", state);
|
||||
// printf("selected: %d\r\n", selected);
|
||||
// printf("timezone: %d\r\n", menu_val_timezone);
|
||||
// printf("\r\n");
|
||||
//}
|
||||
|
||||
uint8_t get_menu_active(){
|
||||
if(state != OFF)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *text[] = {
|
||||
"test ",
|
||||
" test"
|
||||
};
|
||||
|
||||
void enter_menu(){
|
||||
switch(state){
|
||||
case OFF:
|
||||
state = 1;
|
||||
break;
|
||||
case EXIT:
|
||||
state = OFF;
|
||||
break;
|
||||
default:
|
||||
selected ^= 1;
|
||||
break;
|
||||
}
|
||||
//debug_menu();
|
||||
}
|
||||
|
||||
const char* get_menu_text(){
|
||||
char *res = " ";
|
||||
|
||||
memset(res, ' ', 6);
|
||||
if(selected)
|
||||
switch(state){
|
||||
case TIMEZONE:
|
||||
res = " ";
|
||||
if(menu_val_timezone < 0)
|
||||
res[3] = '-';
|
||||
else
|
||||
res[3] = ' ';
|
||||
res[4] = abs(menu_val_timezone / 10)+0x30;
|
||||
res[5] = abs(menu_val_timezone % 10)+0x30;
|
||||
break;
|
||||
case FORMAT:
|
||||
res[2] = (menu_val_format / 10) + 0x30;
|
||||
res[3] = (menu_val_format % 10) + 0x30;
|
||||
res[4] = 'H';
|
||||
break;
|
||||
default:
|
||||
res = "ERROR";
|
||||
break;
|
||||
}
|
||||
else
|
||||
switch(state){
|
||||
case TIMEZONE:
|
||||
res = "ZONE ";
|
||||
break;
|
||||
case FORMAT:
|
||||
res = "FORMAT";
|
||||
break;
|
||||
case EXIT:
|
||||
res = "ZURUEK";
|
||||
break;
|
||||
default:
|
||||
res = "ERROR";
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void menu_up_down(uint8_t up_down){
|
||||
if(selected)
|
||||
switch(state){
|
||||
case TIMEZONE:
|
||||
menu_val_timezone += up_down;
|
||||
if(menu_val_timezone < -12)
|
||||
menu_val_timezone = 12;
|
||||
if(menu_val_timezone > 12)
|
||||
menu_val_timezone = -12;
|
||||
break;
|
||||
case FORMAT:
|
||||
if(menu_val_format == 12)
|
||||
menu_val_format = 24;
|
||||
else if(menu_val_format == 24)
|
||||
menu_val_format = 12;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
else{
|
||||
state += up_down;
|
||||
if(state < 1)
|
||||
state = EXIT;
|
||||
if(state > 3)
|
||||
state = TIMEZONE;
|
||||
}
|
||||
//debug_menu();
|
||||
}
|
||||
Reference in New Issue
Block a user