diff --git a/firmware/applications/mesh/config.c b/firmware/applications/mesh/config.c new file mode 100644 index 0000000..0d8df7c --- /dev/null +++ b/firmware/applications/mesh/config.c @@ -0,0 +1,38 @@ +#include + +#include "basic/basic.h" + +#include "lcd/print.h" +#include "lcd/display.h" + +#include "filesystem/ff.h" + +#include + +/**************************************************************************/ + +void readcfg(void) { + readConfig(); +}; + +void savecfg(void){ + saveConfig(); +}; + +void applycfg(void){ + applyConfig(); +}; + +void show(void){ + lcdClear(); + lcdPrint("time:"); lcdPrintInt(globalconfig.time); lcdNl(); + lcdPrint("btrig:"); lcdPrintInt(globalconfig.backlighttrigger); lcdNl(); + lcdPrint("bval:"); lcdPrintInt(globalconfig.backlightvalue); lcdNl(); + lcdPrint("lcd:"); lcdPrintInt(globalconfig.lcdstate); lcdNl(); + lcdPrint("priv:"); lcdPrintInt(globalconfig.privacy); lcdNl(); + lcdRefresh(); +}; + +void lcdmirror(void){ + lcdToggleFlag(LCD_MIRRORX); +}; diff --git a/firmware/applications/mesh/mesh.c b/firmware/applications/mesh/mesh.c new file mode 100644 index 0000000..ffc4d75 --- /dev/null +++ b/firmware/applications/mesh/mesh.c @@ -0,0 +1,212 @@ +#include +#include +#include + +#include "basic/basic.h" +#include "basic/byteorder.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" + +#include "funk/nrf24l01p.h" + +#include + +#define MESH_CHANNEL 85 +#define MESH_MAC "MESHB" + +/**************************************************************************/ + +uint32_t const meshkey[4] = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000 +}; + +#define MESHBUFSIZE 10 +#define MESHPKTSIZE 32 +typedef struct { + uint8_t pkt[32]; + char flags; +} MPKT; + +MPKT meshbuffer[MESHBUFSIZE]; + +#define MF_FREE (0) +#define MF_USED (1<<0) + +time_t _timet=0; + +// Timezones suck. Currently we only do it all in localtime. +// I know it's broken. Sorry +time_t getSeconds(void){ + return _timet+(getTimer()*SYSTICKSPEED/1000); +}; + +// ********************************************************************** + +void m_init(void){ + nrf_init(); + + struct NRF_CFG config = { + .channel= MESH_CHANNEL, + .txmac= MESH_MAC, + .nrmacs=1, + .mac0= MESH_MAC, + .maclen ="\x20", // XXX: MESHPKTSIZE + }; + + nrf_config_set(&config); + + for(int i=0;itm_sec = dayclock % 60; + timep->tm_min = (dayclock % 3600) / 60; + timep->tm_hour = dayclock / 3600; + timep->tm_wday = (dayno + 4) % 7; /* day 0 was a thursday */ + while (dayno >= YEARSIZE(year)) { + dayno -= YEARSIZE(year); + year++; + } + timep->tm_year = year - YEAR0; + timep->tm_yday = dayno; + timep->tm_mon = 0; + while (dayno >= _ytab[LEAPYEAR(year)][timep->tm_mon]) { + dayno -= _ytab[LEAPYEAR(year)][timep->tm_mon]; + timep->tm_mon++; + } + timep->tm_mday = dayno + 1; + timep->tm_isdst = 0; + + return timep; +} + + +void m_recv(void){ + __attribute__ ((aligned (4))) uint8_t buf[32]; + int len; + int recvend=100/SYSTICKSPEED+getTimer(); + + m_cleanup(); + + nrf_rcv_pkt_start(); + + getInputWaitRelease(); + + do{ + len=nrf_rcv_pkt_poll_dec(sizeof(buf),buf,meshkey); + + // Receive + if(len<=0){ + delayms_power(10); + continue; + }; + + int i; + for(i=0;i_timet) // Do not live in the past. + _timet = toff; + lcdPrintln("Got T"); + lcdPrintInt(getSeconds());lcdNl(); + + }else if (buf[0]>='A' && buf[0] <'T'){ // Truncate ascii packets. + meshbuffer[i].pkt[MESHPKTSIZE-3]=0; + }; + }while(getTimer()tm_hour); + lcdPrint(":"); + lcdPrintInt(tm->tm_min); + lcdPrint(":"); + lcdPrintInt(tm->tm_sec); + lcdNl(); + lcdPrintInt(tm->tm_mday); + lcdPrint("."); + lcdPrintInt(tm->tm_mon+1); + lcdPrint("."); + lcdPrintInt(tm->tm_year+YEAR0); + lcdNl(); + lcdRefresh(); + delayms(50); + }while ((getInputRaw())==BTN_NONE); +}; + +void m_send(void){ + int ctr=0; + __attribute__ ((aligned (4))) uint8_t buf[32]; + int status; + + lcdClear(); + // Update [T]ime packet + + uint32touint8p(getSeconds(),meshbuffer[0].pkt+2); + for (int i=0;i + +#include "basic/basic.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" +#include "lcd/allfonts.h" + +#include "filesystem/ff.h" +#include "filesystem/select.h" +#include "funk/nrf24l01p.h" +#include "usb/usbmsc.h" + +#include + +/**************************************************************************/ + +void show_ticks(void) { + int dx=0; + int dy=8; + lcdClear(); + dx=DoString(0,dy,"Ticks:"); + while ((getInputRaw())==BTN_NONE){ + DoInt(0,dy+8,_timectr); + lcdDisplay(); + }; + dy+=16; + dx=DoString(0,dy,"Done."); +}; + + +void adc_light(void) { + int dx=0; + int dy=8; + dx=DoString(0,dy,"Light:"); + DoString(0,dy+16,"Night:"); + while ((getInputRaw())==BTN_NONE){ + DoInt(dx,dy,GetLight()); + DoInt(dx,dy+16,isNight()); + DoInt(dx,dy+8,globalconfig.backlighttrigger); + lcdDisplay(); + }; + dy+=8; + dx=DoString(0,dy,"Done."); +}; + +void gotoISP(void) { + DoString(0,0,"Enter ISP!"); + lcdDisplay(); + ISPandReset(); +} + +void lcd_mirror(void) { + lcdToggleFlag(LCD_MIRRORX); +}; + +void lcd_invert(void) { + lcdToggleFlag(LCD_INVERTED); +}; + +void adc_check(void) { + int dx=0; + int dy=8; + // Print Voltage + dx=DoString(0,dy,"Voltage:"); + while ((getInputRaw())==BTN_NONE){ + DoInt(dx,dy,GetVoltage()); + lcdDisplay(); + }; + dy+=8; + dx=DoString(0,dy,"Done."); +}; + +void msc_menu(void){ + DoString(0,8,"MSC Enabled."); + lcdDisplay(); + usbMSCInit(); + getInputWaitRelease(); + getInputWait(); + DoString(0,16,"MSC Disabled."); + usbMSCOff(); +}; + diff --git a/firmware/applications/mesh/uuid.c b/firmware/applications/mesh/uuid.c new file mode 100644 index 0000000..601a5f7 --- /dev/null +++ b/firmware/applications/mesh/uuid.c @@ -0,0 +1,26 @@ +#include + +#include "basic/basic.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" + +#include "funk/nrf24l01p.h" + +#include + +#include "funk/rftransfer.h" +#include "funk/openbeacon.h" + +#include "core/iap/iap.h" + +/**************************************************************************/ + +void f_uuid(void) { + IAP_return_t iap_return; + iap_return = iapReadSerialNumber(); + lcdPrintIntHex(iap_return.Result[0]); lcdNl(); + lcdPrintIntHex(iap_return.Result[1]); lcdNl(); + lcdPrintIntHex(iap_return.Result[2]); lcdNl(); + lcdPrintIntHex(iap_return.Result[3]); lcdNl(); +}