2011-08-02 00:10:15 +00:00
|
|
|
#include <sysinit.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "basic/basic.h"
|
|
|
|
#include "basic/byteorder.h"
|
2011-08-02 22:25:09 +00:00
|
|
|
#include "basic/config.h"
|
2011-08-02 00:10:15 +00:00
|
|
|
|
|
|
|
#include "lcd/lcd.h"
|
|
|
|
#include "lcd/print.h"
|
|
|
|
|
|
|
|
#include "funk/nrf24l01p.h"
|
|
|
|
|
|
|
|
#include "funk/mesh.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2011-08-02 11:31:57 +00:00
|
|
|
void init_mesh(void){
|
2011-08-02 00:10:15 +00:00
|
|
|
nrf_init();
|
|
|
|
initMesh();
|
|
|
|
};
|
|
|
|
|
|
|
|
int choose(char * texts, int8_t menuselection){
|
|
|
|
uint8_t numentries = 0;
|
|
|
|
uint8_t visible_lines = 0;
|
|
|
|
uint8_t current_offset = 0;
|
|
|
|
|
|
|
|
char*p=texts;
|
|
|
|
|
|
|
|
do{
|
|
|
|
lcdPrintln(p);
|
|
|
|
while(*p)p++;
|
|
|
|
numentries++;p++;
|
|
|
|
}while(*p);
|
|
|
|
numentries--;
|
|
|
|
|
|
|
|
visible_lines = (RESY/getFontHeight())-1; // subtract title line
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
// Display current menu page
|
|
|
|
lcdClear();
|
|
|
|
lcdPrintln(texts);
|
|
|
|
p=texts;
|
|
|
|
while(*p++);
|
|
|
|
for(int i=0;i<current_offset;i++)
|
|
|
|
while(*p++);
|
|
|
|
for (uint8_t i = current_offset; i < (visible_lines + current_offset) && i < numentries; i++) {
|
|
|
|
if (i == menuselection)
|
|
|
|
lcdPrint("*");
|
|
|
|
lcdSetCrsrX(14);
|
|
|
|
lcdPrintln(p);
|
|
|
|
while(*p++);
|
|
|
|
}
|
|
|
|
lcdRefresh();
|
|
|
|
|
|
|
|
switch (getInputWait()) {
|
|
|
|
case BTN_UP:
|
|
|
|
menuselection--;
|
|
|
|
if (menuselection < current_offset) {
|
|
|
|
if (menuselection < 0) {
|
|
|
|
menuselection = numentries-1;
|
|
|
|
current_offset = ((numentries-1)/visible_lines) * visible_lines;
|
|
|
|
} else {
|
|
|
|
current_offset -= visible_lines;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BTN_DOWN:
|
|
|
|
menuselection++;
|
|
|
|
if (menuselection > (current_offset + visible_lines-1) || menuselection >= numentries) {
|
|
|
|
if (menuselection >= numentries) {
|
|
|
|
menuselection = 0;
|
|
|
|
current_offset = 0;
|
|
|
|
} else {
|
|
|
|
current_offset += visible_lines;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BTN_LEFT:
|
|
|
|
return -1;
|
|
|
|
case BTN_RIGHT:
|
|
|
|
case BTN_ENTER:
|
|
|
|
return menuselection;
|
|
|
|
}
|
|
|
|
getInputWaitRelease();
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
char *meshmsgs(void){
|
|
|
|
static char msgtypes[MESHBUFSIZE+1];
|
|
|
|
memset(msgtypes,'_',MESHBUFSIZE);
|
|
|
|
msgtypes[MESHBUFSIZE]=0;
|
|
|
|
uint8_t lo=0;
|
|
|
|
uint8_t hi;
|
|
|
|
|
|
|
|
for(int o=0;o<MESHBUFSIZE;o++){
|
|
|
|
hi=0xff;
|
|
|
|
for(int i=0;i<MESHBUFSIZE;i++){
|
|
|
|
if(meshbuffer[i].flags&MF_USED){
|
|
|
|
if(MO_TYPE(meshbuffer[i].pkt)>lo)
|
|
|
|
if(MO_TYPE(meshbuffer[i].pkt)<hi)
|
|
|
|
hi=MO_TYPE(meshbuffer[i].pkt);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if(hi==0xff){
|
|
|
|
msgtypes[o]=0;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
msgtypes[o]=hi;
|
|
|
|
lo=hi;
|
|
|
|
};
|
|
|
|
|
|
|
|
return msgtypes;
|
|
|
|
};
|
|
|
|
|
2011-08-05 09:44:57 +00:00
|
|
|
static inline uint32_t popcount(uint32_t *buf, uint8_t n){
|
|
|
|
int cnt=0;
|
|
|
|
do {
|
|
|
|
unsigned m = *buf++;
|
|
|
|
m = (m & 0x55555555) + ((m & 0xaaaaaaaa) >> 1);
|
|
|
|
m = (m & 0x33333333) + ((m & 0xcccccccc) >> 2);
|
|
|
|
m = (m & 0x0f0f0f0f) + ((m & 0xf0f0f0f0) >> 4);
|
|
|
|
m = (m & 0x00ff00ff) + ((m & 0xff00ff00) >> 8);
|
|
|
|
m = (m & 0x0000ffff) + ((m & 0xffff0000) >> 16);
|
|
|
|
cnt += m;
|
|
|
|
} while(--n);
|
|
|
|
return cnt;
|
|
|
|
}
|
2011-08-02 00:10:15 +00:00
|
|
|
|
|
|
|
extern MPKT meshbuffer[MESHBUFSIZE];
|
2011-08-04 22:52:23 +00:00
|
|
|
//# MENU messages
|
2011-08-02 00:10:15 +00:00
|
|
|
void m_choose(){
|
|
|
|
char list[99];
|
|
|
|
int i=0;
|
|
|
|
|
2011-08-04 12:54:16 +00:00
|
|
|
meshmsg=0;
|
|
|
|
gpioSetValue (RB_LED1, 0);
|
|
|
|
|
2011-08-02 00:10:15 +00:00
|
|
|
while(1){
|
|
|
|
char *p=list;
|
|
|
|
strcpy(p,"Note");
|
|
|
|
while(*p++);
|
|
|
|
|
|
|
|
char *mm=meshmsgs();
|
|
|
|
char *tmm=mm;
|
|
|
|
while(*mm){
|
|
|
|
switch(*mm){
|
|
|
|
case('A'):
|
|
|
|
strcpy(p,"Message");
|
|
|
|
break;
|
|
|
|
case('E'):
|
|
|
|
strcpy(p,"Kourou");
|
|
|
|
break;
|
|
|
|
case('F'):
|
|
|
|
strcpy(p,"Baikonur");
|
|
|
|
break;
|
|
|
|
case('T'):
|
|
|
|
strcpy(p,"Time");
|
|
|
|
break;
|
|
|
|
case('i'):
|
|
|
|
strcpy(p,"Invaders");
|
|
|
|
break;
|
2011-08-12 22:52:41 +00:00
|
|
|
case('j'):
|
|
|
|
strcpy(p,"Jump");
|
|
|
|
break;
|
|
|
|
case('r'):
|
|
|
|
strcpy(p,"r0type");
|
|
|
|
break;
|
2011-08-02 00:10:15 +00:00
|
|
|
default:
|
|
|
|
p[0]=*mm;
|
|
|
|
p[1]=0;
|
|
|
|
};
|
|
|
|
while(*p++);
|
|
|
|
mm++;
|
|
|
|
};
|
|
|
|
p[0]=0;
|
|
|
|
|
|
|
|
i=choose(list,i);
|
|
|
|
if(i<0)
|
|
|
|
return;
|
|
|
|
lcdClear();
|
|
|
|
|
|
|
|
int j=0;
|
|
|
|
for(int z=0;z<MESHBUFSIZE;z++)
|
|
|
|
if(meshbuffer[z].flags&MF_USED)
|
|
|
|
if(MO_TYPE(meshbuffer[z].pkt)==tmm[i])
|
|
|
|
j=z;
|
|
|
|
|
|
|
|
switch(tmm[i]){
|
|
|
|
case('A'):
|
|
|
|
lcdPrintln("Message");
|
|
|
|
break;
|
|
|
|
case('E'):
|
|
|
|
lcdPrintln("Kourou");
|
|
|
|
break;
|
|
|
|
case('F'):
|
|
|
|
lcdPrintln("Baikonur");
|
|
|
|
break;
|
|
|
|
case('T'):
|
|
|
|
lcdPrintln("Time");
|
|
|
|
break;
|
|
|
|
case('i'):
|
|
|
|
lcdPrintln("Invaders");
|
|
|
|
break;
|
2011-08-12 22:52:41 +00:00
|
|
|
case('j'):
|
|
|
|
strcpy(p,"Jump");
|
|
|
|
break;
|
|
|
|
case('r'):
|
|
|
|
strcpy(p,"r0type");
|
|
|
|
break;
|
2011-08-02 00:10:15 +00:00
|
|
|
};
|
|
|
|
if(tmm[i]>='a' && tmm[i]<='z'){
|
|
|
|
lcdPrintln(IntToStr(MO_TIME(meshbuffer[j].pkt),10,0));
|
|
|
|
}else{
|
|
|
|
struct tm *tm= mygmtime(MO_TIME(meshbuffer[j].pkt));
|
|
|
|
lcdPrint(IntToStr(tm->tm_hour,2,F_LONG));
|
|
|
|
lcdPrint(":");
|
|
|
|
lcdPrint(IntToStr(tm->tm_min,2,F_LONG|F_ZEROS));
|
|
|
|
lcdPrint(":");
|
|
|
|
lcdPrint(IntToStr(tm->tm_sec,2,F_LONG|F_ZEROS));
|
|
|
|
lcdNl();
|
2011-08-03 21:36:16 +00:00
|
|
|
|
2011-08-05 09:44:57 +00:00
|
|
|
if(tmm[i]=='Z'){
|
|
|
|
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[j].pkt+ 6),8));
|
|
|
|
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[j].pkt+10),8));
|
|
|
|
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[j].pkt+14),8));
|
|
|
|
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[j].pkt+18),8));
|
|
|
|
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[j].pkt+22),8));
|
|
|
|
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[j].pkt+26),8));
|
2011-08-05 16:11:37 +00:00
|
|
|
lcdPrint(IntToStr(popcount((uint32_t*)(meshbuffer[j].pkt+6),6),3,0));
|
2011-08-05 09:44:57 +00:00
|
|
|
lcdPrintln(" pts.");
|
|
|
|
lcdRefresh();
|
|
|
|
getInputWaitRelease();
|
|
|
|
continue;
|
|
|
|
}else if(tmm[i]=='T'){
|
2011-08-03 21:36:16 +00:00
|
|
|
lcdPrint(IntToStr(tm->tm_mday,2,F_LONG));
|
|
|
|
lcdPrint(".");
|
|
|
|
lcdPrint(IntToStr(tm->tm_mon+1,2,0));
|
|
|
|
lcdPrint(".");
|
|
|
|
lcdPrint(IntToStr(tm->tm_year+YEAR0,4,F_LONG|F_ZEROS));
|
|
|
|
lcdNl();
|
2011-08-04 18:23:14 +00:00
|
|
|
MO_BODY(meshbuffer[j].pkt)[0]=0;
|
2011-08-03 21:36:16 +00:00
|
|
|
};
|
2011-08-02 00:10:15 +00:00
|
|
|
};
|
|
|
|
char *foo=(char *)MO_BODY(meshbuffer[j].pkt);
|
|
|
|
while(strlen(foo)>13){
|
|
|
|
int q;
|
|
|
|
for(q=0;q<13;q++){
|
|
|
|
if(foo[q]==' ')
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
foo[q]=0;
|
|
|
|
lcdPrintln(foo);
|
|
|
|
foo[q]=' ';
|
|
|
|
foo+=q+1;
|
|
|
|
};
|
|
|
|
lcdPrintln(foo);
|
|
|
|
lcdRefresh();
|
|
|
|
getInputWaitRelease();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void tick_mesh(void){
|
2011-08-02 22:25:09 +00:00
|
|
|
if(GLOBAL(privacy)<2)
|
|
|
|
mesh_systick();
|
2011-08-04 12:54:16 +00:00
|
|
|
if(_timectr%64)
|
|
|
|
if(meshmsg){
|
|
|
|
gpioSetValue (RB_LED1, 1);
|
|
|
|
meshmsg=0;
|
|
|
|
};
|
2011-08-02 00:10:15 +00:00
|
|
|
};
|
|
|
|
|