crashtest-r0ket/firmware/applications/font.c

210 lines
4.0 KiB
C
Raw Permalink Normal View History

2011-07-17 09:06:34 +00:00
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/lcd.h"
#include "lcd/print.h"
#include "lcd/allfonts.h"
2011-07-17 09:06:34 +00:00
#include "filesystem/ff.h"
#include "filesystem/select.h"
2011-07-17 09:06:34 +00:00
#include "funk/nrf24l01p.h"
#include "usb/usbmsc.h"
#include <string.h>
/**************************************************************************/
uint32_t const testkey[4] = {
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
};
#define MAXNICK 20
char nickname[MAXNICK];
void f_init(void){
FIL file[2]; /* File objects */
UINT readbytes;
int res;
res=f_open(&file[0], "nick.cfg", FA_OPEN_EXISTING|FA_READ);
lcdPrint("open:");
lcdPrintln(f_get_rc_string(res));
if(res){
lcdPrintln("no nick.cfg...");
return;
};
res = f_read(&file[0], nickname, MAXNICK-1, &readbytes);
lcdPrint("read:");
lcdPrintln(f_get_rc_string(res));
if(res){
return;
};
nickname[MAXNICK-1]=0;
// truncate at newline (or other control chars)
for(int i=0;i<MAXNICK;i++){
if(nickname[i]<32)nickname[i]=0;
};
lcdPrint("<");
lcdPrint(nickname);
lcdPrint(">");
lcdNl();
res=f_close(&file[0]);
lcdPrint("close:");
lcdPrintln(f_get_rc_string(res));
if(res){
return;
};
lcdPrintln("Done.");
};
char fontname[15];
2011-07-17 09:06:34 +00:00
void f_nick(void){
char key;
static signed char x=10;
static signed char y=10;
2011-07-17 09:06:34 +00:00
while (1) {
lcdClear();
lcdFill(255);
2011-07-17 09:06:34 +00:00
setExtFont(fontname);
2011-07-17 09:06:34 +00:00
DoString(x,y,nickname);
setIntFont(&Font_7x8);
2011-07-17 09:06:34 +00:00
lcdSetCrsr(50,50);
lcdPrintInt(x);
lcdPrint("x");
lcdPrintInt(y);
2011-08-01 21:50:58 +00:00
lcdDisplay();
delayms(40);
2011-07-17 09:06:34 +00:00
key= getInputRaw();
2011-07-21 18:08:00 +00:00
if(key & BTN_UP){
--y;//if(--y<0) y=0;
2011-07-21 18:08:00 +00:00
};
if (key & BTN_DOWN){
++y;//if(++y>=RESY) y=RESY-1;
2011-07-21 18:08:00 +00:00
};
if (key & BTN_LEFT){
--x;//if(--x<0) x=0;
2011-07-21 18:08:00 +00:00
};
if (key & BTN_RIGHT){
++x;//if(++x>=RESX) x=RESX-1;
2011-07-21 18:08:00 +00:00
};
if (key == BTN_ENTER){
2011-07-17 09:06:34 +00:00
lcdClear();
lcdPrintln("Done.");
lcdDisplay();
2011-07-17 09:06:34 +00:00
break;
};
};
};
void f_font(void){
if( selectFile(fontname,"F0N") != 0){
lcdPrintln("No file selected.");
return;
};
lcdClear();
lcdPrintln(fontname);
setExtFont(fontname);
lcdPrintln("PUabc€");
setIntFont(&Font_7x8);
lcdPrintln("done.");
lcdDisplay();
while(!getInputRaw())delayms(10);
};
2011-07-17 09:06:34 +00:00
/***********************************************************************/
void gotoISP(void) {
DoString(0,0,"Enter ISP!");
lcdDisplay();
ISPandReset();
2011-07-17 09:06:34 +00:00
}
void lcd_mirror(void) {
lcdToggleFlag(LCD_MIRRORX);
};
void lcd_invert(void) {
lcdToggleFlag(LCD_INVERTED);
};
void adc_check(void) {
int dx=0;
int dy=8;
// Print Voltage
dx=DoString(0,dy,"Voltage:");
while ((getInputRaw())==BTN_NONE){
DoInt(dx,dy,GetVoltage());
lcdDisplay();
2011-07-17 09:06:34 +00:00
};
dy+=8;
dx=DoString(0,dy,"Done.");
};
void msc_menu(void){
DoString(0,8,"MSC Enabled.");
lcdDisplay();
2011-07-17 09:06:34 +00:00
usbMSCInit();
while(!getInputRaw())delayms(10);
DoString(0,16,"MSC Disabled.");
usbMSCOff();
};
/**************************************************************************/
static const struct MENU mainmenu = {"Mainmenu", {
{"Invoke ISP", &gotoISP},
{"F Init", &f_init},
{"F Nick", &f_nick},
{"F sel", &f_font},
{"Mirror", &lcd_mirror},
{"Invert", &lcd_invert},
{"Akku", &adc_check},
{"MSC", &msc_menu},
{"---", NULL},
{NULL,NULL}
}};
2011-07-17 09:06:34 +00:00
void main_font(void) {
strcpy(nickname,"Äg€");
2011-07-17 09:06:34 +00:00
font=&Font_7x8;
while (1) {
lcdFill(0); // clear display buffer
lcdDisplay();
2011-07-17 09:06:34 +00:00
handleMenu(&mainmenu);
gotoISP();
}
};
void tick_font(void){
static int foo=0;
static int toggle=0;
if(foo++>80){
toggle=1-toggle;
foo=0;
gpioSetValue (RB_LED0, toggle);
};
return;
};