Merge branch 'master' of github.com:r0ket/r0ket

This commit is contained in:
bsx 2011-12-23 09:41:48 +01:00
commit 8002095eb4
25 changed files with 631 additions and 78 deletions

View File

@ -42,7 +42,7 @@ CPU_TYPE = cortex-$(CORTEX_TYPE)
# Compiler settings, parameters and flags
##########################################################################
CFLAGS = -std=c99 -c -g -Os $(INCLUDE_PATHS) -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -DTARGET=$(TARGET) -DRAMCODE=$(RAMCODE) -fno-builtin
CFLAGS = -std=c99 -c -g -Os $(INCLUDE_PATHS) -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -DTARGET=$(TARGET) -DRAMCODE=$(RAMCODE) -fno-builtin -Wno-unused-function
LDFLAGS = -nostartfiles

View File

@ -19,8 +19,10 @@ void init_nick();
void fancyNickname();
void main_final(void) {
init_nick();
if(GLOBAL(privacy)>2){ //firstboot
execute_file("initanim.int");
if(execute_file("1boot.int")){
lcdPrintln("Badge SETUP");
lcdPrintln("error.");

View File

@ -8,6 +8,7 @@
#include "lcd/display.h"
#include "filesystem/ff.h"
#include "filesystem/execute.h"
#include <string.h>

View File

@ -124,7 +124,7 @@ void init_flame(void) {
flameInit(flamesEnabled);
rgbDataSize = readTextFile("FLAME.RGB", rgbData, 24);
rgbDataSize = readTextFile("FLAME.RGB", (char *)rgbData, 24);
enableConfig(CFG_TYPE_FLAME,1);
}

View File

@ -120,6 +120,7 @@ char *meshmsgs(void){
return msgtypes;
};
#if 0
static inline uint32_t popcount(uint32_t *buf, uint8_t n){
int cnt=0;
do {
@ -133,6 +134,7 @@ static inline uint32_t popcount(uint32_t *buf, uint8_t n){
} while(--n);
return cnt;
}
#endif
extern MPKT meshbuffer[MESHBUFSIZE];
//# MENU messages
@ -156,10 +158,13 @@ void m_choose(){
strcpy(p,"Message");
break;
case('E'):
strcpy(p,"Kourou");
strcpy(p,"Saal 1");
break;
case('F'):
strcpy(p,"Baikonur");
strcpy(p,"Saal 2");
break;
case('G'):
strcpy(p,"Saal 3");
break;
case('T'):
strcpy(p,"Time");
@ -167,12 +172,14 @@ void m_choose(){
case('i'):
strcpy(p,"Invaders");
break;
#if 0
case('j'):
strcpy(p,"Jump");
break;
case('r'):
strcpy(p,"r0type");
break;
#endif
default:
p[0]=*mm;
p[1]=0;
@ -198,10 +205,13 @@ void m_choose(){
lcdPrintln("Message");
break;
case('E'):
lcdPrintln("Kourou");
lcdPrintln("Saal 1");
break;
case('F'):
lcdPrintln("Baikonur");
lcdPrintln("Saal 2");
break;
case('G'):
lcdPrintln("Saal 3");
break;
case('T'):
lcdPrintln("Time");
@ -209,12 +219,14 @@ void m_choose(){
case('i'):
lcdPrintln("Invaders");
break;
#if 0
case('j'):
strcpy(p,"Jump");
break;
case('r'):
strcpy(p,"r0type");
break;
#endif
};
if(tmm[i]>='a' && tmm[i]<='z'){
lcdPrintln(IntToStr(MO_TIME(meshbuffer[j].pkt),10,0));
@ -227,6 +239,7 @@ void m_choose(){
lcdPrint(IntToStr(tm->tm_sec,2,F_LONG|F_ZEROS));
lcdNl();
#if 0
if(tmm[i]=='Z'){
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[j].pkt+ 6),8));
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[j].pkt+10),8));
@ -239,7 +252,9 @@ void m_choose(){
lcdRefresh();
getInputWaitRelease();
continue;
}else if(tmm[i]=='T'){
}else
#endif
if(tmm[i]=='T'){
lcdPrint(IntToStr(tm->tm_mday,2,F_LONG));
lcdPrint(".");
lcdPrint(IntToStr(tm->tm_mon+1,2,0));

View File

@ -145,9 +145,7 @@ static int process(char * input){
return -1;
puts_plus("\r\n");
puts_plus("D [");
puts_plus(input);
puts("]\r\n");
// puts_plus("D ["); puts_plus(input); puts("]\r\n");
if(input[0]=='i'){
nrf_init();
@ -161,8 +159,8 @@ static int process(char * input){
config.maclen[0]=0x20;
config.nrmacs=1;
nrf_config_set(&config);
memcpy(thekey,meshkey,sizeof(thekey));
funkencrypt=1;
// memcpy(thekey,meshkey,sizeof(thekey));
funkencrypt=0;
}else if(input[1]=='M'){
config.channel=83;
memcpy(config.txmac,MESH_MAC,5);
@ -170,11 +168,11 @@ static int process(char * input){
config.maclen[0]=0x20;
config.nrmacs=1;
nrf_config_set(&config);
static const uint32_t const pubmesh[4] = {
0x00000042, 0x000005ec, 0x00000023, 0x00000005
};
memcpy(thekey,pubmesh,sizeof(thekey));
funkencrypt=1;
// static const uint32_t const pubmesh[4] = {
// 0x00000042, 0x000005ec, 0x00000023, 0x00000005
// };
// memcpy(thekey,pubmesh,sizeof(thekey));
funkencrypt=0;
}else if(input[1]=='r'){
config.channel=REMOTE_CHANNEL;
memcpy(config.txmac,REMOTE_MAC,5);
@ -182,8 +180,8 @@ static int process(char * input){
config.maclen[0]=0x10;
config.nrmacs=1;
nrf_config_set(&config);
memcpy(thekey,remotekey,sizeof(thekey));
funkencrypt=1;
// memcpy(thekey,remotekey,sizeof(thekey));
funkencrypt=0;
}else if(input[1]=='b'){
config.channel=BEACON_CHANNEL;
memcpy(config.txmac,BEACON_MAC,5);
@ -191,8 +189,8 @@ static int process(char * input){
config.maclen[0]=0x10;
config.nrmacs=1;
nrf_config_set(&config);
memcpy(thekey,openbeaconkey,sizeof(thekey));
funkencrypt=1;
// memcpy(thekey,openbeaconkey,sizeof(thekey));
funkencrypt=0;
}else if(input[1]=='B'){
config.channel=BEACON_CHANNEL;
memcpy(config.txmac,BEACON_MAC,5);
@ -200,11 +198,11 @@ static int process(char * input){
config.maclen[0]=0x10;
config.nrmacs=1;
nrf_config_set(&config);
static const uint32_t pubbeaconkey[4] = {
0xB4595344, 0xD3E119B6, 0xA814D0EC, 0xEFF5A24E
};
memcpy(thekey,pubbeaconkey,sizeof(thekey));
funkencrypt=1;
// static const uint32_t pubbeaconkey[4] = {
// 0xB4595344, 0xD3E119B6, 0xA814D0EC, 0xEFF5A24E
// };
// memcpy(thekey,pubbeaconkey,sizeof(thekey));
funkencrypt=0;
};
}else if(input[0]=='t'){
type=input[1];

View File

@ -3,6 +3,7 @@
#include "lcd/display.h"
#include "lcd/print.h"
#include "lcd/backlight.h"
#include "filesystem/ff.h"
#include "basic/random.h"
#include "basic/config.h"

View File

@ -89,7 +89,7 @@ uint8_t execute_file (const char * fname){
/**************************************************************************/
void executeSelect(char *ext){
void executeSelect(const char *ext){
char filename[15];
filename[0]='0';
filename[1]=':';

View File

@ -2,6 +2,6 @@
#define _EXECUTE_H_
uint8_t execute_file (const char * fname);
void executeSelect(char *ext);
void executeSelect(const char *ext);
#endif

View File

@ -8,7 +8,7 @@
#define FLEN 13
int getFiles(char files[][FLEN], uint8_t count, uint16_t skip, char *ext)
int getFiles(char files[][FLEN], uint8_t count, uint16_t skip, const char *ext)
{
DIR dir; /* Directory object */
FILINFO Finfo;
@ -45,7 +45,7 @@ int getFiles(char files[][FLEN], uint8_t count, uint16_t skip, char *ext)
}
#define PERPAGE 7
int selectFile(char *filename, char *extension)
int selectFile(char *filename, const char *extension)
{
int skip = 0;
char key;

View File

@ -4,7 +4,7 @@
#define FLEN 13
int getFiles(char files[][FLEN], uint8_t count, uint16_t skip, char *ext);
int selectFile(char *filename, char *extension);
int getFiles(char files[][FLEN], uint8_t count, uint16_t skip, const char *ext);
int selectFile(char *filename, const char *extension);
#endif

View File

@ -1,5 +1,9 @@
#include <sysdefs.h>
#include <ff.h>
#include <string.h>
#include "at45db041d.h"
#include "lcd/print.h"
#include "usb/usbmsc.h"
FATFS FatFs; /* File system object for logical drive */
@ -29,13 +33,12 @@ const uint8_t init2[] = {0x80, 0x00, 0x29, 0x37,
0x4d, 0x45, 0x20, 0x20, 0x20, 0x20, 0x46, 0x41,
0x54, 0x20, 0x20, 0x20, 0x20, 0x20};
inline void format_formatDF(void)
{
inline void format_formatDF(void) {
int i;
char buf[512];
BYTE buf[512];
memset(buf, 0, 512);
for(i=0; i<20; i++) dataflash_write(buf, i, 1);
for(i=0; i<100; i++) dataflash_write(buf, i, 1);
memcpy(buf, init1, sizeof(init1));
memcpy(buf+0x24, init2, sizeof(init2));

View File

@ -31,9 +31,9 @@ void initMesh(void){
int mesh_sanity(uint8_t * pkt){
if(MO_TYPE(pkt)>='A' && MO_TYPE(pkt)<='Z'){
if(MO_TIME(pkt)>1313803870)
if(MO_TIME(pkt)>1325379600)
return 1;
if(MO_TIME(pkt)<1312075898)
if(MO_TIME(pkt)<1324602000)
return 1;
}else if(MO_TYPE(pkt)>='a' && MO_TYPE(pkt)<='z'){
if(MO_TIME(pkt)>16777216)
@ -41,7 +41,12 @@ int mesh_sanity(uint8_t * pkt){
if(MO_TIME(pkt)<0)
return 1;
};
if(MO_TYPE(pkt)=='t'){
if(MO_TYPE(pkt)!='E' &&
MO_TYPE(pkt)!='F' &&
MO_TYPE(pkt)!='G' &&
MO_TYPE(pkt)!='T' &&
1
){
return 1;
};
if(MO_TYPE(pkt)>0x7f || MO_TYPE(pkt)<0x20)
@ -92,7 +97,7 @@ void mesh_cleanup(void){
};
if(mesh_sanity(meshbuffer[i].pkt)){
meshbuffer[i].flags=MF_FREE;
#if 1
#if 0
setSystemFont();
lcdClear();
lcdPrintln("MESH PANIC!");

View File

@ -1,10 +1,13 @@
#include <stdint.h>
#include <string.h>
#include "funk/openbeacon.h"
#include "funk/nrf24l01p.h"
#include "basic/byteorder.h"
#include "sysdefs.h"
#include "filesystem/ff.h"
#include "basic/uuid.h"
#include "basic/config.h"
#include "basic/random.h"
#include "SECRETS"
@ -77,17 +80,25 @@ void openbeaconSetup(void)
#endif
}
static uint8_t openbeaconSendPacket(uint32_t id, uint32_t seq,
static void openbeaconSendPacket(uint32_t id, uint32_t seq,
uint8_t flags, uint8_t strength)
{
uint8_t buf[32];
uint8_t buf[16];
uint8_t proto = 0x17; //Tracking
volatile uint16_t i;
i = getRandom()&0xfff;
i = (getRandom()&0xfff)+1;
while(i--);
static uint32_t n = 123;
if( --n == 0 ){
n = 123;
proto = 0x23; //Nick name
}
buf[0]=0x10; // Length: 16 bytes
buf[1]=0x17; // Proto - fixed at 0x17?
buf[1]=proto;
if( proto == 0x17 ){
buf[2]=flags;
buf[3]=strength*85; // Send intensity
@ -96,12 +107,32 @@ static uint8_t openbeaconSendPacket(uint32_t id, uint32_t seq,
buf[12]=0xff; // salt (0xffff always?)
buf[13]=0xff;
#if ENCRYPT_OPENBEACON
return nrf_snd_pkt_crc_encr(16,buf,openbeaconkey);
nrf_snd_pkt_crc_encr(16,buf,openbeaconkey);
#else
return nrf_snd_pkt_crc_encr(16,buf,NULL);
nrf_snd_pkt_crc_encr(16,buf,NULL);
#endif
}else{
if( strlen(GLOBAL(nickname)) > 8 )
buf[1] = 0x24;
nrf_set_strength(3);
uint32touint8p(id, buf+2);
memcpy(buf+6, GLOBAL(nickname), 8);
#if ENCRYPT_OPENBEACON
nrf_snd_pkt_crc_encr(16,buf,openbeaconkey);
#else
nrf_snd_pkt_crc_encr(16,buf,NULL);
#endif
if( strlen(GLOBAL(nickname)) < 9 )
return;
buf[1]=0x25;
memcpy(buf+6, GLOBAL(nickname)+8, 8);
#if ENCRYPT_OPENBEACON
nrf_snd_pkt_crc_encr(16,buf,openbeaconkey);
#else
nrf_snd_pkt_crc_encr(16,buf,NULL);
#endif
}
}
void openbeaconSend(void)

View File

@ -104,18 +104,6 @@ nickname
systickGetTicks
uint32touint8p
uint8ptouint32
#Add stuff here
#o_init
#o_path_new
#o_move_to
#o_line_to
#o_curve_to
#o_close
#o_set_gray
#o_fill
#o_set_shader
#o_identity
#o_transform
#I2C
I2CMasterBuffer
I2CSlaveBuffer
@ -123,6 +111,7 @@ I2CWriteLength
I2CReadLength
i2cEngine
i2cInit
#stuff
timer32Callback0
lcdRead
lcdInit
@ -136,4 +125,15 @@ flameSetBrightness
flameSetColor
flameClaim
flameFree
o_init
o_path_new
o_move_to
o_line_to
o_curve_to
o_close
o_set_gray
o_fill
o_set_shader
o_identity
o_transform
#Add stuff here

View File

@ -31,7 +31,7 @@ CRYPTFLAGS=-p
skey=`cd .. && ./getkey.pl l0dable_sign`
ekey=`cd .. && ./getkey.pl l0dable_crypt`
all: $(OBJS) $(ELFS) $(BINS) $(CODS) $(NIKS) 1boot.int debug.int config.int
all: $(OBJS) $(ELFS) $(BINS) $(CODS) $(NIKS) 1boot.int debug.int config.int initanim.int
$(LDFILE):
-@echo "MEMORY" > $(LDFILE)
@ -71,6 +71,9 @@ debug.int: debug.c0d .PHONY
config.int: config.c0d .PHONY
mv $< $@
initanim.int: initanim.c0d .PHONY
mv $< $@
clean:
rm -f *.o *.elf *.bin usetable.h

View File

@ -0,0 +1,22 @@
#include <sysinit.h>
#include <string.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "lcd/render.h"
#include "lcd/print.h"
#include "funk/nrf24l01p.h"
#include "usetable.h"
/**************************************************************************/
void ram(void) {
lcdClear();
lcdPrintln("OpenBeaconId:");
lcdPrintIntHex(GetUUID32());
lcdRefresh();
do{
}while ((getInputRaw())==BTN_NONE);
}

126
firmware/l0dable/config.c Normal file
View File

@ -0,0 +1,126 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "lcd/print.h"
#include "lcd/render.h"
#include "lcd/display.h"
#include "filesystem/ff.h"
#include <string.h>
/**************************************************************************/
#include "usetable.h"
//# MENU config
void ram(void){
uint8_t numentries = 0;
signed char menuselection = 0;
uint8_t visible_lines = 0;
uint8_t current_offset = 0;
for (int i=0;the_config[i].name!=NULL;i++){
if(!the_config[i].disabled)
numentries++;
};
visible_lines = ((RESY/getFontHeight())-1)/2;
while (1) {
// Display current menu page
lcdClear();
lcdPrint("Config");
lcdSetCrsrX(60);
lcdPrint("[");
lcdPrint(IntToStr((current_offset/visible_lines)+1,1,0));
lcdPrint("/");
lcdPrint(IntToStr(((numentries-1)/visible_lines)+1,1,0));
lcdPrint("]");
lcdNl();
lcdNl();
uint8_t j=0;
for (uint8_t i=0;i<current_offset;i++)
while (the_config[++j].disabled);
uint8_t t=0;
for (uint8_t i=0;i<menuselection;i++)
while (the_config[++t].disabled);
for (uint8_t i = current_offset; i < (visible_lines + current_offset) && i < numentries; i++,j++) {
while(the_config[j].disabled)j++;
if(i==0){
lcdPrintln("Save changes:");
if (i == t)
lcdPrint("*");
lcdSetCrsrX(14);
if (i == t)
lcdPrintln("YES");
else
lcdPrintln("no");
}else{
lcdPrintln(the_config[j].name);
if (j == t)
lcdPrint("*");
lcdSetCrsrX(14);
lcdPrint("<");
lcdPrint(IntToStr(the_config[j].value,3,F_LONG));
lcdPrintln(">");
};
lcdRefresh();
}
switch (getInputWaitRepeat()) {
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:
if(the_config[t].value >
the_config[t].min)
the_config[t].value--;
if(the_config[t].value > the_config[t].max)
the_config[t].value=
the_config[t].max;
applyConfig();
break;
case BTN_RIGHT:
if(the_config[t].value <
the_config[t].max)
the_config[t].value++;
if(the_config[t].value < the_config[t].min)
the_config[t].value=
the_config[t].min;
applyConfig();
break;
case BTN_ENTER:
if(menuselection==0)
saveConfig();
return;
}
}
/* NOTREACHED */
}

290
firmware/l0dable/initanim.c Normal file
View File

@ -0,0 +1,290 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/lcd.h"
#include "usetable.h"
#define O_FIXED 1023
#define SPP 10
static void draw_rakett (int x, int y, int scale, int angle);
static int my_gray (int x, int y, void *data);
static int o_sin(int x);
static int o_cos(int x);
static int frame_no = 0;
#define ANIM(start_val, end_val) \
(((start_val) * (1000-(t))) / 1000 + ((end_val) * ((t))) /1000)
void ram (void)
{
char test[512]; /* scratch space */
o_init (test, sizeof(test));
int frame_dir = 1;
int inpt;
o_set_shader (my_gray, NULL);
int x;
int y;
int angle;
int scale;
int velocity = 0;
frame_no=0;
while ((inpt = getInputRaw()) != BTN_ENTER)
{
int t;
o_identity (); /* reset tranforms */
o_set_gray (0);
o_rectangle (0,0,RESX, RESY); /* fill background with black */
o_fill (); /* fill with 50% gray */
if (frame_no < 800)
{
o_set_gray (250);
o_rectangle (0,RESY-7,RESX, 10); /* fill background with black */
o_fill (); /* fill with 50% gray */
}
if (frame_no < 100)
{
t = frame_no * 1000 / 100;
x = ANIM(-60 * 10, 100 * 10);
y = RESY/2 * 10;
angle = ANIM(500, 300);
scale = ANIM(1200, 700);
}
else if (frame_no < 300)
{
t = (frame_no - 100) * 1000 / 200;
x = ANIM(100 * 10, 10 * RESX/2);
y = ANIM((RESY/2) * 10, (RESY/2 - 10) * 10);
angle = ANIM(300, 0);
scale = ANIM(700, 300);
}
else if (frame_no < 600)
{
t = (frame_no - 300) * 1000 / 300;
x = RESX/2 * 10;
y = ANIM((RESY/2-10) * 10, (RESY-14) * 10);
angle = 0;
scale = 300;
}
else
{
return;
/* flying time */
if (inpt == BTN_UP)
{
velocity ++;
}
else if (inpt == BTN_DOWN)
{
velocity --;
}
else if (inpt == BTN_LEFT)
{
angle -= 5;
}
else if (inpt == BTN_RIGHT)
{
angle += 5;
}
if (velocity > 10)
velocity = 10;
if (velocity < -10)
velocity = -10;
{
int c = o_cos ((angle - 900) * 4 * 8192 / 3600) / 4;
int s = o_sin ((angle - 900) * 4 * 8192 / 3600) / 4;
x += (c / 100) * velocity / 10;
y += (s / 100) * velocity / 10;
}
y++;
if (y > (RESY-14) * 10)
y = (RESY-14) * 10;
}
draw_rakett (x, y, scale, angle);
frame_no += frame_dir;
lcdDisplay();
}
}
static int my_gray (int x, int y, void *data)
{
int value = (int)(data);
switch (value)
{
case 0: /* 0.0 */
return 0;
case 1: /* 0.16 */
return (x%3==0) ? (y %2)? 0:0:
(x%3==1) ? (y %2)? 0:0:
(y %2)? 0:1;
case 2: /* 0.25 */
switch (frame_no % 4) {
case 0:
return (x%2) ? (y %2)? 1:0:
(y %2)? 0:0;
case 1:
return (x%2) ? (y %2)? 0:1:
(y %2)? 0:0;
case 2:
return (x%2) ? (y %2)? 0:0:
(y %2)? 0:1;
case 3:
return (x%2) ? (y %2)? 0:0:
(y %2)? 1:0;
}
case 3: /* 0.33 */
return (x%3==0) ? (y %2)? 1:0:
(x%3==1) ? (y %2)? 0:0:
(y %2)? 0:1;
case 4: /* 0.50 */
if (frame_no %2)
return (x%2==0) ? (y %2)? 1:0:
(y %2)? 0:1;
else
return (x%2==0) ? (y %2)? 0:1:
(y %2)? 1:0;
case 5: /* 0.66 */
return (x%3==0) ? (y %2)? 0:1:
(x%3==1) ? (y %2)? 1:1:
(y %2)? 1:0;
case 6: /* 0.75 */
return (x%2) ? (y %2)? 1:0:
(y %2)? 1:1;
case 7: /* 0.85 */
return (x%3==0) ? (y %2)? 1:1:
(x%3==1) ? (y %2)? 1:0:
(y %2)? 1:1;
case 8: /* 1.0 */
return 1;
default: // return ((char)(rnd1())) < value;
/* XXX: use a faster "random" source
for this fallback */
break;
}
return 0;
}
/* This is a very simple vector drawing of heart of gold encoded in a
* string (search and replace regexp-fu on an SVG made in inkscape was
* used to create the strings)
*
* to reduce size, all coordinates are encoded as bytes, 'g'ray values
* are in the range 0-100.
*/
static signed char rakett[] = {
' ',
'm',38,6,
'c',38,6,36,13,36,15,
'c',24,22,23,26,21,32,'c',19,41,23,61,23,61,'c',15,73,14,95,17,110,'l',26,109,'c',26,102,26,87,30,83,'c',30,83,30,88,30,95,'c',31,103,31,108,31,108,'l',36,108,'c',36,108,35,98,36,91,'c',37,83,38,80,38,80,'c',41,79,43,80,47,79,'c',56,85,56,89,58,99,'c',58,103,58,108,58,108,'l',68,108,'c',67,89,69,73,54,58,'c',54,58,56,41,53,31,'c',50,21,40,15,40,15,'l',38,6,'z','g',100,'f','g',100,'s',
' ',
'm',33,20,'c',31,20,29,21,27,22,'c',25,24,23,27,22,29,'c',20,35,21,38,21,38,'c',26,38,29,36,34,33,'c',38,31,42,24,34,21,'c',34,21,33,20,33,20,'z','g', 50,'f','.'
};
static const signed char * o_process_op (const signed char *g)
{
switch (*g++) {
case ' ': o_path_new (); break;
/* all of these path commands are directly in integer coordinates */
case 'm':
o_move_to (g[0], g[1]); g += 2;
break;
case 'l': o_line_to (g[0], g[1]); g += 2; break;
case 'c': o_curve_to (g[0], g[1], g[2], g[3], g[4], g[5]); g += 6; break;
case 'z': o_close (); break;
case 'g': o_set_gray (g[0]*10); g ++; break;
case 'f': o_fill (); break;
case 's': break;
//case 's': o_stroke (); break;
/* 1 = 1 10 = 10 100 = 100 */
#if 0
case '!': o_identity (); break;
case 'T': o_translate (g[0] * 100, g[1] * 100); g+=2; break;
/* 1 = 0.01 10 = 0.1 50 = 0.5 100 = 10x */
case 'S': o_scale (g[0] * 10, g[1] * 10); g+=2; break;
/* -128 = -360 64 = 180 128 = 360 */
case 'R': o_rotate ((g[0] * 3600)/127); g+=1; break;
#endif
default:
case '\0':
case '.': /* end */
return NULL;
}
return g;
}
static void
orender (const signed char *g)
{
for (; g; g = o_process_op (g));
}
void o_rectangle (int x0, int y0, int width, int height)
{
o_path_new ();
o_move_to (x0, y0);
o_line_to (x0 + width, y0);
o_line_to (x0 + width, y0+height);
o_line_to (x0, y0+height);
o_close ();
}
static int o_sin(int x)
{
#define qN 13
#define qA 12
#define qP 15
#define qR (2*qN-qP)
#define qS (qN+qP+1-qA)
x= x<<(30-qN); // shift to full s32 range (Q13->Q30)
if( (x^(x<<1)) < 0) // test for quadrant 1 or 2
x= (1<<31) - x;
x= x>>(30-qN);
return (x * ( (3<<qP) - (x*x>>qR) ) >> qS );
}
static inline int o_cos(int x)
{
return o_sin(x + 8192);
}
static void draw_rakett (int x, int y, int scale, int angle)
{
/* directly including the matrices used to build up the transform, the fudging factors
depend on internal values of o to add up properly */
OMatrix mtranslate = {{{O_FIXED,0},
{0,O_FIXED},
{x * 100 * SPP * O_FIXED / 1000, y * 100 * SPP * O_FIXED / 1000}}};
int c = o_cos (angle * 4 * 8192 / 3600) / 4;
int s = o_sin (angle * 4 * 8192 / 3600) / 4;
OMatrix mrotate = {{{c,s},
{-s,c},
{0, 0}}};
OMatrix mscale = {{{scale * O_FIXED / 1000, 0},
{0,scale * O_FIXED / 1000},
{0,0}}};
OMatrix mtranslate2 = {{{O_FIXED,0},
{0,O_FIXED},
{-37000 * SPP * O_FIXED / 1000, -60000 * SPP * O_FIXED / 1000}}};
o_transform (&mtranslate, 1); /* passing 1 as second arg sets the transform to this */
o_transform (&mrotate, 0); /* passing 0 adds this transformaiton */
o_transform (&mscale, 0); /* again (it is multiplying the matrices internally) */
o_transform (&mtranslate2, 0); /* the final translate (first actually) sets the local origin. */
orender (rakett); /* render the rocket data */
}

38
firmware/l0dable/people.c Normal file
View File

@ -0,0 +1,38 @@
#include <sysinit.h>
#include <string.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "lcd/render.h"
#include "lcd/print.h"
#include "funk/nrf24l01p.h"
#include "usetable.h"
/**************************************************************************/
void ram(void) {
struct NRF_CFG config;
uint8_t buf[16];
config.nrmacs=1;
config.maclen[0] = 16;
config.channel = 81;
memcpy(config.mac0, "\x01\x02\x03\x02\x01", 5);
nrf_config_set(&config);
lcdClear();
lcdPrintln("People nearby:");
//lcdPrint("nearby:");
lcdRefresh();
do{
if( nrf_rcv_pkt_time(64,sizeof(buf),buf) == 16 ){
buf[14] = 0;
if( buf[1] == 0x23 || buf[1] == 0x24){
lcdPrintln(buf+6);
//lcdPrintln("foo");
}
lcdRefresh();
}
}while ((getInputRaw())==BTN_NONE);
}

View File

@ -93,6 +93,7 @@ uint16_t gameId;
uint8_t interval;
uint8_t jitter;
uint8_t flags;
uint8_t *gameTitle;
void sendButton(uint8_t button);
void sendJoin(uint32_t game);
@ -129,6 +130,9 @@ void playGame(void)
{
int len;
struct packet p;
lcdPrintln("Now playing:");
lcdPrintln(gameTitle);
lcdRefresh();
while(1){
uint8_t button = getInputRaw();
@ -182,24 +186,26 @@ uint8_t joinGame()
{
int i;
struct packet p;
struct packet ack;
memset((void*)&p, 0, sizeof(p));
memset((void*)&ack, 0, sizeof(ack));
p.len=sizeof(p);
p.protocol='G';
p.command='J';
p.id= id;
p.ctr= ++ctr;
p.c.join.gameId=gameId;
lcdClear();
lcdPrintln("Joining game");
lcdRefresh();
for(i=0; i<10; i++){
nrf_snd_pkt_crc(sizeof(p),(uint8_t*)&p);
int len = nrf_rcv_pkt_time(30,sizeof(p),(uint8_t*)&p);
if( len==sizeof(p) ){
if( (p.len==32) && (p.protocol=='G') && p.command=='a' ){ //check sanity, protocol
if( p.id == id && p.ctr == ctr ){
if( p.c.ack.flags & FLAGS_ACK_JOINOK ){
int len = nrf_rcv_pkt_time(30,sizeof(ack),(uint8_t*)&ack);
if( len==sizeof(ack) ){
if( (ack.len==32) && (ack.protocol=='G') && ack.command=='a' ){ //check sanity, protocol
if( ack.id == id && ack.ctr == ctr ){
if( ack.c.ack.flags & FLAGS_ACK_JOINOK ){
lcdPrintln("Join OK");
lcdRefresh();
return 1;
@ -233,6 +239,10 @@ uint8_t selectGame()
nrf_config_set(&config);
gamecount = 0;
lcdClear();
lcdPrintln("Searching for");
lcdPrintln("games...");
lcdRefresh();
for(i=0;i<60;i++){
len= nrf_rcv_pkt_time(30, sizeof(p), (uint8_t*)&p);
if (len==sizeof(p)){
@ -271,7 +281,9 @@ uint8_t selectGame()
interval = games[selected].interval;
jitter = games[selected].jitter;
flags = games[selected].gameFlags;
gameTitle = games[selected].gameTitle;
nrf_config_set(&config);
lcdClear();
if( games[selected].gameFlags & FLAGS_MASS_GAME )
return 1;
else
@ -283,6 +295,7 @@ uint8_t selectGame()
void processNickRequest( struct nickrequest *nq)
{
struct packet p;
memset((void*)&p, 0, sizeof(p));
p.len=sizeof(p);
p.protocol='G'; // Proto
p.command='n';
@ -299,12 +312,14 @@ void processPacket(struct packet *p)
if ((p->len==32) && (p->protocol=='G') && (p->id == id || p->id == 0) ){ //check sanity, protocol, id
if (p->command=='T'){
struct packet ack;
ack.len=sizeof(p);
memset((void*)&ack, 0, sizeof(ack));
ack.len=sizeof(ack);
ack.protocol='G';
ack.command='a';
ack.id= id;
ack.ctr= p->ctr;
ack.c.ack.flags = 0;
if( p->id )
nrf_snd_pkt_crc(sizeof(ack),(uint8_t*)&ack);
processText(&(p->c.text));
}
@ -349,6 +364,7 @@ void processText(struct text *t)
void sendButton(uint8_t button)
{
struct packet p;
memset((void*)&p, 0, sizeof(p));
p.len=sizeof(p);
p.protocol='G'; // Proto
p.command='B';

View File

@ -270,7 +270,7 @@ void lcdDisplay(void) {
unsigned char br=0xFF, bg=0xFF, bb=0xFF;
unsigned char frame_r=0x00, frame_g=0x00, frame_b=0x80;
uint16_t color,framecolor,backcolor;
uint16_t x,y,i;
uint16_t x,y;
bool px;
uint16_t actualcolor;
color = ((r&0xF8) << 8) | ((g&0xFC)<<3) | ((b&0xF8) >> 3);

View File

@ -41,7 +41,7 @@ volatile unsigned char CDC_DepInEmpty = 1; // Data IN EP is
much faster than UART transmits
*---------------------------------------------------------------------------*/
/* Buffer masks */
#define CDC_BUF_SIZE (64) // Output buffer in bytes (power 2)
#define CDC_BUF_SIZE (128) // Output buffer in bytes (power 2)
// large enough for file transfer
#define CDC_BUF_MASK (CDC_BUF_SIZE-1ul)
@ -342,6 +342,8 @@ void CDC_BulkIn(void)
{
int numBytesRead, numBytesAvail;
CDC_InBufAvailChar(&numBytesAvail);
if( numBytesAvail > 64 )
numBytesAvail = 64;
numBytesRead = CDC_RdInBuf((char*)&BulkBufIn[0], &numBytesAvail);
// send over USB
if (numBytesRead > 0) {

View File

@ -23,7 +23,7 @@ class Game:
self.bridge = bridge.Bridge(device, self.channel, self.gamemac)
self.announce = packets.Announce(self.gamemac, self.channel,
self.gameid, 1, self.gameName)
self.gameid, 0, self.gameName)
self.announcequeue = Queue.Queue()
self.bridge.registerQueue(self.announcequeue)