Mesh++ Now we can display messages.

This commit is contained in:
Stefan `Sec` Zehl 2011-07-30 19:06:12 +02:00
parent 1a23641c8d
commit 8625d1b3ef
2 changed files with 178 additions and 7 deletions

View File

@ -84,22 +84,192 @@ inline void blink(char a, char b){
}; };
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/font->u8Height)-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;
void m_cleanup(void){ for(int o=0;o<MESHBUFSIZE;o++){
mesh_cleanup(); 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;
}; };
void m_recv(void){ return msgtypes;
mesh_recvloop();
}
void m_send(void){
mesh_sendloop();
}; };
extern MPKT meshbuffer[MESHBUFSIZE];
void m_choose(){
char list[99];
int i=0;
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;
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;
};
struct tm *tm= mygmtime(MO_TIME(meshbuffer[j].pkt));
lcdPrintInt(tm->tm_hour);
lcdPrint(":");
lcdPrintInt(tm->tm_min);
lcdPrint(":");
lcdPrintInt(tm->tm_sec);
lcdNl();
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){ void tick_mesh(void){
mesh_systick(); mesh_systick();
}; };

View File

@ -17,6 +17,7 @@
#define MO_GEN_set(x,y) (x[1]=y) #define MO_GEN_set(x,y) (x[1]=y)
#define MO_TIME(x) (uint8ptouint32(x+2)) #define MO_TIME(x) (uint8ptouint32(x+2))
#define MO_TIME_set(x,y) (uint32touint8p(y,x+2)) #define MO_TIME_set(x,y) (uint32touint8p(y,x+2))
#define MO_BODY(x) (x+6)
typedef struct { typedef struct {
uint8_t pkt[32]; uint8_t pkt[32];