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

This commit is contained in:
lilafisch 2011-12-21 14:27:48 +01:00
commit 8e17dc8056
23 changed files with 647 additions and 534 deletions

View File

@ -9,13 +9,11 @@ LIBS =
VPATH += VPATH +=
OBJS += main.o OBJS += main.o
ifeq "$(wildcard table.c)" "table.c" ifeq "$(TABLE)" "NO"
ifeq "$(APP)" "serial"
OBJS += OBJS +=
else else
OBJS += table.o OBJS += table.o
endif endif
endif
LIBS += lcd/liblcd.a LIBS += lcd/liblcd.a
LIBS += basic/libbasic.a LIBS += basic/libbasic.a
@ -66,14 +64,11 @@ all: $(OUTFILE).bin
protect: $(OUTFILE).bin protect: $(OUTFILE).bin
$(LPCFIX) -p 2 $(OUTFILE).bin $(LPCFIX) -p 2 $(OUTFILE).bin
loadables: $(OUTFILE).bin l0dables: table.c
@cd loadable && $(MAKE)
l0dables:
@cd l0dable && $(MAKE) @cd l0dable && $(MAKE)
clean: clean:
rm -f $(OBJS) $(LD_TEMP) $(OUTFILE).elf $(OUTFILE).bin $(OUTFILE).hex rm -f $(OBJS) $(LD_TEMP) $(OUTFILE).elf $(OUTFILE).bin $(OUTFILE).hex table.c table.h
for dir in $(SUBDIRS); do \ for dir in $(SUBDIRS); do \
$(MAKE) $(CONFIG_MAKE_PRINTDIRECTORY) -C $$dir clean; \ $(MAKE) $(CONFIG_MAKE_PRINTDIRECTORY) -C $$dir clean; \
done done
@ -87,6 +82,9 @@ flash: all
%.o : %.c %.o : %.c
$(CC) $(CFLAGS) -o $@ $< $(CC) $(CFLAGS) -o $@ $<
table.c: l0dable/EXPORTS
./l0dable/mktable.pl
### Make all libraries... ### Make all libraries...
.PHONY: subdirs $(SUBDIRS) .PHONY: subdirs $(SUBDIRS)

View File

@ -4,6 +4,10 @@
OBJS = OBJS =
ifndef APP
APP=final
endif
ifeq "$(APP)" "initial" ifeq "$(APP)" "initial"
NODEFAULT = y NODEFAULT = y
endif endif
@ -20,20 +24,6 @@ OBJS += $(foreach mod,$(APP),$(mod).o)
SRCS = $(foreach mod,$(APP),$(mod).c) SRCS = $(foreach mod,$(APP),$(mod).c)
ifndef APP
ME_OBJ=$(USERNAME)
ifeq "$(ME_OBJ)" ""
ME_OBJ=$(USER)
endif
ifeq "$(ME_OBJ)" ""
ME_OBJ=nouser
endif
OBJS += $(ME_OBJ).o
endif
WRAP=wrapper WRAP=wrapper
LIBNAME=app LIBNAME=app
@ -60,21 +50,6 @@ endif
all: $(LIBFILE) all: $(LIBFILE)
ifeq "$(APP)" "loadable"
ifndef LAPP
LAPP=blinktest
endif
LSRC=../loadable/$(LAPP).c
LOBJ=loadable_$(LAPP).o
.PHONY: $(LOBJ)
$(LOBJ):
$(CC) $(CFLAGS) -o $@ $(LSRC)
OBJS += $(LOBJ)
endif
ifeq "$(APP)" "l0dable" ifeq "$(APP)" "l0dable"
ifndef LAPP ifndef LAPP
LAPP=blinktest LAPP=blinktest

View File

