crashtest-r0ket/firmware/applications/funk.c

183 lines
3.9 KiB
C
Raw Normal View History

#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/lcd.h"
#include "lcd/print.h"
#include "funk/nrf24l01p.h"
2011-07-14 00:24:42 +00:00
#include <string.h>
#include "funk/rftransfer.h"
/**************************************************************************/
void f_init(void){
nrf_init();
2011-07-09 20:49:24 +00:00
int dx=0;
int dy=8;
dx=DoString(0,dy,"Done."); ;dy+=8;
};
void f_status(void){
int dx=0;
2011-07-05 09:52:09 +00:00
int dy=8;
uint8_t buf[4];
2011-07-05 12:42:12 +00:00
buf[0]=C_R_REGISTER | R_CONFIG;
buf[1]=0;
buf[2]=0;
buf[3]=0;
2011-07-14 00:02:23 +00:00
dx=DoString(0,dy,"S:");
dx=DoCharX(dx,dy,buf[0]);
dx=DoCharX(dx,dy,buf[1]);
dx=DoCharX(dx,dy,buf[2]);
dx=DoCharX(dx,dy,buf[3]);
dy+=8;
nrf_cmd_rw_long(buf,2);
2011-07-14 00:02:23 +00:00
dx=DoString(0,dy,"R:");
dx=DoCharX(dx,dy,buf[0]);
dx=DoCharX(dx,dy,buf[1]);
dx=DoCharX(dx,dy,buf[2]);
dx=DoCharX(dx,dy,buf[3]);
dy+=8;
2011-07-05 12:42:12 +00:00
int status=nrf_cmd_status(C_NOP);
2011-07-14 00:02:23 +00:00
dx=DoString(0,dy,"St:"); DoCharX(dx,dy,status);dy+=8;
};
void f_recv(void){
__attribute__ ((aligned (4))) uint8_t buf[32];
int len;
len=nrf_rcv_pkt_time(1000,sizeof(buf),buf);
if(len==0){
lcdPrintln("No pkt (Timeout)");
};
lcdPrint("Size:");lcdPrintInt(len);lcdNl();
lcdPrint("1:");lcdPrintIntHex( *(int*)(buf+ 0) ); lcdNl();
lcdPrint("2:");lcdPrintIntHex( *(int*)(buf+ 4) ); lcdNl();
lcdPrint("3:");lcdPrintIntHex( *(int*)(buf+ 8) ); lcdNl();
lcdPrint("4:");lcdPrintShortHex( *(int*)(buf+12) ); lcdNl();
len=crc16(buf,14);
lcdPrint("crc:");lcdPrintShortHex(len); lcdNl();
};
2011-07-07 22:39:51 +00:00
void f_send(void){
static char ctr=1;
int dx=0;
int dy=8;
uint8_t buf[32];
int status;
2011-07-09 20:49:24 +00:00
buf[0]=0x10; // Length: 16 bytes
buf[1]=0x17; // Proto - fixed at 0x17?
buf[2]=0xff; // Flags (0xff)
2011-07-07 22:39:51 +00:00
buf[3]=0xff; // Send intensity
buf[4]=0x00; // ctr
buf[5]=0x00; // ctr
buf[6]=0x00; // ctr
buf[7]=ctr++; // ctr
2011-07-09 20:49:24 +00:00
buf[8]=0x0; // Object id
buf[9]=0x0;
buf[10]=0x05;
buf[11]=0xec;
2011-07-07 22:39:51 +00:00
2011-07-09 20:49:24 +00:00
buf[12]=0xff; // salt (0xffff always?)
buf[13]=0xff;
2011-07-07 22:39:51 +00:00
status=nrf_snd_pkt_crc(14,buf);
2011-07-07 22:39:51 +00:00
2011-07-09 20:49:24 +00:00
dx=DoString(0,dy,"St:"); DoIntX(dx,dy,status); dy+=8;
2011-07-07 22:39:51 +00:00
};
void gotoISP(void) {
DoString(0,0,"Enter ISP!");
lcdDisplay(0);
ISPandReset(5);
}
void lcd_mirror(void) {
lcdToggleFlag(LCD_MIRRORX);
};
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(0);
};
dy+=8;
dx=DoString(0,dy,"Done.");
};
2011-07-14 00:24:42 +00:00
void f_sendBlock(void)
{
uint8_t data[] = "hallo welt, das hier ist ein langer string, der"
"per funk verschickt werden soll.";
rftransfer_send(strlen((char *)data), data);
2011-07-14 00:24:42 +00:00
}
/**************************************************************************/
const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP};
const struct MENU_DEF menu_init = {"F Init", &f_init};
const struct MENU_DEF menu_status = {"F Status", &f_status};
const struct MENU_DEF menu_rcv = {"F Recv", &f_recv};
2011-07-07 22:39:51 +00:00
const struct MENU_DEF menu_snd = {"F Send", &f_send};
2011-07-14 00:24:42 +00:00
const struct MENU_DEF menu_sndblock={"F Send block", &f_sendBlock};
const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror};
const struct MENU_DEF menu_volt = {"Akku", &adc_check};
const struct MENU_DEF menu_nop = {"---", NULL};
static menuentry menu[] = {
2011-07-05 12:42:12 +00:00
&menu_init,
&menu_status,
&menu_rcv,
2011-07-07 22:39:51 +00:00
&menu_snd,
2011-07-14 00:24:42 +00:00
&menu_sndblock,
&menu_nop,
&menu_mirror,
&menu_volt,
&menu_ISP,
NULL,
};
static const struct MENU mainmenu = {"Mainmenu", menu};
void main_funk(void) {
backlightInit();
2011-07-09 20:49:24 +00:00
font=&Font_7x8;
while (1) {
lcdFill(0); // clear display buffer
lcdDisplay(0);
handleMenu(&mainmenu);
gotoISP();
}
};
void tick_funk(void){
static int foo=0;
static int toggle=0;
if(foo++>50){
toggle=1-toggle;
foo=0;
gpioSetValue (RB_LED0, toggle);
};
return;
};
2011-07-07 22:39:51 +00:00