2011-07-16 21:04:40 +00:00
|
|
|
#include <sysinit.h>
|
|
|
|
|
|
|
|
#include "basic/basic.h"
|
|
|
|
|
|
|
|
#include "lcd/lcd.h"
|
|
|
|
#include "lcd/print.h"
|
|
|
|
|
|
|
|
#include "funk/nrf24l01p.h"
|
2011-07-17 00:01:51 +00:00
|
|
|
#include "usb/usbmsc.h"
|
2011-07-16 21:04:40 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2011-07-16 23:06:06 +00:00
|
|
|
uint32_t const testkey[4] = {
|
|
|
|
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
|
|
|
|
};
|
|
|
|
|
2011-07-16 21:04:40 +00:00
|
|
|
void f_init(void){
|
|
|
|
nrf_init();
|
|
|
|
|
|
|
|
struct NRF_CFG config = {
|
|
|
|
.channel= 81,
|
2011-07-17 00:01:51 +00:00
|
|
|
.txmac= "REMOT",
|
2011-07-16 21:04:40 +00:00
|
|
|
.nrmacs=1,
|
2011-07-17 00:01:51 +00:00
|
|
|
.mac0= "REMOT",
|
2011-07-16 21:04:40 +00:00
|
|
|
.maclen ="\x10",
|
|
|
|
};
|
|
|
|
|
|
|
|
nrf_config_set(&config);
|
|
|
|
|
|
|
|
lcdPrintln("Done.");
|
|
|
|
};
|
|
|
|
|
|
|
|
void f_recv(void){
|
|
|
|
__attribute__ ((aligned (4))) uint8_t buf[32];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
while(1){
|
2011-07-16 23:06:06 +00:00
|
|
|
len=nrf_rcv_pkt_time_encr(1000,sizeof(buf),buf,testkey);
|
2011-07-16 21:04:40 +00:00
|
|
|
|
|
|
|
if(len==0){
|
|
|
|
lcdPrintln("No pkt (Timeout)");
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
lcdClear();
|
|
|
|
lcdPrint("Size:");lcdPrintInt(len);lcdNl();
|
|
|
|
|
|
|
|
lcdPrintCharHex(buf[0]);
|
|
|
|
lcdPrint(" ");
|
|
|
|
lcdPrintCharHex(buf[1]);
|
|
|
|
lcdPrint(" ");
|
|
|
|
lcdPrintCharHex(buf[2]);
|
|
|
|
lcdPrint(" ");
|
|
|
|
lcdPrintCharHex(buf[3]);
|
|
|
|
lcdNl();
|
|
|
|
|
|
|
|
lcdPrint("ct:");lcdPrintIntHex( *(int*)(buf+ 4) ); lcdNl();
|
|
|
|
lcdPrint("id:");lcdPrintIntHex( *(int*)(buf+ 8) ); lcdNl();
|
2011-07-16 23:06:06 +00:00
|
|
|
lcdPrint("xx:");lcdPrintIntHex( *(int*)(buf+12) ); lcdNl();
|
2011-07-18 20:09:31 +00:00
|
|
|
lcdDisplay();
|
2011-07-16 21:04:40 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void f_send(void){
|
|
|
|
int ctr=1;
|
2011-07-16 23:06:06 +00:00
|
|
|
__attribute__ ((aligned (4))) uint8_t buf[32];
|
2011-07-17 00:23:07 +00:00
|
|
|
int len;
|
2011-07-16 21:04:40 +00:00
|
|
|
int status;
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
|
|
|
|
buf[0]=0x10; // Length: 16 bytes
|
2011-07-17 00:23:07 +00:00
|
|
|
buf[1]='C'; // Proto
|
2011-07-16 21:04:40 +00:00
|
|
|
buf[2]=getInputRaw();
|
|
|
|
buf[3]=0x00; // Unused
|
|
|
|
|
|
|
|
ctr++;
|
|
|
|
*(int*)(buf+4)=ctr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
buf[4]=0x00; // ctr
|
|
|
|
buf[5]=0x00; // ctr
|
|
|
|
buf[6]=0x00; // ctr
|
|
|
|
buf[7]=ctr++; // ctr
|
|
|
|
*/
|
|
|
|
|
|
|
|
buf[8]=0x0; // Object id
|
|
|
|
buf[9]=0x0;
|
|
|
|
buf[10]=0x05;
|
|
|
|
buf[11]=0xec;
|
|
|
|
|
|
|
|
buf[12]=0xff; // salt (0xffff always?)
|
|
|
|
buf[13]=0xff;
|
|
|
|
|
2011-07-16 23:06:06 +00:00
|
|
|
status=nrf_snd_pkt_crc_encr(16,buf,testkey);
|
2011-07-16 21:04:40 +00:00
|
|
|
lcdClear();
|
|
|
|
lcdPrint("Key:"); lcdPrintInt(buf[2]); lcdNl();
|
|
|
|
lcdPrint("F-St:"); lcdPrintInt(status);
|
|
|
|
if(buf[2]==BTN_ENTER)
|
|
|
|
break;
|
2011-07-18 20:09:31 +00:00
|
|
|
lcdDisplay();
|
2011-07-17 00:23:07 +00:00
|
|
|
len=nrf_rcv_pkt_time_encr(10,sizeof(buf),buf,testkey);
|
|
|
|
if(len>0){
|
|
|
|
lcdPrint("Got!");
|
|
|
|
};
|
2011-07-16 21:04:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
void gotoISP(void) {
|
|
|
|
DoString(0,0,"Enter ISP!");
|
2011-07-18 20:09:31 +00:00
|
|
|
lcdDisplay();
|
|
|
|
ISPandReset();
|
2011-07-16 21:04:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2011-07-18 20:09:31 +00:00
|
|
|
lcdDisplay();
|
2011-07-16 21:04:40 +00:00
|
|
|
};
|
|
|
|
dy+=8;
|
|
|
|
dx=DoString(0,dy,"Done.");
|
|
|
|
};
|
|
|
|
|
2011-07-17 00:01:51 +00:00
|
|
|
void msc_menu(void){
|
|
|
|
DoString(0,8,"MSC Enabled.");
|
2011-07-18 20:09:31 +00:00
|
|
|
lcdDisplay();
|
2011-07-17 00:01:51 +00:00
|
|
|
usbMSCInit();
|
|
|
|
while(!getInputRaw())delayms(10);
|
|
|
|
DoString(0,16,"MSC Disabled.");
|
|
|
|
usbMSCOff();
|
|
|
|
};
|
|
|
|
|
2011-07-16 21:04:40 +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_rcv = {"F Recv", &f_recv};
|
|
|
|
const struct MENU_DEF menu_snd = {"F Send", &f_send};
|
|
|
|
//const struct MENU_DEF menu_cfg = {"F Cfg", &f_cfg};
|
|
|
|
const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror};
|
|
|
|
const struct MENU_DEF menu_volt = {"Akku", &adc_check};
|
2011-07-17 00:01:51 +00:00
|
|
|
const struct MENU_DEF menu_msc = {"MSC", &msc_menu};
|
2011-07-16 21:04:40 +00:00
|
|
|
const struct MENU_DEF menu_nop = {"---", NULL};
|
|
|
|
|
|
|
|
static menuentry menu[] = {
|
|
|
|
&menu_init,
|
|
|
|
&menu_rcv,
|
|
|
|
&menu_snd,
|
|
|
|
// &menu_cfg,
|
|
|
|
&menu_nop,
|
|
|
|
&menu_mirror,
|
|
|
|
&menu_volt,
|
2011-07-17 00:01:51 +00:00
|
|
|
&menu_msc,
|
|
|
|
&menu_nop,
|
2011-07-16 21:04:40 +00:00
|
|
|
&menu_ISP,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct MENU mainmenu = {"Mainmenu", menu};
|
|
|
|
|
|
|
|
void main_remote(void) {
|
|
|
|
|
|
|
|
font=&Font_7x8;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
lcdFill(0); // clear display buffer
|
2011-07-18 20:09:31 +00:00
|
|
|
lcdDisplay();
|
2011-07-16 21:04:40 +00:00
|
|
|
handleMenu(&mainmenu);
|
|
|
|
gotoISP();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void tick_remote(void){
|
|
|
|
static int foo=0;
|
|
|
|
static int toggle=0;
|
|
|
|
if(foo++>80){
|
|
|
|
toggle=1-toggle;
|
|
|
|
foo=0;
|
|
|
|
gpioSetValue (RB_LED0, toggle);
|
|
|
|
};
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
|