@ -18,40 +18,38 @@ void rbInit() {
gpioSetDir(USB_CONNECT, gpioDirection_Output); gpioSetDir(USB_CONNECT, gpioDirection_Output);
gpioSetValue(USB_CONNECT, 1); gpioSetValue(USB_CONNECT, 1);
// prepare buttons uint8_t ports[] = { RB_BTN0, RB_BTN1, RB_BTN2, RB_BTN3, RB_BTN4,
gpioSetDir(RB_BTN0, gpioDirection_Input); RB_LED0, RB_LED1, RB_LED2,
gpioSetPullup (&RB_BTN0_IO, gpioPullupMode_PullUp);
gpioSetDir(RB_BTN1, gpioDirection_Input);
gpioSetPullup (&RB_BTN1_IO, gpioPullupMode_PullUp);
gpioSetDir(RB_BTN2, gpioDirection_Input);
gpioSetPullup (&RB_BTN2_IO, gpioPullupMode_PullUp);
gpioSetDir(RB_BTN3, gpioDirection_Input);
gpioSetPullup (&RB_BTN3_IO, gpioPullupMode_PullUp);
gpioSetDir(RB_BTN4, gpioDirection_Input);
gpioSetPullup (&RB_BTN4_IO, gpioPullupMode_PullUp);
// prepate chrg_stat
gpioSetDir(RB_PWR_CHRG, gpioDirection_Input);
gpioSetPullup (&RB_PWR_CHRG_IO, gpioPullupMode_PullUp);
// prepare LEDs
IOCON_JTAG_TDI_PIO0_11 &= ~IOCON_JTAG_TDI_PIO0_11_FUNC_MASK;
IOCON_JTAG_TDI_PIO0_11 |= IOCON_JTAG_TDI_PIO0_11_FUNC_GPIO;
uint8_t ports[] = { RB_LED0, RB_LED1, RB_LED2, RB_LED3,
RB_SPI_SS0, RB_SPI_SS1, RB_SPI_SS2, RB_SPI_SS0, RB_SPI_SS1, RB_SPI_SS2,
RB_SPI_SS3, RB_SPI_SS4, RB_SPI_SS5, RB_SPI_SS3, RB_SPI_SS4, RB_SPI_SS5,
RB_HB0, RB_HB1, RB_HB2, RB_HB0, RB_HB1, RB_HB2,
RB_HB3, RB_HB4, RB_HB5}; RB_HB3, RB_HB4, RB_HB5};
volatile uint32_t * regs[] = {&RB_BTN0_IO, &RB_BTN1_IO, &RB_BTN2_IO,
&RB_BTN3_IO, &RB_BTN4_IO};
int i = 0; int i = 0;
while( i<8 ){ while( i<10 ){
gpioSetDir(ports[i], ports[i+1], gpioDirection_Input);
gpioSetPullup(regs[i/2], gpioPullupMode_PullUp);
i+=2;
}
// prepate chrg_stat
gpioSetDir(RB_PWR_CHRG, gpioDirection_Input);
gpioSetPullup (&RB_PWR_CHRG_IO, gpioPullupMode_PullUp);
gpioSetDir(RB_LED3, gpioDirection_Input);
IOCON_PIO1_11 = 0x41;
// prepare LEDs
IOCON_JTAG_TDI_PIO0_11 &= ~IOCON_JTAG_TDI_PIO0_11_FUNC_MASK;
IOCON_JTAG_TDI_PIO0_11 |= IOCON_JTAG_TDI_PIO0_11_FUNC_GPIO;
while( i<16 ){
gpioSetDir(ports[i],ports[i+1], gpioDirection_Output); gpioSetDir(ports[i],ports[i+1], gpioDirection_Output);
gpioSetValue (ports[i++], ports[i++], 0); gpioSetValue (ports[i], ports[i+1], 0);
i+=2;
} }
// Set LED3 to ? // Set LED3 to ?
@ -78,7 +76,8 @@ void rbInit() {
// prepare hackerbus // prepare hackerbus
while(i<sizeof(ports)){ while(i<sizeof(ports)){
gpioSetDir(ports[i],ports[i+1], gpioDirection_Output); gpioSetDir(ports[i],ports[i+1], gpioDirection_Output);
gpioSetValue (ports[i++], ports[i++], 1); gpioSetValue (ports[i], ports[i+1], 1);
i+=2;
} }
// prepare BUSINT interrupt // prepare BUSINT interrupt

View File

@ -12,7 +12,6 @@ OBJS += at45db041d.o
OBJS += util.o OBJS += util.o
OBJS += select.o OBJS += select.o
OBJS += execute.o OBJS += execute.o
OBJS += format.o
LIBNAME=fat LIBNAME=fat

View File

@ -1,188 +0,0 @@
/*---------------------------------------------------------------------------/
/ FatFs - FAT file system module configuration file R0.08b (C)ChaN, 2011
/----------------------------------------------------------------------------/
/
/ CAUTION! Do not forget to make clean the project after any changes to
/ the configuration options.
/
/----------------------------------------------------------------------------*/
#ifndef _FFCONF
#define _FFCONF 8237 /* Revision ID */
/*---------------------------------------------------------------------------/
/ Function and Buffer Configurations
/----------------------------------------------------------------------------*/
#define _FS_TINY 1 /* 0:Normal or 1:Tiny */
/* When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system
/ object instead of the sector buffer in the individual file object for file
/ data transfer. This reduces memory consumption 512 bytes each file object. */
#define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */
/* Setting _FS_READONLY to 1 defines read only configuration. This removes
/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename,
/ f_truncate and useless f_getfree. */
#define _FS_MINIMIZE 1 /* 0 to 3 */
/* The _FS_MINIMIZE option defines minimization level to remove some functions.
/
/ 0: Full function.
/ 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename
/ are removed.
/ 2: f_opendir and f_readdir are removed in addition to 1.
/ 3: f_lseek is removed in addition to 2. */
#define _USE_STRFUNC 0 /* 0:Disable or 1/2:Enable */
/* To enable string functions, set _USE_STRFUNC to 1 or 2. */
#define _USE_MKFS 0 /* 0:Disable or 1:Enable */
/* To enable f_mkfs function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */
#define _USE_FORWARD 0 /* 0:Disable or 1:Enable */
/* To enable f_forward function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */
#define _USE_FASTSEEK 0 /* 0:Disable or 1:Enable */
/* To enable fast seek feature, set _USE_FASTSEEK to 1. */
/*---------------------------------------------------------------------------/
/ Locale and Namespace Configurations
/----------------------------------------------------------------------------*/
#define _CODE_PAGE 1
/* The _CODE_PAGE specifies the OEM code page to be used on the target system.
/ Incorrect setting of the code page can cause a file open failure.
/
/ 932 - Japanese Shift-JIS (DBCS, OEM, Windows)
/ 936 - Simplified Chinese GBK (DBCS, OEM, Windows)
/ 949 - Korean (DBCS, OEM, Windows)
/ 950 - Traditional Chinese Big5 (DBCS, OEM, Windows)
/ 1250 - Central Europe (Windows)
/ 1251 - Cyrillic (Windows)
/ 1252 - Latin 1 (Windows)
/ 1253 - Greek (Windows)
/ 1254 - Turkish (Windows)
/ 1255 - Hebrew (Windows)
/ 1256 - Arabic (Windows)
/ 1257 - Baltic (Windows)
/ 1258 - Vietnam (OEM, Windows)
/ 437 - U.S. (OEM)
/ 720 - Arabic (OEM)
/ 737 - Greek (OEM)
/ 775 - Baltic (OEM)
/ 850 - Multilingual Latin 1 (OEM)
/ 858 - Multilingual Latin 1 + Euro (OEM)
/ 852 - Latin 2 (OEM)
/ 855 - Cyrillic (OEM)
/ 866 - Russian (OEM)
/ 857 - Turkish (OEM)
/ 862 - Hebrew (OEM)
/ 874 - Thai (OEM, Windows)
/ 1 - ASCII only (Valid for non LFN cfg.)
*/
#define _USE_LFN 0 /* 0 to 3 */
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
/* The _USE_LFN option switches the LFN support.
/
/ 0: Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect.
/ 1: Enable LFN with static working buffer on the BSS. Always NOT reentrant.
/ 2: Enable LFN with dynamic working buffer on the STACK.
/ 3: Enable LFN with dynamic working buffer on the HEAP.
/
/ The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. To enable LFN,
/ Unicode handling functions ff_convert() and ff_wtoupper() must be added
/ to the project. When enable to use heap, memory control functions
/ ff_memalloc() and ff_memfree() must be added to the project. */
#define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
/* To switch the character code set on FatFs API to Unicode,
/ enable LFN feature and set _LFN_UNICODE to 1. */
#define _FS_RPATH 0 /* 0 to 2 */
/* The _FS_RPATH option configures relative path feature.
/
/ 0: Disable relative path feature and remove related functions.
/ 1: Enable relative path. f_chdrive() and f_chdir() are available.
/ 2: f_getcwd() is available in addition to 1.
/
/ Note that output of the f_readdir fnction is affected by this option. */
/*---------------------------------------------------------------------------/
/ Physical Drive Configurations
/----------------------------------------------------------------------------*/
#define _VOLUMES 1
/* Number of volumes (logical drives) to be used. */
#define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */
/* Maximum sector size to be handled.
/ Always set 512 for memory card and hard disk but a larger value may be
/ required for on-board flash memory, floppy disk and optical disk.
/ When _MAX_SS is larger than 512, it configures FatFs to variable sector size
/ and GET_SECTOR_SIZE command must be implememted to the disk_ioctl function. */
#define _MULTI_PARTITION 0 /* 0:Single partition or 1:Multiple partition */
/* When set to 0, each volume is bound to the same physical drive number and
/ it can mount only first primaly partition. When it is set to 1, each volume
/ is tied to the partitions listed in VolToPart[]. */
#define _USE_ERASE 0 /* 0:Disable or 1:Enable */
/* To enable sector erase feature, set _USE_ERASE to 1. CTRL_ERASE_SECTOR command
/ should be added to the disk_ioctl functio. */
/*---------------------------------------------------------------------------/
/ System Configurations
/----------------------------------------------------------------------------*/
#define _WORD_ACCESS 0 /* 0 or 1 */
/* Set 0 first and it is always compatible with all platforms. The _WORD_ACCESS
/ option defines which access method is used to the word data on the FAT volume.
/
/ 0: Byte-by-byte access.
/ 1: Word access. Do not choose this unless following condition is met.
/
/ When the byte order on the memory is big-endian or address miss-aligned word
/ access results incorrect behavior, the _WORD_ACCESS must be set to 0.
/ If it is not the case, the value can also be set to 1 to improve the
/ performance and code size. */
/* A header file that defines sync object types on the O/S, such as
/ windows.h, ucos_ii.h and semphr.h, must be included prior to ff.h. */
#define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */
#define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */
#define _SYNC_t HANDLE /* O/S dependent type of sync object. e.g. HANDLE, OS_EVENT*, ID and etc.. */
/* The _FS_REENTRANT option switches the reentrancy (thread safe) of the FatFs module.
/
/ 0: Disable reentrancy. _SYNC_t and _FS_TIMEOUT have no effect.
/ 1: Enable reentrancy. Also user provided synchronization handlers,
/ ff_req_grant, ff_rel_grant, ff_del_syncobj and ff_cre_syncobj
/ function must be added to the project. */
#define _FS_SHARE 0 /* 0:Disable or >=1:Enable */
/* To enable file shareing feature, set _FS_SHARE to 1 or greater. The value
defines how many files can be opened simultaneously. */
#endif /* _FFCONFIG */

View File

@ -1,55 +0,0 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "usb/usbmsc.h"
#include "lcd/print.h"
#include "funk/nrf24l01p.h"
#include "funk/mesh.h"
#include "filesystem/at45db041d.h"
uint8_t init1[] = {0xeb, 0xfe, 0x90, 0x4d, 0x53, 0x44, 0x4f, 0x53,
0x35, 0x2e, 0x30, 0x00, 0x02, 0x01, 0x01, 0x00,
0x01, 0x00, 0x02, 0x00, 0x04, 0xf0, 0x04, 0x00,
0x3f, 0x00, 0xff};
uint8_t init2[] = {0x80, 0x00, 0x29, 0x37,
0x4b, 0x55, 0x33, 0x4e, 0x4f, 0x20, 0x4e, 0x41,
0x4d, 0x45, 0x20, 0x20, 0x20, 0x20, 0x46, 0x41,
0x54, 0x20, 0x20, 0x20, 0x20, 0x20};
void format_formatDF(void)
{
int i;
char buf[512];
//dataflash_initialize();
//delayms(100);
for(i=0; i< 512; i++) buf[i] = 0x00;
//for(i=0; i<1024; i++)
// dataflash_write(buf, i, 1);
memcpy(buf, init1, sizeof(init1));
memcpy(buf+0x24, init2, sizeof(init2));
buf[510] = 0x55;
buf[511] = 0xaa;
//memcpy(buf+510, "\x55\xaa", 2);
dataflash_write(buf, 0, 1);
for(i=0; i< 512; i++) buf[i] = 0x00;
buf[0] = 0xf0;
buf[1] = 0xff;
buf[2] = 0xff;
dataflash_write(buf, 1, 1);
}

View File

@ -1,6 +0,0 @@
#ifndef __FORMAT_H_
#define __FORMAT_H_
void format_formatDF(void);
#endif

View File

@ -19,6 +19,37 @@ const char* f_get_rc_string (FRESULT rc) {
return p; return p;
} }
const uint8_t init1[] = {0xeb, 0xfe, 0x90, 0x4d, 0x53, 0x44, 0x4f, 0x53,
0x35, 0x2e, 0x30, 0x00, 0x02, 0x01, 0x01, 0x00,
0x01, 0x00, 0x02, 0x00, 0x04, 0xf0, 0x04, 0x00,
0x3f, 0x00, 0xff};
const uint8_t init2[] = {0x80, 0x00, 0x29, 0x37,
0x4b, 0x55, 0x33, 0x4e, 0x4f, 0x20, 0x4e, 0x41,
0x4d, 0x45, 0x20, 0x20, 0x20, 0x20, 0x46, 0x41,
0x54, 0x20, 0x20, 0x20, 0x20, 0x20};
inline void format_formatDF(void)
{
int i;
char buf[512];
memset(buf, 0, 512);
for(i=0; i<20; i++) dataflash_write(buf, i, 1);
memcpy(buf, init1, sizeof(init1));
memcpy(buf+0x24, init2, sizeof(init2));
buf[510] = 0x55;
buf[511] = 0xaa;
dataflash_write(buf, 0, 1);
for(i=0; i< 512; i++) buf[i] = 0x00;
buf[0] = 0xf0;
buf[1] = 0xff;
buf[2] = 0xff;
dataflash_write(buf, 1, 1);
}
void fsInit(){ void fsInit(){
FRESULT i; FRESULT i;

View File

@ -301,12 +301,8 @@ uint8_t mesh_recvloop_plus(uint8_t state){
delayms_power(10); delayms_power(10);
}; };
if(getTimer()>recvend || pktctr>MESHBUFSIZE) if(getTimer()>recvend || pktctr>MESHBUFSIZE)
state=0xff; state=QS_END;
}; };
if(state==0xff){
return 0xff;
};
return state; return state;
}; };

