From 78561095623b75cc1c11dc0582f85ee8b2215e9a Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 11 Aug 2011 01:53:54 +0200 Subject: [PATCH 01/29] debug menu, mesh info: browse pkt details --- firmware/l0dable/debug.c | 94 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 3 deletions(-) diff --git a/firmware/l0dable/debug.c b/firmware/l0dable/debug.c index 2c65d1f..2603037 100644 --- a/firmware/l0dable/debug.c +++ b/firmware/l0dable/debug.c @@ -165,12 +165,72 @@ void getsp(void) { dx=DoString(0,dy,"Done."); }; +void m_time_details(int select) { + getInputWaitRelease(); + + while(getInputWaitTimeout(50) != BTN_LEFT){ + lcdClear(); + MPKT *mpkt = &meshbuffer[select]; + uint8_t *pkt = mpkt->pkt; + + if (!mpkt->flags & MF_USED) + lcdPrint(""); + else { + lcdPrint("Type: "); + char c[2] = {0, 0}; + c[0] = mpkt->pkt[0]; + lcdPrint(c); + lcdNl(); + + lcdPrint("Gen: "); + lcdPrintInt(MO_GEN(pkt) & 0xff); + lcdNl(); + + lcdPrint("Time: "); + lcdPrintInt(MO_TIME(pkt) & 0xffff); + lcdNl(); + lcdPrint("Body: "); + lcdNl(); + + int x = 0; + for(uint8_t *body = MO_BODY(pkt); body < pkt + 32; body++) { + if (*body >= ' ' && *body < 128) { + if (x > 12) { + lcdNl(); + x = 0; + } + + char c[2] = {*body, 0}; + lcdPrint(c); + x++; + } else { + if (x > 10) { + lcdNl(); + x = 0; + } + + lcdPrint("\\"); + lcdPrintInt(*body & 0xff); + x += 2; + if (*body > 9) + x++; + if (*body > 99) + x++; + } + } + } + + lcdRefresh(); + } +} + void m_time(void){ struct tm* tm; + int select=0; char c[2]={0,0}; getInputWaitRelease(); delayms(100); - do{ + while(1) { lcdClear(); tm= mygmtime(getSeconds()); lcdPrint(IntToStr(tm->tm_hour,2,F_LONG)); @@ -199,6 +259,12 @@ void m_time(void){ }; lcdPrintln(">"); + lcdPrint(" "); + for(int i=0; i= MESHBUFSIZE) + select = 0; + break; + case BTN_RIGHT: + case BTN_ENTER: + m_time_details(select); + break; + case BTN_LEFT: + // Exit + return; + } + if (key != BTN_NONE) + getInputWaitRelease(); + } }; void ChkFunk(){ From ba34771069f48c83aa7611f260a50c4d1e5e909a Mon Sep 17 00:00:00 2001 From: NiciDieNase Date: Thu, 11 Aug 2011 10:51:02 +0200 Subject: [PATCH 02/29] Added SpaceInvaders Nick-Animation --- firmware/l0dable/nick_invaders.c | 80 ++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 firmware/l0dable/nick_invaders.c diff --git a/firmware/l0dable/nick_invaders.c b/firmware/l0dable/nick_invaders.c new file mode 100644 index 0000000..faab749 --- /dev/null +++ b/firmware/l0dable/nick_invaders.c @@ -0,0 +1,80 @@ +/* nick_invaders.c + * + * By NiciDieNase + * r0ket@nicidienase.de + * + * Known Bugs: + * - Ignores Font-Setting + * - might look odd with really short or really long nicknames + * + */ + +#include +#include +#include "basic/basic.h" +#include "lcd/render.h" +#include "lcd/display.h" +#include "usetable.h" +#include "lcd/fonts.h" +#include "lcd/fonts/invaders.h" +#include "lcd/fonts/invaders.c" + +void ram(void) +{ + bool step = true; + const int minX = 10; + const int minY = 10; + const int maxX = 50; + const int maxY = 30; + const int space = 15; + const int delaytime = 150; + const int defaultfont = font; + int x = minX; + int y = minY; + int u = 0; + int dir = 0; + + while(1){ + lcdFill(0); + font = &Font_Invaders; + // Draw UFO + DoChar(-15+u,1,'U'); + u+=2; + if(u > 1337) u=0; + //Draw Invaders + DoChar(x,y,step?'a':'A'); + DoChar(x+space,y,step?'b':'B'); + DoChar(x+2*space,y,step?'c':'C'); + switch (dir){ + // move left + case 0: + x++; + if(x == maxX) dir++; + break; + // move down on right end + case 1: + y++; + dir++; + if(y == maxY) y=minY; + break; + // move left + case 2: + x--; + if(x==minX) dir++; + break; + // move down on left end + case 3: + y++; + dir++; + if(y == maxY) y=minY; + break; + } + dir %= 4; + font = defaultfont; + DoString(10,40,nickname); + lcdDisplay(); + if(getInputRaw()!=BTN_NONE) return; + step = !step; + delayms_queue_plus(delaytime,0); + } +} From 493396a5978b8364608ffe1eb6405328989fabe7 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Thu, 11 Aug 2011 18:31:07 +0200 Subject: [PATCH 03/29] Move snake aside until the gfx library is back --- firmware/l0dable/{snake.c => snake.c.disabled} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename firmware/l0dable/{snake.c => snake.c.disabled} (100%) diff --git a/firmware/l0dable/snake.c b/firmware/l0dable/snake.c.disabled similarity index 100% rename from firmware/l0dable/snake.c rename to firmware/l0dable/snake.c.disabled From 22dcb53673ed1c48af5237d5f1f7be3f887cf008 Mon Sep 17 00:00:00 2001 From: Florian Richter Date: Fri, 12 Aug 2011 01:39:21 +0200 Subject: [PATCH 04/29] matrix animation as l0dable --- firmware/l0dable/matrix.c | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 firmware/l0dable/matrix.c diff --git a/firmware/l0dable/matrix.c b/firmware/l0dable/matrix.c new file mode 100644 index 0000000..c62d872 --- /dev/null +++ b/firmware/l0dable/matrix.c @@ -0,0 +1,62 @@ +#include + +#include "basic/basic.h" +#include "lcd/render.h" + +#include "usetable.h" + +#define SCREEN_WIDTH 12 +#define SCREEN_HEIGHT 8 +#define INVALID_POS 127 + +#define FONT_WIDTH 7 +#define FONT_HEIGHT 8 + +#define MATRIX_LINES_LENGTH 15 + +#define MAX_LINE_LENGTH 6 + +void ram(void){ + lcdClear(); + + struct matrix_line { + int head_x, head_y; + int cur_length; + int length; + } matrix_lines[MATRIX_LINES_LENGTH]; + + for (int i = 0; i < MATRIX_LINES_LENGTH; i++) { + matrix_lines[i].cur_length = -1; + } + + while (1) { + for(int i = 0; icur_length == -1) { + ml->head_x = getRandom() % SCREEN_WIDTH; + ml->head_y = getRandom() % SCREEN_HEIGHT - 1; + ml->length = getRandom() % MAX_LINE_LENGTH + 3; + ml->cur_length = 0; + } + // new char + if (ml->head_y < SCREEN_HEIGHT-1) { + ml->head_y++; + int chr = getRandom() % 95 + 33; + DoChar(ml->head_x * FONT_WIDTH, ml->head_y * FONT_HEIGHT, chr); + ml->cur_length++; + } + // remove chars (when length or bottom is reached) + if (ml->cur_length > ml->length || ml->head_y >= SCREEN_HEIGHT-1) { + DoChar(ml->head_x * FONT_WIDTH, (ml->head_y - ml->cur_length) * FONT_HEIGHT, ' '); + ml->cur_length--; + } + } + lcdDisplay(); + // Exit on enter+left + int key = getInputRaw(); + if(key== BTN_ENTER || key == BTN_LEFT) + return; + delayms(60); + }; +}; From 03f2f8a7d307aea704993105b93eae0567bd7a67 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Fri, 12 Aug 2011 02:59:33 +0200 Subject: [PATCH 05/29] make matrix a nickname replacement. Also make it work queue --- firmware/l0dable/{matrix.c => nick_matrix.c} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename firmware/l0dable/{matrix.c => nick_matrix.c} (96%) diff --git a/firmware/l0dable/matrix.c b/firmware/l0dable/nick_matrix.c similarity index 96% rename from firmware/l0dable/matrix.c rename to firmware/l0dable/nick_matrix.c index c62d872..a6398c9 100644 --- a/firmware/l0dable/matrix.c +++ b/firmware/l0dable/nick_matrix.c @@ -55,8 +55,8 @@ void ram(void){ lcdDisplay(); // Exit on enter+left int key = getInputRaw(); - if(key== BTN_ENTER || key == BTN_LEFT) + if(key!= BTN_NONE) return; - delayms(60); + delayms_queue_plus(90,0); }; }; From b605025acf9c580d90ed3f5d14fbd57f98954997 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Fri, 12 Aug 2011 13:27:38 +0200 Subject: [PATCH 06/29] Fix invaders nickdisplay --- firmware/l0dable/nick_invaders.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/firmware/l0dable/nick_invaders.c b/firmware/l0dable/nick_invaders.c index faab749..ab7140b 100644 --- a/firmware/l0dable/nick_invaders.c +++ b/firmware/l0dable/nick_invaders.c @@ -28,11 +28,18 @@ void ram(void) const int maxY = 30; const int space = 15; const int delaytime = 150; - const int defaultfont = font; int x = minX; int y = minY; int u = 0; int dir = 0; + int dx,dy; + + + dx=DoString(0,0,nickname); + dx=(RESX-dx)/2; + if(dx<0) + dx=0; + dy=40; while(1){ lcdFill(0); @@ -70,8 +77,8 @@ void ram(void) break; } dir %= 4; - font = defaultfont; - DoString(10,40,nickname); + font = NULL; + DoString(dx,dy,nickname); lcdDisplay(); if(getInputRaw()!=BTN_NONE) return; step = !step; From 77fb7a388a2e0cab5926b96dcae0db440cd54eee Mon Sep 17 00:00:00 2001 From: Hagen Fritsch Date: Thu, 11 Aug 2011 11:53:07 +0200 Subject: [PATCH 07/29] fix buffer overflow in font handler --- firmware/lcd/render.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/firmware/lcd/render.c b/firmware/lcd/render.c index c98b147..37f0110 100644 --- a/firmware/lcd/render.c +++ b/firmware/lcd/render.c @@ -223,7 +223,9 @@ int DoChar(int sx, int sy, int c){ _getFontData(SEEK_DATA,toff); UINT res; UINT readbytes; - res = f_read(&file, charBuf, width*height, &readbytes); + UINT size = width * height; + if(size > MAXCHR) size = MAXCHR; + res = f_read(&file, charBuf, size, &readbytes); if(res != FR_OK || readbytes MAXCHR) size = MAXCHR; + res = f_read(&file, charBuf, size, &readbytes); if(res != FR_OK || readbytes Date: Thu, 11 Aug 2011 12:05:03 +0200 Subject: [PATCH 08/29] l0dable/invaders.c: fix potential buffer overflow --- firmware/l0dable/invaders.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/firmware/l0dable/invaders.c b/firmware/l0dable/invaders.c index 94d177c..2e9dc58 100644 --- a/firmware/l0dable/invaders.c +++ b/firmware/l0dable/invaders.c @@ -178,9 +178,11 @@ static bool highscore_set(uint32_t score, char nick[]) { static uint32_t highscore_get(char nick[]){ MPKT * mpkt= meshGetMessage('i'); - - strcpy(nick,(char*)MO_BODY(mpkt->pkt)); - + char * packet_nick = (char*)MO_BODY(mpkt->pkt); + // the packet crc end is already zeroed + if(MAXNICKpkt); } From 198d91a86ea4b765349b4cc149bb0acf35f43167 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Fri, 12 Aug 2011 14:22:51 +0200 Subject: [PATCH 09/29] rumpeltux found this typo --- firmware/funk/mesh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/funk/mesh.c b/firmware/funk/mesh.c index d79973b..a951149 100644 --- a/firmware/funk/mesh.c +++ b/firmware/funk/mesh.c @@ -251,7 +251,7 @@ uint8_t mesh_recvqloop_work(void){ return 2; if((MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C') || - (MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C')) + (MO_TYPE(buf)>='a' && MO_TYPE(buf)<='c')) meshmsg=1; memcpy(mpkt->pkt,buf,MESHPKTSIZE); From ff98c7de21688f612696c80406290310bbb91dce Mon Sep 17 00:00:00 2001 From: Florian Richter Date: Fri, 12 Aug 2011 15:07:56 +0200 Subject: [PATCH 10/29] nick_matrix: show/hide nickname in center --- firmware/l0dable/nick_matrix.c | 66 +++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/firmware/l0dable/nick_matrix.c b/firmware/l0dable/nick_matrix.c index a6398c9..8e70318 100644 --- a/firmware/l0dable/nick_matrix.c +++ b/firmware/l0dable/nick_matrix.c @@ -1,13 +1,13 @@ #include #include "basic/basic.h" +#include "basic/config.h" #include "lcd/render.h" #include "usetable.h" -#define SCREEN_WIDTH 12 +#define SCREEN_WIDTH 13 #define SCREEN_HEIGHT 8 -#define INVALID_POS 127 #define FONT_WIDTH 7 #define FONT_HEIGHT 8 @@ -16,47 +16,95 @@ #define MAX_LINE_LENGTH 6 +#define TICKS_SHOW_NICKNAME 100 +#define TICKS_HIDE_NICKNAME 50 +#define NICKNAME_ACTION_SHOW 1 +#define NICKNAME_ACTION_HIDE 2 + void ram(void){ lcdClear(); + // nickname helper variables + int nickname_len = strlen(GLOBAL(nickname)); + int nickname_posx = (SCREEN_WIDTH - nickname_len) / 2; + int nickname_posy = SCREEN_HEIGHT / 2; + + // state variables for show/hide effect + int ticks_until_next_nickname_action = TICKS_SHOW_NICKNAME; + int nickname_action = NICKNAME_ACTION_SHOW; + struct matrix_line { int head_x, head_y; int cur_length; int length; } matrix_lines[MATRIX_LINES_LENGTH]; + // initialize matrix_lines for (int i = 0; i < MATRIX_LINES_LENGTH; i++) { matrix_lines[i].cur_length = -1; } + // main loop while (1) { + // for every matrix line for(int i = 0; icur_length == -1) { ml->head_x = getRandom() % SCREEN_WIDTH; ml->head_y = getRandom() % SCREEN_HEIGHT - 1; ml->length = getRandom() % MAX_LINE_LENGTH + 3; ml->cur_length = 0; } - // new char + // set new char if (ml->head_y < SCREEN_HEIGHT-1) { ml->head_y++; - int chr = getRandom() % 95 + 33; + char chr; + int chrpos = ml->head_x - nickname_posx; + if (nickname_action == NICKNAME_ACTION_SHOW + && ml->head_y == nickname_posy + && chrpos >= 0 && chrpos < nickname_len) { + // show the nickname + chr = GLOBAL(nickname)[chrpos]; + } else { + chr = getRandom() % 95 + 33; + } DoChar(ml->head_x * FONT_WIDTH, ml->head_y * FONT_HEIGHT, chr); ml->cur_length++; } - // remove chars (when length or bottom is reached) + // remove char (when length or bottom is reached) if (ml->cur_length > ml->length || ml->head_y >= SCREEN_HEIGHT-1) { - DoChar(ml->head_x * FONT_WIDTH, (ml->head_y - ml->cur_length) * FONT_HEIGHT, ' '); + int chrpos = ml->head_x - nickname_posx; + if ( ! (nickname_action == NICKNAME_ACTION_SHOW + && (ml->head_y - ml->cur_length) == nickname_posy + && chrpos >= 0 && chrpos < nickname_len + )) { + // only delete, if it's not the nickname + DoChar(ml->head_x * FONT_WIDTH, (ml->head_y - ml->cur_length) * FONT_HEIGHT, ' '); + } ml->cur_length--; } } lcdDisplay(); - // Exit on enter+left + // show and hide nickname + ticks_until_next_nickname_action--; + if (ticks_until_next_nickname_action <= 0) { + switch (nickname_action) { + case NICKNAME_ACTION_SHOW: + nickname_action = NICKNAME_ACTION_HIDE; + ticks_until_next_nickname_action = TICKS_HIDE_NICKNAME; + break; + case NICKNAME_ACTION_HIDE: + nickname_action = NICKNAME_ACTION_SHOW; + ticks_until_next_nickname_action = TICKS_SHOW_NICKNAME; + break; + } + } + // Exit on any key int key = getInputRaw(); if(key!= BTN_NONE) return; - delayms_queue_plus(90,0); + // sleep and process queue (e. g. meshnetwork) + delayms_queue_plus(90,0); }; }; From 423df99c9a86098189b634883b2b860d5949f090 Mon Sep 17 00:00:00 2001 From: Florian Richter Date: Fri, 12 Aug 2011 15:14:48 +0200 Subject: [PATCH 11/29] nick_matrix: show nick on random locations --- firmware/l0dable/nick_matrix.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/firmware/l0dable/nick_matrix.c b/firmware/l0dable/nick_matrix.c index 8e70318..8e6837d 100644 --- a/firmware/l0dable/nick_matrix.c +++ b/firmware/l0dable/nick_matrix.c @@ -93,6 +93,9 @@ void ram(void){ case NICKNAME_ACTION_SHOW: nickname_action = NICKNAME_ACTION_HIDE; ticks_until_next_nickname_action = TICKS_HIDE_NICKNAME; + // new nickname_pos + nickname_posx = getRandom() % (SCREEN_WIDTH - nickname_len); + nickname_posy = getRandom() % SCREEN_HEIGHT; break; case NICKNAME_ACTION_HIDE: nickname_action = NICKNAME_ACTION_SHOW; From 0397197d6029693847fd6b59c2ce12a8b82c4814 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Fri, 12 Aug 2011 06:43:01 +0200 Subject: [PATCH 12/29] reenable charge led and workaround for daytrig --- firmware/applications/default.c | 24 ++++++++++++++++-------- firmware/basic/night.c | 26 +++++++++++++++----------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/firmware/applications/default.c b/firmware/applications/default.c index ea52100..b5a357c 100644 --- a/firmware/applications/default.c +++ b/firmware/applications/default.c @@ -108,16 +108,24 @@ void tick_default(void) { EVERY(50,0){ - /* if(GLOBAL(chargeled)){ - IOCON_PIO1_11 = 0x0; - gpioSetDir(RB_LED3, gpioDirection_Output); - if(GetChrgStat()) - gpioSetValue (RB_LED3, 1); - else - gpioSetValue (RB_LED3, 0); + char iodir= (GPIO_GPIO1DIR & (1 << (11) ))?1:0; + if(GetChrgStat()) { + if (iodir == gpioDirection_Input){ + IOCON_PIO1_11 = 0x0; + gpioSetDir(RB_LED3, gpioDirection_Output); + gpioSetValue (RB_LED3, 1); + LightCheck(); + } + } else { + if (iodir != gpioDirection_Input){ + gpioSetValue (RB_LED3, 0); + gpioSetDir(RB_LED3, gpioDirection_Input); + IOCON_PIO1_11 = 0x41; + LightCheck(); + } + } }; - */ if(GetVoltage()<3600){ IOCON_PIO1_11 = 0x0; diff --git a/firmware/basic/night.c b/firmware/basic/night.c index 97387d4..4a6d706 100644 --- a/firmware/basic/night.c +++ b/firmware/basic/night.c @@ -15,23 +15,27 @@ void LightCheck(void){ char iodir; iocon=IOCON_PIO1_11; -// iodir=gpioGetDir(RB_LED3); //LED3 is on pin 11 iodir= (GPIO_GPIO1DIR & (1 << (11) ))?1:0; - gpioSetDir(RB_LED3, gpioDirection_Input); - IOCON_PIO1_11 = IOCON_PIO1_11_FUNC_AD7|IOCON_PIO1_11_ADMODE_ANALOG; - light-=light/SAMPCT; - light += (adcRead(7)/2); - - gpioSetDir(RB_LED3, iodir); - IOCON_PIO1_11=iocon; + //gpioSetDir(RB_LED3, gpioDirection_Input); + if (iodir == gpioDirection_Input) { + IOCON_PIO1_11 = IOCON_PIO1_11_FUNC_AD7|IOCON_PIO1_11_ADMODE_ANALOG; + light-=light/SAMPCT; + light += (adcRead(7)/2); - if(_isnight && light/SAMPCT>(threshold+RANGE)) - _isnight=0; + gpioSetDir(RB_LED3, iodir); + IOCON_PIO1_11=iocon; - if(!_isnight && light/SAMPCT(threshold+RANGE)) + _isnight=0; + + if(!_isnight && light/SAMPCT Date: Fri, 12 Aug 2011 14:49:38 +0200 Subject: [PATCH 13/29] ignore release dir --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2de545f..4f6b597 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.o *.a *.swp +release From 51a1b20f3eaa443d69d1ebc0ef305672d6b28b0e Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Fri, 12 Aug 2011 14:51:10 +0200 Subject: [PATCH 14/29] Reenable chargeled config option --- firmware/basic/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/basic/config.c b/firmware/basic/config.c index 6ae9cdc..e0eba99 100644 --- a/firmware/basic/config.c +++ b/firmware/basic/config.c @@ -28,7 +28,7 @@ struct CDESC the_config[]= { {"flamemaxw", 255, 1, 255, 1, CFG_TYPE_FLAME}, {"flameminw", 0x8f, 1, 255, 1, CFG_TYPE_FLAME}, {"l0nick", 0, 0, 1 , 0, 0}, - {"chargeled", 0, 0, 1 , 0, CFG_TYPE_GONE}, + {"chargeled", 0, 0, 1 , 0, 0}, {"positionleds", 0, 0, 1 , 0, 0}, { NULL, 0, 0, 0 , 0, 0}, }; From ea4f163658ae74e94e272a1329a33b7f9b18d0be Mon Sep 17 00:00:00 2001 From: the_nihilant Date: Fri, 12 Aug 2011 15:33:12 +0200 Subject: [PATCH 15/29] add basic Nokia 1600 color display support --- firmware/lcd/display.c | 119 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 115 insertions(+), 4 deletions(-) diff --git a/firmware/lcd/display.c b/firmware/lcd/display.c index 40bd2ae..7f45319 100644 --- a/firmware/lcd/display.c +++ b/firmware/lcd/display.c @@ -9,6 +9,9 @@ #include "basic/config.h" #include "usb/usbmsc.h" + +#define N1600 + /**************************************************************************/ /* Utility routines to manage nokia display */ /**************************************************************************/ @@ -143,7 +146,7 @@ void lcdInit(void) { * 0xd0+x black lines from top? (-0xdf?) * */ - +#ifndef N1600 lcdWrite(TYPE_CMD,0xE2); delayms(5); lcdWrite(TYPE_CMD,0xAF); // Display ON @@ -152,12 +155,53 @@ void lcdInit(void) { lcdWrite(TYPE_CMD,0x2F); lcdWrite(TYPE_CMD,0xB0); lcdWrite(TYPE_CMD,0x10); - lcdWrite(TYPE_CMD,0x00); + // lcdWrite(TYPE_CMD,0x00); +#else + delayms(10); + lcdWrite(TYPE_CMD,0x01); //sw reset + delayms(10); + lcdWrite(TYPE_CMD,0x11); //sleepout + delayms(10); + + lcdWrite(TYPE_CMD,0x36); //MADCTL MY MX V LAO RGB X X X + lcdWrite(TYPE_DATA,0x00); + lcdWrite(TYPE_CMD,0x25); // contrast... + lcdWrite(TYPE_DATA,0x3F); + delayms(10); + + lcdWrite(TYPE_CMD,0x29); //display on + + lcdWrite(TYPE_CMD,0xBA); //data order + lcdWrite(TYPE_DATA,0x07); + lcdWrite(TYPE_DATA,0x15); + + lcdWrite(TYPE_CMD,0x25); //contrast... again? + lcdWrite(TYPE_DATA,0x3f); + + lcdWrite(TYPE_CMD,0x11); //Sleepout + lcdWrite(TYPE_CMD,0x13); //display mode normal + + lcdWrite(TYPE_CMD,0X37); //vscroll addr + lcdWrite(TYPE_DATA,0x00); + + lcdWrite(TYPE_CMD,0x3A); // COLMOD pixel format 4=12, 5=16, 6=18 + lcdWrite(TYPE_DATA,0x05); + + lcdWrite(TYPE_CMD,0x2A); //no clue... I think it's setting up the size of the display? + lcdWrite(TYPE_DATA,0); + lcdWrite(TYPE_DATA,98-1); //98 = width + + lcdWrite(TYPE_CMD,0x2B); + lcdWrite(TYPE_DATA,0); + lcdWrite(TYPE_DATA,70-1); //70 = height + +#endif + /* uint16_t i; for(i=0; i<100; i++) lcdWrite(TYPE_DATA,0x00); - + */ lcd_deselect(); } @@ -194,13 +238,25 @@ bool lcdGetPixel(char x, char y){ return byte & (1 << y_off); } +#define THECOLOR_R 0x0 +#define THECOLOR_G 0x80 +#define THECOLOR_B 0x0 + void lcdDisplay(void) { char byte; lcd_select(); +#ifndef N1600 lcdWrite(TYPE_CMD,0xB0); lcdWrite(TYPE_CMD,0x10); lcdWrite(TYPE_CMD,0x00); +#else + lcdWrite(TYPE_CMD,0x2C); + +#endif + + +#ifndef N1600 uint16_t i,page; for(page=0; page> 3); + framecolor= ((frame_r&0xF8) << 8) | ((frame_g&0xFC)<<3) | ((frame_b&0xF8) >> 3); + backcolor= ((br&0xF8) << 8) | ((bg&0xFC)<<3) | ((bb&0xF8) >> 3); + + //top line of the frame... + for(i=0;i<98;i++){ + lcdWrite(TYPE_DATA,framecolor>>8); + lcdWrite(TYPE_DATA,framecolor&0xFF); + } + + for(y=RESY;y>0;y--){ + //left line of the frame + lcdWrite(TYPE_DATA,framecolor>>8); + lcdWrite(TYPE_DATA,framecolor&0xFF); + + for(x=RESX;x>0;x--){ + if(GLOBAL(lcdmirror)) + px=lcdGetPixel(RESX-x+1,y-1); + else + px=lcdGetPixel(x-1,y-1); + + if((!px)^(!GLOBAL(lcdinvert))) actualcolor=color; + else actualcolor=backcolor; /* white */ + + lcdWrite(TYPE_DATA,actualcolor>>8); + lcdWrite(TYPE_DATA,actualcolor&0xFF); + } + //right line of the frame + lcdWrite(TYPE_DATA,framecolor>>8); + lcdWrite(TYPE_DATA,framecolor&0xFF); + } + + //bottom line of the frame + for(i=0;i<98;i++){ + lcdWrite(TYPE_DATA,framecolor>>8); + lcdWrite(TYPE_DATA,framecolor&0xFF); + } +#endif lcd_deselect(); } @@ -225,12 +327,21 @@ inline void lcdInvert(void) { } void lcdSetContrast(int c) { + #ifndef N1600 c+=0x80; if(c>0x9F) return; lcd_select(); lcdWrite(TYPE_CMD,c); lcd_deselect(); + #else + if(c>=0x40) + return; + lcd_select(); + lcdWrite(TYPE_CMD,0x25); + lcdWrite(TYPE_DATA,4*c); + lcd_deselect(); + #endif }; void lcdSetInvert(int c) { From dbc8bb287a5c159dbf52f4e803a7274d3d660a21 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Fri, 12 Aug 2011 15:58:19 +0200 Subject: [PATCH 16/29] Change default back to default display --- firmware/lcd/display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/lcd/display.c b/firmware/lcd/display.c index 7f45319..38b280b 100644 --- a/firmware/lcd/display.c +++ b/firmware/lcd/display.c @@ -10,7 +10,7 @@ #include "usb/usbmsc.h" -#define N1600 +#undef N1600 /**************************************************************************/ /* Utility routines to manage nokia display */ From de110ea5be432feb3db300ec6c26783a93e74ba6 Mon Sep 17 00:00:00 2001 From: Rainer Mueller Date: Sat, 6 Aug 2011 21:42:17 +0200 Subject: [PATCH 17/29] Fix update-bridge-files.sh for BSD find BSD find outputs a trailing slash when given on the command line, GNU find does not. This can lead to path like firmware//lcd/image.c which would fail with the used dirname and sed combination. --- simulat0r/bin/update-bridge-files.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/simulat0r/bin/update-bridge-files.sh b/simulat0r/bin/update-bridge-files.sh index 441bc53..d85524e 100755 --- a/simulat0r/bin/update-bridge-files.sh +++ b/simulat0r/bin/update-bridge-files.sh @@ -13,7 +13,7 @@ exit fi echo "Updating directories" -for i in `find firmware/ -type d ` +for i in `find firmware -type d ` do if test -d simulat0r/$i then verbmsg "OK Directory already exists: $i" @@ -22,7 +22,7 @@ fi done echo "Updating bridge files for C source" -for i in `find firmware/ \! -path firmware/lcd/allfonts.h \! -path firmware/l0dable/usetable.h -type f -iname \*.[ch]` +for i in `find firmware \! -path firmware/lcd/allfonts.h \! -path firmware/l0dable/usetable.h -type f -iname \*.[ch]` do if test -f simulat0r/$i; then @@ -34,7 +34,7 @@ do done echo "Updating bridge files for Makefiles" -for i in `find firmware/ -type f -iname Makefile` +for i in `find firmware -type f -iname Makefile` do if test -f simulat0r/$i; then From f9982c226f3bc85248847ea0c156f964a13ee3fa Mon Sep 17 00:00:00 2001 From: Rainer Mueller Date: Sun, 31 Jul 2011 21:49:02 +0200 Subject: [PATCH 18/29] Avoid duplicate symbols in usbhid.o and usbmsc.o --- firmware/usb/usbhid.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firmware/usb/usbhid.c b/firmware/usb/usbhid.c index 5072b0b..4f7975d 100644 --- a/firmware/usb/usbhid.c +++ b/firmware/usb/usbhid.c @@ -44,9 +44,9 @@ #include "usbconfig.h" #include "usbhid.h" -USB_DEV_INFO DeviceInfo; -HID_DEVICE_INFO HidDevInfo; -ROM ** rom = (ROM **)0x1fff1ff8; +static USB_DEV_INFO DeviceInfo; +static HID_DEVICE_INFO HidDevInfo; +static ROM ** rom = (ROM **)0x1fff1ff8; typedef struct usbhid_out_s { From 083fd79adc4c72906e2ee080da7236cad1747cbe Mon Sep 17 00:00:00 2001 From: Rainer Mueller Date: Sun, 31 Jul 2011 21:44:50 +0200 Subject: [PATCH 19/29] Remove duplicated libbasic --- simulat0r/tui/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/simulat0r/tui/Makefile b/simulat0r/tui/Makefile index a74e2f7..84a2447 100644 --- a/simulat0r/tui/Makefile +++ b/simulat0r/tui/Makefile @@ -6,7 +6,6 @@ CFLAGS += -I../firmware CFLAGS += -I../firmware/core # for gpio.h including projectconfig.h without path CFLAGS += -I../simcore -OBJS+= ../firmware/basic/*.o OBJS+= ../firmware/core/*.o OBJS+= ../firmware/core/*/*.o LIBS+= ../firmware/applications/libapp.a From 8af2fb3f08455b8a2237339d716b00a6dbfa716d Mon Sep 17 00:00:00 2001 From: Rainer Mueller Date: Tue, 2 Aug 2011 06:29:14 +0200 Subject: [PATCH 20/29] Use $(CC) for linking --- simulat0r/tui/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/simulat0r/tui/Makefile b/simulat0r/tui/Makefile index 84a2447..a81d347 100644 --- a/simulat0r/tui/Makefile +++ b/simulat0r/tui/Makefile @@ -31,7 +31,6 @@ OBJS += simulat0r.o all : simulat0r simulat0r : $(OBJS) $(LIBS) - $(LD) $(OBJS) $(LIBS) -lc -o $@ clean: $(RM) simulat0r.o From 35b92adcfc16c13b15b0a778964c118bda45b89b Mon Sep 17 00:00:00 2001 From: Rainer Mueller Date: Fri, 5 Aug 2011 14:23:27 +0200 Subject: [PATCH 21/29] No section attribute on Mac OS X This attribute isn't compatible with Mach-O, so avoid this when building simulat0r on Mac OS X. --- firmware/l0dable/mktable.pl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/firmware/l0dable/mktable.pl b/firmware/l0dable/mktable.pl index ad54420..254ca2c 100755 --- a/firmware/l0dable/mktable.pl +++ b/firmware/l0dable/mktable.pl @@ -77,7 +77,12 @@ sub wanted { File::Find::find({wanted => \&wanted}, '.'); print C ""; -print C qq!__attribute__ ((used, section("table"))) const void * TheTable[]={!; +print C < Date: Fri, 5 Aug 2011 14:45:20 +0200 Subject: [PATCH 22/29] Weak aliasing is not supported with Mach-O This fixes the simulator for Mac OS X. --- simulat0r/firmware/lcd/display.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/simulat0r/firmware/lcd/display.c b/simulat0r/firmware/lcd/display.c index de1d975..90fce64 100644 --- a/simulat0r/firmware/lcd/display.c +++ b/simulat0r/firmware/lcd/display.c @@ -1,8 +1,14 @@ +#ifdef __APPLE__ +#define lcdRefresh _hideaway_lcdRefresh +#endif #define lcdDisplay _hideaway_lcdDisplay #define lcdInit _hideaway_lcdInit #include "../../../firmware/lcd/display.c" #undef lcdDisplay #undef lcdInit +#ifdef __APPLE__ +#undef lcdRefresh +#endif #include "simulator.h" @@ -10,5 +16,11 @@ void lcdDisplay() { simlcdDisplayUpdate(); } +#ifdef __APPLE__ +void lcdRefresh() { + lcdDisplay(); +} +#endif + void lcdInit() { } From 384a72af8159bff996de3b4405ed7743931a2484 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Fri, 12 Aug 2011 19:18:48 +0200 Subject: [PATCH 23/29] Make debug more usable, also omit CRC from packets --- firmware/l0dable/debug.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/firmware/l0dable/debug.c b/firmware/l0dable/debug.c index 2603037..b57a296 100644 --- a/firmware/l0dable/debug.c +++ b/firmware/l0dable/debug.c @@ -168,7 +168,7 @@ void getsp(void) { void m_time_details(int select) { getInputWaitRelease(); - while(getInputWaitTimeout(50) != BTN_LEFT){ + while(getInputWaitTimeout(50) == BTN_NONE){ lcdClear(); MPKT *mpkt = &meshbuffer[select]; uint8_t *pkt = mpkt->pkt; @@ -193,7 +193,7 @@ void m_time_details(int select) { lcdNl(); int x = 0; - for(uint8_t *body = MO_BODY(pkt); body < pkt + 32; body++) { + for(uint8_t *body = MO_BODY(pkt); body < (pkt + 30); body++) { if (*body >= ' ' && *body < 128) { if (x > 12) { lcdNl(); @@ -276,23 +276,23 @@ void m_time(void){ lcdNl(); lcdRefresh(); - uint8_t key = getInputWaitTimeout(50); + uint8_t key = getInputWaitTimeout(100); switch(key) { - case BTN_UP: + case BTN_LEFT: select--; if (select < 0) select = MESHBUFSIZE - 1; break; - case BTN_DOWN: + case BTN_RIGHT: select++; if (select >= MESHBUFSIZE) select = 0; break; - case BTN_RIGHT: case BTN_ENTER: m_time_details(select); break; - case BTN_LEFT: + case BTN_UP: + case BTN_DOWN: // Exit return; } From 51f79dbd548ad89ff27fb3679f80c146d98dfa65 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Fri, 12 Aug 2011 19:19:38 +0200 Subject: [PATCH 24/29] Fix compile on Debian Squeeze PowerPC thanks to phil --- tools/bootloader/lpcfix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bootloader/lpcfix.c b/tools/bootloader/lpcfix.c index 12a585e..cdc29c2 100644 --- a/tools/bootloader/lpcfix.c +++ b/tools/bootloader/lpcfix.c @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) { } /* The big getopt loop */ - while ((c = getopt(argc, argv, "vcp:nh")) != EOF) + while ((c = getopt(argc, argv, "vcp:nh")) != (char)EOF) switch (c) { case 'c': do_crc = 1; From 426972d291e8eaed9bbd328baf7b01b9e218b79f Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Fri, 12 Aug 2011 20:07:09 +0200 Subject: [PATCH 25/29] Add nick_time animation from SvOlli --- firmware/l0dable/nick_time.c | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 firmware/l0dable/nick_time.c diff --git a/firmware/l0dable/nick_time.c b/firmware/l0dable/nick_time.c new file mode 100755 index 0000000..8f393a5 --- /dev/null +++ b/firmware/l0dable/nick_time.c @@ -0,0 +1,58 @@ +#include + +#include "basic/basic.h" +#include "basic/config.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" + +#include "usetable.h" + +void ram(void) +{ + struct tm* tm; + char timestr[9]="00:00:00"; + int dx1=0; + int dx2=0; + int dy1=0; + int dy2=0; + setExtFont(GLOBAL(nickfont)); + + dx1=DoString(0,0,GLOBAL(nickname)); + dx1=(RESX-dx1)/2; + if(dx1<0) + { + dx1=0; + } + dy1=(RESY/2-getFontHeight())/2; + dy2=RESY/2 + dy1; + while(getInputRaw()==BTN_NONE) + { + tm = mygmtime(getSeconds()); + + timestr[0] = '0' + tm->tm_hour / 10; + timestr[1] = '0' + tm->tm_hour % 10; + + timestr[3] = '0' + tm->tm_min / 10; + timestr[4] = '0' + tm->tm_min % 10; + + timestr[6] = '0' + tm->tm_sec / 10; + timestr[7] = '0' + tm->tm_sec % 10; + + dx2=DoString(0,0,×tr[0]); + dx2=(RESX-dx2)/2; + if(dx2<0) + { + dx2=0; + } + + lcdClear(); + + DoString(dx1,dy1,GLOBAL(nickname)); + DoString(dx2,dy2,×tr[0]); + + lcdRefresh(); + delayms_queue_plus(10,0); + } + return; +} From d8d056e5ef0136ee0425a6aa03f710ce99fa3da9 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Fri, 12 Aug 2011 20:13:19 +0200 Subject: [PATCH 26/29] Add simple static screen based on idea by SvOlli --- firmware/l0dable/static.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 firmware/l0dable/static.c diff --git a/firmware/l0dable/static.c b/firmware/l0dable/static.c new file mode 100755 index 0000000..c1610c3 --- /dev/null +++ b/firmware/l0dable/static.c @@ -0,0 +1,33 @@ +#include +#include + +#include "basic/basic.h" +#include "basic/config.h" +#include "basic/random.h" + +#include "lcd/render.h" +#include "lcd/display.h" + +#include "lcd/fonts.h" +#include "lcd/fonts/invaders.h" + +#include "funk/mesh.h" + +#include "usetable.h" + + +void ram(void) +{ + int x, y; + + while( getInputRaw() == BTN_NONE ) { + for( x = 0; x < RESX; x++ ) { + for( y = 0; y < RESY_B; y++ ) { + lcdBuffer[y*RESX+x]=getRandom()&0xff; + } + } + lcdDisplay(); + } + return; +} + From 39efe08dabc547f6f1929641c21c40029313757c Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Fri, 12 Aug 2011 20:17:11 +0200 Subject: [PATCH 27/29] Add starfield loadable --- firmware/l0dable/starfld.c | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 firmware/l0dable/starfld.c diff --git a/firmware/l0dable/starfld.c b/firmware/l0dable/starfld.c new file mode 100644 index 0000000..1a41eef --- /dev/null +++ b/firmware/l0dable/starfld.c @@ -0,0 +1,73 @@ +#include + +#include "basic/basic.h" +#include "basic/config.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" + +#include "usetable.h" + +#define NUM_STARS 150 + +typedef struct { + short x, y, z, speed; +} s_star; + +static s_star stars[NUM_STARS]; + +void init_star(s_star *star, int z); + +void ram(void) +{ + short centerx = RESX >> 1; + short centery = RESY >> 1; + short i; + + for (i = 0; i < NUM_STARS; i++) { + init_star(stars + i, i + 1); + } + + while(getInputRaw()==BTN_NONE){ + lcdClear(); + + for (i = 0; i < NUM_STARS; i++) { + stars[i].z -= stars[i].speed; + + if (stars[i].z <= 0) + init_star(stars + i, i + 1); + + short tempx = ((stars[i].x * 30) / stars[i].z) + centerx; + short tempy = ((stars[i].y * 30) / stars[i].z) + centery; + + if (tempx < 0 || tempx > RESX - 1 || tempy < 0 || tempy > RESY - 1) { + init_star(stars + i, i + 1); + continue; + } + + lcdSetPixel(tempx, tempy, 1); + if (stars[i].z < 50) { + lcdSetPixel(tempx + 1, tempy, 1); + } + if (stars[i].z < 20) { + lcdSetPixel(tempx, tempy + 1, 1); + lcdSetPixel(tempx + 1, tempy + 1, 1); + } + } + + lcdRefresh(); + + delayms_queue_plus(50,0); + } +} + +void init_star(s_star *star, int z) +{ + star->x = (getRandom() % RESX) - (RESX >> 1); + star->y = (getRandom() % RESY) - (RESY >> 1); + star->z = z; + star->speed = (getRandom() % 4) + 1; + + return; +} + From 4ec0525b3a23068eff97b39bc689c5dc4f08d242 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Fri, 12 Aug 2011 20:24:56 +0200 Subject: [PATCH 28/29] Fix ifdef check to be more correct --- firmware/l0dable/mktable.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/l0dable/mktable.pl b/firmware/l0dable/mktable.pl index 254ca2c..cceebe7 100755 --- a/firmware/l0dable/mktable.pl +++ b/firmware/l0dable/mktable.pl @@ -78,9 +78,9 @@ File::Find::find({wanted => \&wanted}, '.'); print C ""; print C < Date: Fri, 12 Aug 2011 20:25:27 +0200 Subject: [PATCH 29/29] Make simulat0r build work again --- firmware/l0dable/nick_life.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/firmware/l0dable/nick_life.c b/firmware/l0dable/nick_life.c index 4faed8f..818c232 100644 --- a/firmware/l0dable/nick_life.c +++ b/firmware/l0dable/nick_life.c @@ -256,10 +256,6 @@ static void reset_area() { } } -#ifdef SIMULATOR -extern uint32_t getRandom(void); -#endif - static void random_area(struct bitset *area, uchar x0, uchar y0, uchar x1, uchar y1,uchar value) { for(uchar x=x0; x<=x1; ++x) { for(uchar y=y0; y<=y1; ++y) {