#include #include "console.h" #include "screen.h" #include "charmap.h" #include "menu.h" #define LED_MODE_ADDR 0x90110B00 #define TEXT_SIZE 256 int getMem(int addr) { return *(volatile unsigned*) addr; } void setMem(int addr, int val) { *(volatile unsigned*) addr = val; } #define MENU_ITEMS 6 #define NORSE_TCODES 95 #define NORSE_TCHARS 64 short int norse_chars2sigs[NORSE_TCODES]; short int norse_sigs2chars[NORSE_TCODES]; void add_norse(char c, int sigs) { norse_chars2sigs[c]=sigs; norse_sigs2chars[sigs]=c; } void init_norse() { memset(norse_chars2sigs, 0, NORSE_TCODES*sizeof(short int)); //signals 2-1-0: GRGRGR <- add_norse(' ', 0b000000); add_norse('E', 0b000001); add_norse('S', 0b000010); add_norse('A', 0b000011); add_norse('I', 0b000101); add_norse('T', 0b001001); add_norse('N', 0b001101); add_norse('R', 0b000110); add_norse('U', 0b001010); add_norse('L', 0b001110); add_norse('O', 0b000111); add_norse('D', 0b001011); add_norse('C', 0b001111); add_norse('P', 0b010101); add_norse('M', 0b100101); add_norse('V', 0b110101); add_norse('Q', 0b011001); add_norse('F', 0b101001); add_norse('B', 0b111001); add_norse('G', 0b011101); add_norse('H', 0b101101); add_norse('J', 0b111101); add_norse('X', 0b010110); add_norse('Y', 0b100110); add_norse('Z', 0b110110); add_norse('W', 0b011010); add_norse('K', 0b101010); add_norse('0', 0b111010); add_norse('1', 0b011110); add_norse('2', 0b101110); add_norse('3', 0b111110); add_norse('4', 0b010111); add_norse('5', 0b100111); add_norse('6', 0b110111); add_norse('7', 0b011011); add_norse('8', 0b101011); add_norse('9', 0b111011); add_norse('-', 0b011111); add_norse('.', 0b101111); add_norse('/', 0b111111); } char* strNorseSigs(char* tmp, int sig) { int csig; char t; int i; for(i=0;i<3 && sig;i++) { csig=sig&0b11; sig=sig>>2; if((csig&0b11) == 0b11) t='Y'; else if(csig&0b01) t='R'; else if(csig&0b10) t='G'; else t='_'; tmp[i]=t; } tmp[i]=0; return tmp; } #define TIME_BASE 100 void sendSigs(int sig) { int cmode; if(!sig) wait(4*TIME_BASE); while(sig && !isKeyPressed(KEY_NSPIRE_ESC)) { cmode=0; if(sig&0b01) cmode|=0b100000; if(sig&0b10) cmode|=0b010000; sig=sig>>2; setMem(LED_MODE_ADDR,cmode); wait(3*TIME_BASE); setMem(LED_MODE_ADDR,0); wait(TIME_BASE); } wait(6*TIME_BASE); } void encMess(char* str, int progress, int trace) { int n = strlen(str); int i; for(i=0;i ",0); mode_last=getMem(LED_MODE_ADDR); dispi(mode_curr,0); if(mode_last!=mode_curr) { disp(" * error *",0); error=1; } displn("",0); } } } void dispNorseTable() { int i=0; displn(" Sigs: Chars Sigs: Chars Sigs: Chars",0); displn("-------------- ------------- -------------",0); int l=5; char tmp[4]; int c=0; for(;i=MAX_LGN-1) { l=5; c++; } } } drwStr(0,(MAX_LGN-1)*CHAR_HEIGHT,"[Esc] to continue",0); while(!isKeyPressed(KEY_NSPIRE_ESC)) {} } void sendMessage(char* msg) { while(!isKeyPressed(KEY_NSPIRE_ESC)) { clrScr(); resetConsole(); displn("Sending:",0); displn(LSEPARATOR,0); displn(msg,1); displn(LSEPARATOR,0); displn("",0); initProgress(0,5+(strlen(msg)/40),0); displn("",0); displn("",0); displn("Sent message:",0); displn(LSEPARATOR,0); encMess(msg,1,1); displn("",0); displn(LSEPARATOR,0); drwStr(0,(MAX_LGN-2)*CHAR_HEIGHT,"[Enter] to resend",0); drwStr(0,(MAX_LGN-1)*CHAR_HEIGHT,"[ Esc ] to continue",0); while(isKeyPressed(KEY_NSPIRE_ESC)) {} while(!isKeyPressed(KEY_NSPIRE_ESC) && !isKeyPressed(KEY_NSPIRE_ENTER) && !isKeyPressed(KEY_NSPIRE_RET)){} } while(isKeyPressed(KEY_NSPIRE_ESC)) {} } char getPressedChar() { char c=0; if(isKeyPressed(KEY_NSPIRE_A)) c='A'; else if(isKeyPressed(KEY_NSPIRE_B)) c='B'; else if(isKeyPressed(KEY_NSPIRE_C)) c='C'; else if(isKeyPressed(KEY_NSPIRE_D)) c='D'; else if(isKeyPressed(KEY_NSPIRE_E) || isKeyPressed(KEY_NSPIRE_EE)) c='E'; else if(isKeyPressed(KEY_NSPIRE_F)) c='F'; else if(isKeyPressed(KEY_NSPIRE_G)) c='G'; else if(isKeyPressed(KEY_NSPIRE_H)) c='H'; else if(isKeyPressed(KEY_NSPIRE_I) || isKeyPressed(KEY_NSPIRE_II)) c='I'; else if(isKeyPressed(KEY_NSPIRE_J)) c='J'; else if(isKeyPressed(KEY_NSPIRE_K)) c='K'; else if(isKeyPressed(KEY_NSPIRE_L)) c='L'; else if(isKeyPressed(KEY_NSPIRE_M)) c='M'; else if(isKeyPressed(KEY_NSPIRE_N)) c='N'; else if(isKeyPressed(KEY_NSPIRE_O)) c='O'; else if(isKeyPressed(KEY_NSPIRE_P)) c='P'; else if(isKeyPressed(KEY_NSPIRE_Q)) c='Q'; else if(isKeyPressed(KEY_NSPIRE_R)) c='R'; else if(isKeyPressed(KEY_NSPIRE_S)) c='S'; else if(isKeyPressed(KEY_NSPIRE_T)) c='T'; else if(isKeyPressed(KEY_NSPIRE_U)) c='U'; else if(isKeyPressed(KEY_NSPIRE_V)) c='V'; else if(isKeyPressed(KEY_NSPIRE_W)) c='W'; else if(isKeyPressed(KEY_NSPIRE_X)) c='X'; else if(isKeyPressed(KEY_NSPIRE_Y)) c='Y'; else if(isKeyPressed(KEY_NSPIRE_Z)) c='Z'; else if(isKeyPressed(KEY_NSPIRE_0)) c='0'; else if(isKeyPressed(KEY_NSPIRE_1)) c='1'; else if(isKeyPressed(KEY_NSPIRE_2)) c='2'; else if(isKeyPressed(KEY_NSPIRE_3)) c='3'; else if(isKeyPressed(KEY_NSPIRE_4)) c='4'; else if(isKeyPressed(KEY_NSPIRE_5)) c='5'; else if(isKeyPressed(KEY_NSPIRE_6)) c='6'; else if(isKeyPressed(KEY_NSPIRE_7)) c='7'; else if(isKeyPressed(KEY_NSPIRE_8)) c='8'; else if(isKeyPressed(KEY_NSPIRE_9)) c='9'; else if(isKeyPressed(KEY_NSPIRE_SPACE)) c=' '; else if(isKeyPressed(KEY_NSPIRE_MINUS) || isKeyPressed(KEY_NSPIRE_NEGATIVE)) c='-'; else if(isKeyPressed(KEY_NSPIRE_PERIOD) || isKeyPressed(KEY_NSPIRE_COMMA)) c='.'; else if(isKeyPressed(KEY_NSPIRE_DIVIDE))c='/'; return c; } char inputShort() { char c=0; while(!isKeyPressed(KEY_NSPIRE_ESC) && !c) c=getPressedChar(); return c; } int inputMess(char* tmp) { int r=1; *tmp=0; int l=0; char c=1; while(!isKeyPressed(KEY_NSPIRE_ESC) && !isKeyPressed(KEY_NSPIRE_ENTER) && !isKeyPressed(KEY_NSPIRE_RET)) { if(c) { clrScr(); resetConsole(); drwStr(0,(MAX_LGN-4)*CHAR_HEIGHT,"[Space] between words",0); drwStr(0,(MAX_LGN-3)*CHAR_HEIGHT,"[Enter] to send message",0); drwStr(0,(MAX_LGN-2)*CHAR_HEIGHT,"[Clear] to cancel last char",0); drwStr(0,(MAX_LGN-1)*CHAR_HEIGHT,"[ Esc ] to return",0); displn("Enter message:",0); displn(LSEPARATOR,0); displn(tmp,1); displn(LSEPARATOR,0); wait(200); } c=0; if(l>0 && (isKeyPressed(KEY_NSPIRE_LEFT) || isKeyPressed(KEY_NSPIRE_CLEAR))) { tmp[l-1]=0; l--; c=-1;} else { c=getPressedChar(); if(c!=0 && c!=-1) { tmp[l]=c; tmp[l+1]=0; l++; } } } if(isKeyPressed(KEY_NSPIRE_ESC)) r=0; while(isKeyPressed(KEY_NSPIRE_ESC)) {} return r; } void inputLights() { char tmp[TEXT_SIZE]; char tmps[4]; *tmp=0; int code=0; int sig=0; int l=0; int c=1; int s=0; while(!isKeyPressed(KEY_NSPIRE_ESC)) { if(c) { clrScr(); resetConsole(); drwStr(0,(MAX_LGN-5)*CHAR_HEIGHT,"[R]ed [G]reen [Y]ellow",0); drwStr(0,(MAX_LGN-4)*CHAR_HEIGHT,"[Space]x2 for long pauses between words",0); drwStr(0,(MAX_LGN-3)*CHAR_HEIGHT,"[Space] for short pauses between chars",0); drwStr(0,(MAX_LGN-2)*CHAR_HEIGHT,"[Clear] to cancel last color/char",0); drwStr(0,(MAX_LGN-1)*CHAR_HEIGHT,"[ Esc ] to return",0); displn("Enter colors seen on the other Nspire!",0); displn("Current message: ",0); displn(LSEPARATOR,0); displn(tmp,1); displn(LSEPARATOR,0); disp("Next character colors: ",0); displn(strNorseSigs(tmps,code),0); disp("Next character: ",0); if(code) dispc(norse_sigs2chars[code],0); wait(200); c=0; } if((l>0 || s>0) && (isKeyPressed(KEY_NSPIRE_LEFT) || isKeyPressed(KEY_NSPIRE_CLEAR))) { if(!code) {tmp[l-1]=0; l--; c=-1;} else { tmps[s-1]=0; code=code&(0b111111>>(2*(4-s))); s--; c=-1; } } else if(isKeyPressed(KEY_NSPIRE_SPACE) || isKeyPressed(KEY_NSPIRE_RET) || isKeyPressed(KEY_NSPIRE_ENTER) || isKeyPressed(KEY_NSPIRE_RIGHT)) { if(code) { tmp[l+1]=0; tmp[l]=norse_sigs2chars[code]; l++; code=0; s=0; } else { tmp[l]=' '; tmp[l+1]=0; l++; } c=1; } else if(isKeyPressed(KEY_NSPIRE_Y) || isKeyPressed(KEY_NSPIRE_J) || isKeyPressed(KEY_NSPIRE_R) || isKeyPressed(KEY_NSPIRE_V) || isKeyPressed(KEY_NSPIRE_G)) { if(s==3) { tmp[l+1]=0; tmp[l]=norse_sigs2chars[code]; l++; code=0; s=0; } sig=0; if(isKeyPressed(KEY_NSPIRE_R)) sig|=0b01; if(isKeyPressed(KEY_NSPIRE_G) || isKeyPressed(KEY_NSPIRE_V)) sig|=0b10; if(isKeyPressed(KEY_NSPIRE_Y) || isKeyPressed(KEY_NSPIRE_J)) sig|=0b11; sig=sig<<(2*s); code|=sig; c=1; s++; } } while(isKeyPressed(KEY_NSPIRE_ESC)) {} } void inputLoopMess() { char tmp[TEXT_SIZE]; while(inputMess(tmp)) sendMessage(tmp); } void inputLoopShort() { char c; drwStr(0,(MAX_LGN-1)*CHAR_HEIGHT,"[Esc] to return",0); displn("Press chars to send:",0); displn(LSEPARATOR,0); while((c=inputShort())) { dispc(c,0); drwStr(0,(MAX_LGN-2)*CHAR_HEIGHT,"Sending... Wait!",0); sendSigs(norse_chars2sigs[c]); drwStr(0,(MAX_LGN-2)*CHAR_HEIGHT," ",0); } while(isKeyPressed(KEY_NSPIRE_ESC)) {} } int main(int argc, char* argv[]) { int mode_orig = getMem(LED_MODE_ADDR); int m; char* str[MENU_ITEMS]; str[0]="Messages editor"; str[1]="Typewriter"; str[2]="Messages decoder"; str[3]="Codes table (Norse 1.0)"; str[4]="Test LED"; str[5]="Quit"; init_norse(); while((m=menu("Norse 1.0 ( http://www.ti-bank.fr/911 )",str,MENU_ITEMS))>=0 && m