View File

@ -8,18 +8,20 @@
#include "SECRETS" #include "SECRETS"
#define SAVE_OPENBEACON 1
const uint8_t mac[5] = {1,2,3,2,1}; const uint8_t mac[5] = {1,2,3,2,1};
volatile uint32_t oid = 0; volatile uint32_t oid = 0;
volatile uint32_t seq = 0; volatile uint32_t seq = 0;
volatile uint8_t strength = 0; volatile uint8_t strength = 0;
#if ENCRYPT_OPENBEACON
#if SAVE_OPENBEACON
static void openbeaconSave(uint32_t s); static void openbeaconSave(uint32_t s);
#endif #endif
static struct NRF_CFG oldconfig; static struct NRF_CFG oldconfig;
#if ENCRYPT_OPENBEACON #if SAVE_OPENBEACON
static void openbeaconShutdown(void) static void openbeaconShutdown(void)
{ {
openbeaconSave(seq); openbeaconSave(seq);
@ -69,7 +71,7 @@ void openbeaconSetup(void)
{ {
oid = GetUUID32(); oid = GetUUID32();
strength = 0; strength = 0;
#if ENCRYPT_OPENBEACON #if SAVE_OPENBEACON
openbeaconRead(); openbeaconRead();
openbeaconSaveBlock(); openbeaconSaveBlock();
#endif #endif
@ -108,12 +110,12 @@ uint8_t openbeaconSend(void)
nrf_set_strength(strength); nrf_set_strength(strength);
nrf_set_tx_mac(sizeof(mac), mac); nrf_set_tx_mac(sizeof(mac), mac);
status = openbeaconSendPacket(oid, seq, 0xFF, strength++); status = openbeaconSendPacket(oid, seq++, 0xFF, strength++);
if( strength == 4 ) if( strength == 4 )
strength = 0; strength = 0;
#if ENCRYPT_OPENBEACON #if SAVE_OPENBEACON
if( (seq++ & OPENBEACON_SAVE) == OPENBEACON_SAVE ) if( (seq & OPENBEACON_SAVE) == OPENBEACON_SAVE )
openbeaconSaveBlock(); push_queue(&openbeaconSaveBlock);
#endif #endif
nrf_config_set(&oldconfig); nrf_config_set(&oldconfig);
return status; return status;

View File

@ -2,6 +2,7 @@
#include "basic/basic.h" #include "basic/basic.h"
#include "basic/config.h" #include "basic/config.h"
#include "filesystem/ff.h"
#include "lcd/print.h" #include "lcd/print.h"
#include "usetable.h" #include "usetable.h"
@ -21,17 +22,44 @@ static const struct MENU submenu_privacy={ "Privacy?", {
{NULL,NULL} {NULL,NULL}
}}; }};
static void yellow();
static void green();
static const char colors[][12] = {"0-yellow","1-green"};
bool color_set;
static const struct MENU submenu_color={ "r0ket color?", {
{ colors[0], &yellow},
{ colors[1], &green},
{NULL,NULL}
}};
void ram(void){ void ram(void){
bool again = true; bool again = true;
FIL file;
menuflags|=(MENU_JUSTONCE|MENU_BIG); menuflags|=(MENU_JUSTONCE|MENU_BIG);
screen_intro(); screen_intro();
while (again) { while (again) {
color_set = false;
if( f_open(&file, "yell0w", FA_OPEN_EXISTING|FA_READ) == 0 ){
yellow();
color_set = true;
}
if( f_open(&file, "green", FA_OPEN_EXISTING|FA_READ) == 0 ){
yellow();
color_set = true;
}
while (!color_set) {
handleMenu(&submenu_color);
}
privacy_set = false; privacy_set = false;
while (!privacy_set) { while (!privacy_set) {
handleMenu(&submenu_privacy); handleMenu(&submenu_privacy);
} }
input("Nickname?", GLOBAL(nickname), 32, 127, MAXNICK-1); input("Nickname?", GLOBAL(nickname), 32, 127, MAXNICK-1);
getInputWaitRelease(); getInputWaitRelease();
again = screen_overview(); again = screen_overview();
@ -41,6 +69,18 @@ void ram(void){
saveConfig(); saveConfig();
}; };
static void green() {
GLOBAL(daytrig) = 155;
GLOBAL(daytrighyst) = 10;
color_set = true;
}
static void yellow() {
GLOBAL(daytrig) = 160;
GLOBAL(daytrighyst) = 15;
color_set = true;
}
static void privacy0() { static void privacy0() {
set_privacy(0); set_privacy(0);
} }

View File

@ -124,4 +124,6 @@ i2cEngine
i2cInit i2cInit
timer32Callback0 timer32Callback0
lcdRead lcdRead
lcdInit
lcdSetCrsr

View File

@ -25,6 +25,7 @@ void Qstatus(void);
void getsp(void); void getsp(void);
void uptime(void); void uptime(void);
void uuid(void); void uuid(void);
void lcdrtest(void);
static const struct MENU submenu_debug={ "debug", { static const struct MENU submenu_debug={ "debug", {
{ "ChkBattery", &ChkBattery}, { "ChkBattery", &ChkBattery},
@ -33,6 +34,7 @@ static const struct MENU submenu_debug={ "debug", {
{ "ChkFunk", &ChkFunk}, { "ChkFunk", &ChkFunk},
{ "Qstatus", &Qstatus}, { "Qstatus", &Qstatus},
// { "ShowSP", &getsp}, // { "ShowSP", &getsp},
{ "lcdrtest", &lcdrtest},
{ "Uptime", &uptime}, { "Uptime", &uptime},
{ "Uuid", &uuid}, { "Uuid", &uuid},
{NULL,NULL} {NULL,NULL}
@ -314,3 +316,18 @@ void ChkFunk(){
while(!getInputRaw())work_queue(); while(!getInputRaw())work_queue();
}; };
// //# MENU lcdread
void lcdrtest(void){
lcdClear();
lcdPrint("ID1:"); lcdPrintInt(lcdRead(128+64+16+8 +2 )); lcdNl();
lcdPrint("ID2:"); lcdPrintInt(lcdRead(128+64+16+8 +2+1)); lcdNl();
lcdPrint("ID3:"); lcdPrintInt(lcdRead(128+64+16+8+4 )); lcdNl();
lcdPrint("ID4:"); lcdPrintInt(lcdRead(128+64+16+8+4 +1)); lcdNl();
lcdPrint("Tmp:"); lcdPrintInt(lcdRead(128+64+16+8+4+2 )); lcdNl();
lcdPrint("VM:"); lcdPrintInt(lcdRead(128+64+16+8+4+2+1)); lcdNl();
// lcd_select(); mylcdWrite(0,128+32+8+4+1); lcd_deselect();
delayms(10);
lcdInit();
lcdRefresh();
while(!getInputRaw())delayms(10);
};

View File

@ -51,22 +51,29 @@ struct packet{
uint8_t gameMac[5]; uint8_t gameMac[5];
uint8_t gameChannel; uint8_t gameChannel;
//uint8_t playerMac[5]; playerMac = gameMac+1; //uint8_t playerMac[5]; playerMac = gameMac+1;
uint32_t gameId; uint16_t gameId;
uint8_t gameFlags; uint8_t gameFlags;
uint8_t interval;
uint8_t jitter;
uint8_t gameTitle[8]; uint8_t gameTitle[8];
}__attribute__((packed)) announce; }__attribute__((packed)) announce;
struct join{ struct join{
uint32_t gameId; uint16_t gameId;
uint8_t reserved[15]; uint8_t reserved[17];
}__attribute__((packed)) join; }__attribute__((packed)) join;
}c; }c;
uint16_t crc; uint16_t crc;
}__attribute__((packed)); }__attribute__((packed));
#define FLAGS_MASS_GAME 1 #define FLAGS_MASS_GAME 1
#define FLAGS_SHORT_PACKET 2
#define FLAGS_LONG_RECV 4
#define FLAGS_ACK_JOINOK 1 #define FLAGS_ACK_JOINOK 1
#define MASS_ID 1 #define MASS_ID 1
#define FLAGS_CLS 1
/**************************************************************************/ /**************************************************************************/
/* l0dable for playing games which are announced by other r0kets with the l0dabel r_game */ /* l0dable for playing games which are announced by other r0kets with the l0dabel r_game */
/* Values of buf[3]: /* Values of buf[3]:
@ -82,12 +89,16 @@ struct packet{
uint32_t ctr; uint32_t ctr;
uint32_t id; uint32_t id;
uint32_t gameId; uint16_t gameId;
uint8_t interval;
uint8_t jitter;
uint8_t flags;
void sendButton(uint8_t button); void sendButton(uint8_t button);
void sendJoin(uint32_t game); void sendJoin(uint32_t game);
void processPacket(struct packet *p); void processPacket(struct packet *p);
void processAnnounce(struct announce *a); void processAnnounce(struct announce *a);
void processText(struct text *t);
uint8_t selectGame(); uint8_t selectGame();
void playGame(); void playGame();
@ -124,14 +135,19 @@ void playGame(void)
sendButton(button); sendButton(button);
while(1){ while(1){
if( flags & FLAGS_LONG_RECV )
len = nrf_rcv_pkt_time(64,sizeof(p),(uint8_t*)&p);
else
len = nrf_rcv_pkt_time(32,sizeof(p),(uint8_t*)&p); len = nrf_rcv_pkt_time(32,sizeof(p),(uint8_t*)&p);
if(len==sizeof(p)){ if(len==sizeof(p)){
processPacket(&p); processPacket(&p);
}else{ }else{
break; break;
} }
} }
delayms(20); int rnd = getRandom() % jitter;
delayms(interval+rnd);
}; };
} }
@ -247,6 +263,9 @@ uint8_t selectGame()
memcpy(config.mac0, games[selected].gameMac, 5); memcpy(config.mac0, games[selected].gameMac, 5);
config.mac0[4]++; config.mac0[4]++;
config.channel = games[selected].gameChannel; config.channel = games[selected].gameChannel;
interval = games[selected].interval;
jitter = games[selected].jitter;
flags = games[selected].gameFlags;
nrf_config_set(&config); nrf_config_set(&config);
if( games[selected].gameFlags & FLAGS_MASS_GAME ) if( games[selected].gameFlags & FLAGS_MASS_GAME )
return 1; return 1;
@ -274,7 +293,15 @@ void processPacket(struct packet *p)
{ {
if ((p->len==32) && (p->protocol=='G') && (p->id == id || p->id == 0) ){ //check sanity, protocol, id if ((p->len==32) && (p->protocol=='G') && (p->id == id || p->id == 0) ){ //check sanity, protocol, id
if (p->command=='T'){ if (p->command=='T'){
//processText(&(p->c.text)); struct packet ack;
ack.len=sizeof(p);
ack.protocol='G';
ack.command='a';
ack.id= id;
ack.ctr= p->ctr;
ack.c.ack.flags = 0;
nrf_snd_pkt_crc(sizeof(ack),(uint8_t*)&ack);
processText(&(p->c.text));
} }
else if (p->command=='N'){ else if (p->command=='N'){
processNickRequest(&(p->c.nickrequest)); processNickRequest(&(p->c.nickrequest));
@ -302,6 +329,17 @@ void processAnnounce(struct announce *a)
} }
} }
void processText(struct text *t)
{
if( t->flags & FLAGS_CLS )
lcdClear() ;
lcdSetCrsr(t->x, t->y);
t->text[16] = 0;
lcdPrint(t->text);
lcdRefresh();
}
//increment ctr and send button state, id and ctr //increment ctr and send button state, id and ctr
void sendButton(uint8_t button) void sendButton(uint8_t button)
{ {
@ -315,7 +353,9 @@ void sendButton(uint8_t button)
//lcdClear(); //lcdClear();
//lcdPrint("Key:"); lcdPrintInt(buf[2]); lcdNl(); //lcdPrint("Key:"); lcdPrintInt(buf[2]); lcdNl();
if( flags & FLAGS_SHORT_PACKET )
nrf_snd_pkt_crc(16,(uint8_t*)&p);
else
nrf_snd_pkt_crc(sizeof(p),(uint8_t*)&p); nrf_snd_pkt_crc(sizeof(p),(uint8_t*)&p);
} }

View File

@ -10,7 +10,8 @@
#include "usb/usbmsc.h" #include "usb/usbmsc.h"
#undef N1600 #define DISPLAY_N1200 0
#define DISPLAY_N1600 1
/**************************************************************************/ /**************************************************************************/
/* Utility routines to manage nokia display */ /* Utility routines to manage nokia display */
@ -19,6 +20,7 @@
uint8_t lcdBuffer[RESX*RESY_B]; uint8_t lcdBuffer[RESX*RESY_B];
uint32_t intstatus; // Caches USB interrupt state uint32_t intstatus; // Caches USB interrupt state
// (need to disable MSC while displaying) // (need to disable MSC while displaying)
uint8_t displayType;
#define TYPE_CMD 0 #define TYPE_CMD 0
#define TYPE_DATA 1 #define TYPE_DATA 1
@ -125,6 +127,8 @@ uint8_t lcdRead(uint8_t data)
void lcdInit(void) { void lcdInit(void) {
int id;
sspInit(0, sspClockPolarity_Low, sspClockPhase_RisingEdge); sspInit(0, sspClockPolarity_Low, sspClockPhase_RisingEdge);
gpioSetValue(RB_LCD_CS, 1); gpioSetValue(RB_LCD_CS, 1);
@ -139,7 +143,12 @@ void lcdInit(void) {
gpioSetValue(RB_LCD_RST, 1); gpioSetValue(RB_LCD_RST, 1);
delayms(100); delayms(100);
lcd_select(); id=lcdRead(220); // ID3
if(id==14)
displayType=DISPLAY_N1600;
else /* ID3 == 48 */
displayType=DISPLAY_N1200;
/* Small Nokia 1200 LCD docs: /* Small Nokia 1200 LCD docs:
* clear/ set * clear/ set
@ -154,94 +163,49 @@ void lcdInit(void) {
* 0xd0+x black lines from top? (-0xdf?) * 0xd0+x black lines from top? (-0xdf?)
* *
*/ */
#ifndef N1600 lcd_select();
lcdWrite(TYPE_CMD,0xE2);
delayms(5); if(displayType==DISPLAY_N1200){
uint8_t initseq[] = {0xAF, // Display ON uint8_t initseq[]= { 0xE2,0xAF, // Display ON
0xA1, // Mirror-X 0xA1, // Mirror-X
0xA4, 0x2F, 0xB0, 0x10}; 0xA4, 0x2F, 0xB0, 0x10};
int i = 0; int i = 0;
while(i<sizeof(initseq)) while(i<sizeof(initseq)){
lcdWrite(TYPE_CMD,initseq[i++]); lcdWrite(TYPE_CMD,initseq[i++]);
// lcdWrite(TYPE_CMD,0x00); delayms(5); // actually only needed after the first
#else }
#if 0 }else{ /* displayType==DISPLAY_N1600 */
uint8_t initseq[] = { uint8_t initseq_d[] = {
//TYPE_CMD,0x01, TYPE_CMD,0x11, TYPE_CMD,0x36, 0x36,
//TYPE_DATA,0x00,TYPE_CMD,0x25, TYPE_DATA,0x3F, 0x29, 0xBA, 0x07,
TYPE_CMD,0x29, TYPE_CMD,0xBA, TYPE_DATA,0x07, 0x15, 0x25, 0x3f,
TYPE_DATA,0x15,TYPE_CMD,0x25, TYPE_DATA,0x3f, 0x11, 0x13, 0x37,
TYPE_CMD,0x11, TYPE_CMD,0x13, TYPE_CMD,0X37, 0x00, 0x3A, 0x05,
TYPE_DATA,0x00, TYPE_CMD,0x3A, TYPE_DATA,0x05, 0x2A, 0, 98-1,
TYPE_CMD,0x2A, TYPE_DATA,0, TYPE_DATA,98-1, 0x2B, 0, 70-1};
TYPE_CMD,0x2B, TYPE_DATA,0, TYPE_DATA,70-1}; uint32_t initseq_c = ~ 0x12BA7; // command/data bitstring
int i = 0 int i = 0;
#endif
delayms(10);
lcdWrite(TYPE_CMD,0x01); //sw reset lcdWrite(TYPE_CMD,0x01); //sw reset
delayms(10); delayms(10);
lcdWrite(TYPE_CMD,0x11); //sleepout
delayms(10);
lcdWrite(TYPE_CMD,0x36); //MADCTL MY MX V LAO RGB X X X while(i<sizeof(initseq_d)){
lcdWrite(TYPE_DATA,0x00); lcdWrite(initseq_c&1, initseq_d[i++]);
initseq_c = initseq_c >> 1;
lcdWrite(TYPE_CMD,0x25); // contrast... }
lcdWrite(TYPE_DATA,0x3F);
delayms(10);
#if 0
while(i<sizeof(initseq)){
lcdWrite(initseq[i++], initseq[i++]);
} }
#else
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
#endif
/*
uint16_t i;
for(i=0; i<100; i++)
lcdWrite(TYPE_DATA,0x00);
*/
lcd_deselect(); lcd_deselect();
} }
void lcdFill(char f){ void lcdFill(char f){
memset(lcdBuffer,f,RESX*RESY_B);
#if 0
int x; int x;
for(x=0;x<RESX*RESY_B;x++) { for(x=0;x<RESX*RESY_B;x++) {
lcdBuffer[x]=f; lcdBuffer[x]=f;
} }
#endif
}; };
void lcdSafeSetPixel(char x, char y, bool f){
if (x>=0 && x<RESX && y>=0 && y < RESY)
lcdSetPixel(x, y, f);
}
void lcdSetPixel(char x, char y, bool f){ void lcdSetPixel(char x, char y, bool f){
if (x<0 || x> RESX || y<0 || y > RESY) if (x<0 || x> RESX || y<0 || y > RESY)
return; return;
@ -263,25 +227,30 @@ bool lcdGetPixel(char x, char y){
return byte & (1 << y_off); return byte & (1 << y_off);
} }
// Color display hepler functions
static void _helper_pixel16(uint16_t color){
lcdWrite(TYPE_DATA,color>>8);
lcdWrite(TYPE_DATA,color&0xFF);
}
static void _helper_hline(uint16_t color){
for(int cx=0;cx<98;cx++)
_helper_pixel16(color);
}
#define THECOLOR_R 0x0 #define THECOLOR_R 0x0
#define THECOLOR_G 0x80 #define THECOLOR_G 0x60
#define THECOLOR_B 0x0 #define THECOLOR_B 0x0
void lcdDisplay(void) { void lcdDisplay(void) {
char byte; char byte;
lcd_select(); lcd_select();
#ifndef N1600 if(displayType==DISPLAY_N1200){
lcdWrite(TYPE_CMD,0xB0); lcdWrite(TYPE_CMD,0xB0);
lcdWrite(TYPE_CMD,0x10); lcdWrite(TYPE_CMD,0x10);
lcdWrite(TYPE_CMD,0x00); lcdWrite(TYPE_CMD,0x00);
#else
lcdWrite(TYPE_CMD,0x2C);
#endif
#ifndef N1600
uint16_t i,page; uint16_t i,page;
for(page=0; page<RESY_B;page++) { for(page=0; page<RESY_B;page++) {
for(i=0; i<RESX; i++) { for(i=0; i<RESX; i++) {
@ -296,7 +265,7 @@ void lcdDisplay(void) {
lcdWrite(TYPE_DATA,byte); lcdWrite(TYPE_DATA,byte);
} }
} }
#else } else { /* displayType==DISPLAY_N1600 */
unsigned char r=THECOLOR_R,g=THECOLOR_G,b=THECOLOR_B; unsigned char r=THECOLOR_R,g=THECOLOR_G,b=THECOLOR_B;
unsigned char br=0xFF, bg=0xFF, bb=0xFF; unsigned char br=0xFF, bg=0xFF, bb=0xFF;
unsigned char frame_r=0x00, frame_g=0x00, frame_b=0x80; unsigned char frame_r=0x00, frame_g=0x00, frame_b=0x80;
@ -308,16 +277,14 @@ void lcdDisplay(void) {
framecolor= ((frame_r&0xF8) << 8) | ((frame_g&0xFC)<<3) | ((frame_b&0xF8) >> 3); framecolor= ((frame_r&0xF8) << 8) | ((frame_g&0xFC)<<3) | ((frame_b&0xF8) >> 3);
backcolor= ((br&0xF8) << 8) | ((bg&0xFC)<<3) | ((bb&0xF8) >> 3); backcolor= ((br&0xF8) << 8) | ((bg&0xFC)<<3) | ((bb&0xF8) >> 3);
lcdWrite(TYPE_CMD,0x2C);
//top line of the frame... //top line of the frame...
for(i=0;i<98;i++){ _helper_hline(framecolor);
lcdWrite(TYPE_DATA,framecolor>>8);
lcdWrite(TYPE_DATA,framecolor&0xFF);
}
for(y=RESY;y>0;y--){ for(y=RESY;y>0;y--){
//left line of the frame //left line of the frame
lcdWrite(TYPE_DATA,framecolor>>8); _helper_pixel16(framecolor);
lcdWrite(TYPE_DATA,framecolor&0xFF);
for(x=RESX;x>0;x--){ for(x=RESX;x>0;x--){
if(GLOBAL(lcdmirror)) if(GLOBAL(lcdmirror))
@ -328,23 +295,18 @@ void lcdDisplay(void) {
if((!px)^(!GLOBAL(lcdinvert))) actualcolor=color; if((!px)^(!GLOBAL(lcdinvert))) actualcolor=color;
else actualcolor=backcolor; /* white */ else actualcolor=backcolor; /* white */
lcdWrite(TYPE_DATA,actualcolor>>8); _helper_pixel16(actualcolor);
lcdWrite(TYPE_DATA,actualcolor&0xFF);
} }
//right line of the frame //right line of the frame
lcdWrite(TYPE_DATA,framecolor>>8); _helper_pixel16(framecolor);
lcdWrite(TYPE_DATA,framecolor&0xFF);
} }
//bottom line of the frame //bottom line of the frame
for(i=0;i<98;i++){ _helper_hline(framecolor);
lcdWrite(TYPE_DATA,framecolor>>8);
lcdWrite(TYPE_DATA,framecolor&0xFF);
} }
#endif
lcd_deselect(); lcd_deselect();
} }
void lcdRefresh() __attribute__ ((weak, alias ("lcdDisplay"))); void lcdRefresh() __attribute__ ((weak, alias ("lcdDisplay")));
inline void lcdInvert(void) { inline void lcdInvert(void) {
@ -352,32 +314,24 @@ inline void lcdInvert(void) {
} }
void lcdSetContrast(int c) { 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(); lcd_select();
if(displayType==DISPLAY_N1200){
if(c<0x1F)
lcdWrite(TYPE_CMD,0x80+c);
}else{ /* displayType==DISPLAY_N1600 */
if(c<0x40) {
lcdWrite(TYPE_CMD,0x25); lcdWrite(TYPE_CMD,0x25);
lcdWrite(TYPE_DATA,4*c); lcdWrite(TYPE_DATA,4*c);
};
}
lcd_deselect(); lcd_deselect();
#endif
}; };
void lcdSetInvert(int c) { void lcdSetInvert(int c) {
if(c>1)
c=1;
if(c<0)
c=1;
c+=0xa6;
lcd_select(); lcd_select();
lcdWrite(TYPE_CMD,c); /* it doesn't harm N1600, save space */
// if(displayType==DISPLAY_N1200)
lcdWrite(TYPE_CMD,(c&1)+0xa6);
lcd_deselect(); lcd_deselect();
}; };
@ -389,7 +343,6 @@ void __attribute__((__deprecated__)) lcdToggleFlag(int flag) {
GLOBAL(lcdinvert)=!GLOBAL(lcdinvert); GLOBAL(lcdinvert)=!GLOBAL(lcdinvert);
} }
void lcdShiftH(bool right, bool wrap) { void lcdShiftH(bool right, bool wrap) {
uint8_t tmp; uint8_t tmp;
for (int yb = 0; yb<RESY_B; yb++) { for (int yb = 0; yb<RESY_B; yb++) {
@ -449,7 +402,6 @@ void lcdShiftV(bool up, bool wrap) {
} }
lcdBuffer[x+((RESY_B-1)*RESX)] = ( lcdBuffer[x+((RESY_B-1)*RESX)] >> 1) | ((tmp[x]<<3)&8); lcdBuffer[x+((RESY_B-1)*RESX)] = ( lcdBuffer[x+((RESY_B-1)*RESX)] >> 1) | ((tmp[x]<<3)&8);
} }
} }
} }

View File

@ -27,7 +27,7 @@ void lcdDisplay(void);
void lcdInvert(void); void lcdInvert(void);
void lcdToggleFlag(int flag); void lcdToggleFlag(int flag);
void lcdSetPixel(char x, char y, bool f); void lcdSetPixel(char x, char y, bool f);
void lcdSafeSetPixel(char x, char y, bool f); //void lcdSafeSetPixel(char x, char y, bool f); //useless. see in display.c to learn why --the_nihilant
bool lcdGetPixel(char x, char y); bool lcdGetPixel(char x, char y);
void lcdShift(int x, int y, bool wrap); void lcdShift(int x, int y, bool wrap);
void lcdSetContrast(int c); void lcdSetContrast(int c);

View File

@ -25,7 +25,7 @@ uint8_t lcdShowAnim(char *fname, uint32_t framems) {
getInputWaitRelease(); getInputWaitRelease();
while(!getInputRaw()){ while(!getInputRaw()){
lcdFill(0x55); // lcdFill(0x55); // useless, as it will be overwritten anyway by the next instruction --the_nihilant
res = f_read(&file, (char *)lcdBuffer, RESX*RESY_B, &readbytes); res = f_read(&file, (char *)lcdBuffer, RESX*RESY_B, &readbytes);
if(res) if(res)
return -1; return -1;

View File

@ -28,31 +28,16 @@ cp SECRETS.release SECRETS
mkdir $TARG mkdir $TARG
mkdir $TARG/files mkdir $TARG/files
echo "###"
echo "### Building initial"
echo "###"
git checkout filesystem/ffconf.h
make clean
make APP=initial
cp firmware.bin $TARG/initial.bin
echo "###" echo "###"
echo "### Building final" echo "### Building final"
echo "###" echo "###"
export FINAL=y export FINAL=y
cp filesystem/ffconf.h-final filesystem/ffconf.h
make clean make clean
./l0dable/mktable.pl ./l0dable/mktable.pl
make APP=final make APP=final
cp firmware.elf $TARG/final.elf cp firmware.elf $TARG/final.elf
cp firmware.bin $TARG/final.bin cp firmware.bin $TARG/final.bin
echo "###"
echo "### Building crypto"
echo "###"
(cd ../tools/crypto && make)
echo "###" echo "###"
echo "### Gathering files" echo "### Gathering files"
echo "###" echo "###"
@ -63,7 +48,6 @@ cp ../tools/image/lcd/i42.lcd $TARG/files/nick.lcd
echo "###" echo "###"
echo "### Gathering loadables" echo "### Gathering loadables"
echo "###" echo "###"
# XXX: add crypto stuff
(cd l0dable && make) (cd l0dable && make)
mv l0dable/*.c0d $TARG/files/ mv l0dable/*.c0d $TARG/files/
mv l0dable/*.int $TARG/files/ mv l0dable/*.int $TARG/files/
@ -71,6 +55,11 @@ mv l0dable/*.nik $TARG/files/
if grep -q 'define ENCRYPT_L0DABLE' SECRETS ; then if grep -q 'define ENCRYPT_L0DABLE' SECRETS ; then
echo "###"
echo "### Building crypto"
echo "###"
(cd ../tools/crypto && make)
echo "###" echo "###"
echo "### Crypting loadables" echo "### Crypting loadables"
echo "###" echo "###"
@ -101,4 +90,3 @@ echo "### Done. Yay!"
echo "###" echo "###"
git checkout SECRETS git checkout SECRETS
git checkout filesystem/ffconf.h

50
tools/game/bong/bong.html Normal file
View File

@ -0,0 +1,50 @@
<html>
<head><title>B-Pong</title></head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="bong.js"></script>
<style>
#playfield
{
color: black;
background-color: black;
border: 0px none black;
margin: 0px;
padding: 0px;
position: absolute;
top: 0px;
left: 0px;
}
div
{
font-size: 1px;
color: white;
background-color: #33FF33;
margin: 0px;
margin: 0px;
position: absolute;
top: 0px;
left: 0px;
}
div.score
{
color: #33FF33;
background-color: transparent;
width: 640px;
font-size: 20px;
font-family: courier new;
}
</style>
<body>
<input id="playfield">
<div id="paddle_left"></div>
<div id="paddle_right"></div>
<div class="score" style="text-align:left" id="score_left">0</div>
<div class="score" style="text-align:right" id="score_right">0</div>
<div id="ball"></div>
</input>
<div style="font-size:14;color:black;background-color:white;" id="socket">s_data...</div>
<div style="font-size:14;color:black;background-color:white;" id="debug">debug</div>
</body>
</html>

262
tools/game/bong/bong.js Normal file
View File

@ -0,0 +1,262 @@
// Initialisation
var socket = "ws://83.133.179.198:8888/data";
var field= { w: 320, h: 240 };
var paddle = { w: 2, h: 30 };
var ball = { w: 5, h: 5, s: 5 };
// Pong game class
function pong() {
this.ball = {};
this.left = {};
this.right = {};
this.score = {};
this.score.left = {};
this.score.right = {};
this.field = {};
this.game = { run: 0 };
this.ball.size=ball;
this.left.size=paddle;
this.right.size=paddle;
this.field.size=field;
this.left.x=-field.w+3*this.left.size.w;
this.right.x=field.w-3*this.right.size.w;
this.ball.avatar=$('div#ball');
this.left.avatar=$('div#paddle_left');
this.right.avatar=$('div#paddle_right');
this.score.left.avatar=$('div#score_left');
this.score.right.avatar=$('div#score_right');
this.field.avatar=$('#playfield');
function setupavatar(obj){
obj.avatar.width(2*obj.size.w)
.height(2*obj.size.h);
};
setupavatar(this.ball);
setupavatar(this.left);
setupavatar(this.right);
setupavatar(this.field);
this.field.avatar.focus();
this.score.left.pts=0;
this.score.right.pts=0;
this.setup( (Math.random()>0.5)?1:-1);
this.field.avatar.keydown(this,function(ev){
if(ev.which == 67) ev.data.socketstart(socket);
if(ev.which == 81) ev.data.game.run=0;
if(ev.which == 82) ev.data.game.run=1;
if(ev.which > 48 && ev.which <=57) ev.data.setleft((ev.which-53)/4);
});
$('#debug').css({left:0,top:2*this.field.size.h+10});
$('#socket').css({left:0,top:2*this.field.size.h+30});
}
pong.prototype.setleft = function(where){
this.left.y=where*(this.field.size.h-this.left.size.h);
};
pong.prototype.setright = function(where){
this.right.y=where*(this.field.size.h-this.right.size.h);
};
pong.prototype.setup = function(rtl){
this.ball.x=0;
this.ball.y=0;
this.ball.ang=Math.random()*20/180*Math.PI;
if(rtl<0) this.ball.ang=Math.PI-this.ball.ang;
this.ball.spd=this.ball.size.s;
this.left.y=0;
this.right.y=0;
this.game.run=0;
};
pong.prototype.update= function(t){
var upv=0;
this.ball.vx=Math.cos(this.ball.ang)*this.ball.spd;
this.ball.vy=Math.sin(this.ball.ang)*this.ball.spd;
this.ball.x+=t*this.ball.vx;
this.ball.y+=t*this.ball.vy;
this.ball.x+=t*this.ball.vx;
this.ball.y+=t*this.ball.vy;
// Clipping
if(this.ball.y-this.ball.size.h<-field.h){
this.ball.ang=-this.ball.ang;
this.ball.y=-field.h+this.ball.size.h;
};
if(this.ball.y+this.ball.size.h>field.h){
this.ball.ang=-this.ball.ang;
this.ball.y=field.h-this.ball.size.h;
};
function newang(off,bath){
var trig=(bath-1)/4;
var ad=0;
if(Math.abs(off)<trig){
ad=0;
}else {
if(off<0){
off+=trig;
}else{
off-=trig;
};
ad=off/(3*trig)*Math.PI/3;
};
this.ball.off=off;
this.ball.ad=ad;
return ad;
};
// Hit bat?
if(this.ball.x-this.ball.size.w<this.right.x+this.right.size.w &&
this.ball.x+this.ball.size.w>this.right.x-this.right.size.w &&
this.ball.y+this.ball.size.h>this.right.y-this.right.size.h &&
this.ball.y-this.ball.size.h<this.right.y+this.right.size.h){
this.ball.ang=Math.PI-this.ball.ang;
this.ball.ang=this.ball.ang-newang(this.ball.y-this.right.y,this.right.size.h+this.ball.size.h);
this.ball.x=this.right.x-this.right.size.w-this.ball.size.w;
this.ball.spd*=1.1;
};
if(this.ball.x-this.ball.size.w<this.left.x+this.left.size.w &&
this.ball.x+this.ball.size.w>this.left.x-this.left.size.w &&
this.ball.y+this.ball.size.h>this.left.y-this.left.size.h &&
this.ball.y-this.ball.size.h<this.left.y+this.left.size.h){
this.ball.ang=Math.PI-this.ball.ang;
this.ball.ang=this.ball.ang+newang(this.ball.y-this.left.y,this.left.size.h+this.ball.size.h);
this.ball.x=this.left.x+this.left.size.w+this.ball.size.w;
this.ball.spd*=1.1;
};
// Score point
if(this.ball.x+this.ball.size.w>field.w){
this.score.left.pts++;
this.setup(-1);
this.ball.ang=Math.PI-this.ball.ang;
this.game.run=1;
};
if(this.ball.x-this.ball.size.w<-field.w){
this.score.right.pts++;
this.setup(1);
this.game.run=1;
};
if(this.ball.ang<0)
this.ball.ang+=2*Math.PI;
if(this.ball.ang>2*Math.PI)
this.ball.ang-=2*Math.PI;
$('#debug').html("ang="+Math.abs(this.ball.ang/Math.PI*180)+" ,x="+Math.ceil(this.ball.x)+" ,y="+Math.ceil(this.ball.y));//+" ,off="+(this.ball.off)+" ,ad="+Math.ceil(this.ball.ad));
};
pong.prototype.display=function(){
function move(obj,av){
var x = obj.x - obj.size.w + field.w;
var y = obj.y - obj.size.h + field.h;
obj.avatar.css({left:x,top:y});
};
move(this.ball);
move(this.left);
move(this.right);
this.score.left.avatar.html(this.score.left.pts);
this.score.right.avatar.html(this.score.right.pts);
};
var time = function() { return +(new Date) / 100 };
var last = time();
pong.prototype.run = function(){
var now = time();
if(game.game.run==1)
game.update(now - last);
game.display();
last=now;
};
pong.prototype.socketstart = function(uri){
function debug(str){
$("#socket").append("<br>" + str);
};
ws = new WebSocket(uri);
debug("ws start");
ws.onopen = function() {
debug("ws open");
$('#socket').css({"color": "green"});
ws.send("hello");
this.game.run=1;
};
ws.onmessage = function (evt) {
var data = evt.data;
$('#socket').html(data);
if(data.slice(0,1)=="{"){
var result=JSON.parse(data);
if (result.right){
this.setright(result.right);
} else if (result.left){
this.setleft(result.left);
}else {
// unknown json input
};
}else{
// unknown non-json input
};
};
ws.onclose = function() {
debug("socket closed");
$('#socket').css({"color": "red"});
// reconnect
};
};
// Start utility stuff
(function() {
var onEachFrame;
if (window.webkitRequestAnimationFrame) {
onEachFrame = function(cb) {
var _cb = function() { cb(); webkitRequestAnimationFrame(_cb); }
_cb();
};
} else if (window.mozRequestAnimationFrame) {
onEachFrame = function(cb) {
var _cb = function() { cb(); mozRequestAnimationFrame(_cb); }
_cb();
};
} else {
onEachFrame = function(cb) {
setInterval(cb, 1000 / 60);
}
}
window.onEachFrame = onEachFrame;
})();
var game;
$(document).ready(function(){
game=new pong();
if (window.MozWebSocket) {
window.WebSocket = window.MozWebSocket;
}
if ("WebSocket" in window) {
game.socketstart(socket);
} else {
alert("You have no web sockets");
};
window.onEachFrame(game.run);
});

4
tools/game/bong/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -19,7 +19,7 @@ class Game:
self.gamemac = [int(random.random()*254) for x in range(1,6)] self.gamemac = [int(random.random()*254) for x in range(1,6)]
self.playermac = list(self.gamemac) self.playermac = list(self.gamemac)
self.playermac[4]+=1 self.playermac[4]+=1
self.gameid = int(random.random()*(2**31)) self.gameid = int(random.random()*(2**15))
self.bridge = bridge.Bridge(device, self.channel, self.gamemac) self.bridge = bridge.Bridge(device, self.channel, self.gamemac)
self.announce = packets.Announce(self.gamemac, self.channel, self.announce = packets.Announce(self.gamemac, self.channel,

View File

@ -4,6 +4,9 @@ def inttouint32(v):
def uint32toint(v): def uint32toint(v):
return (ord(v[3])<< 24) + (ord(v[2])<<16) + (ord(v[1])<<8) + (ord(v[0])) return (ord(v[3])<< 24) + (ord(v[2])<<16) + (ord(v[1])<<8) + (ord(v[0]))
def inttouint16(v):
return chr(v&0xff)+chr((v>>8)&0xff)
class Packet: class Packet:
def __init__(self, command, id=None): def __init__(self, command, id=None):
self.ctr = 0 self.ctr = 0
@ -55,7 +58,7 @@ class Button(Packet):
return s return s
class Announce(Packet): class Announce(Packet):
def __init__(self, gameMac, gameChannel, gameId, gameFlags, gameTitle): def __init__(self, gameMac, gameChannel, gameId, gameFlags, gameTitle, interval=30, jitter=16):
#always a broadcast #always a broadcast
Packet.__init__(self, 'A', 0) Packet.__init__(self, 'A', 0)
self.gameMac = gameMac self.gameMac = gameMac
@ -63,14 +66,18 @@ class Announce(Packet):
self.gameId = gameId self.gameId = gameId
self.gameFlags = gameFlags self.gameFlags = gameFlags
self.gameTitle = gameTitle[0:8] self.gameTitle = gameTitle[0:8]
self.interval = interval
self.jitter = jitter
self.priority = 3 self.priority = 3
def toMessage(self): def toMessage(self):
message = Packet.toMessage(self) message = Packet.toMessage(self)
message += ''.join([chr(x) for x in self.gameMac]) message += ''.join([chr(x) for x in self.gameMac])
message += chr(self.gameChannel) message += chr(self.gameChannel)
message += inttouint32(self.gameId) message += inttouint16(self.gameId)
message += chr(self.gameFlags) message += chr(self.gameFlags)
message += chr(self.interval)
message += chr(self.jitter)
message += self.gameTitle message += self.gameTitle
if len(self.gameTitle) < 8: if len(self.gameTitle) < 8:
message += '\x00'*(8-len(self.gameTitle)) message += '\x00'*(8-len(self.gameTitle))