diff --git a/embedded8266/common/commonservices.c b/embedded8266/common/commonservices.c index dc01a77..de80267 100644 --- a/embedded8266/common/commonservices.c +++ b/embedded8266/common/commonservices.c @@ -21,6 +21,7 @@ static struct espconn *pHTTPServer; struct espconn *pespconn; uint16_t g_gpiooutputmask = 0; +int ets_str2macaddr(void *, void *); static int need_to_switch_back_to_soft_ap = 0; //0 = no, 1 = will need to. 2 = do it now. #define MAX_STATIONS 20 @@ -156,12 +157,49 @@ int ICACHE_FLASH_ATTR issue_command(char * buffer, int retsize, char *pusrdata, flashchip->chip_size = 0x00080000; return buffend - buffer; } + case 'i': case 'I': //Respond with device info. + { + buffend += ets_sprintf(buffend, "I" ); + int i; + for( i = 0; i < 2 ;i++ ) + { + struct ip_info ipi; + wifi_get_ip_info( i, &ipi ); + buffend += ets_sprintf(buffend, "\t"IPSTR, IP2STR(&ipi.ip) ); + } + buffend += ets_sprintf(buffend, "\r\n" ); + return buffend - buffer; + } case 'w': case 'W': // (W1:SSID:PASSWORD) (To connect) or (W2) to be own base station. ...or WI, to get info... or WS to scan. { - char * colon = (char *) ets_strstr( (char*)&pusrdata[2], ":" ); - char * colon2 = (colon)?((char *)ets_strstr( (char*)(colon+1), ":" )):0; + int c1l = 0; + int c2l = 0; + char * colon = (char *) ets_strstr( (char*)&pusrdata[2], "\t" ); + char * colon2 = (colon)?((char *)ets_strstr( (char*)(colon+1), "\t" )):0; + char * colon3 = (colon2)?((char *)ets_strstr( (char*)(colon2+1), "\t" )):0; + char * colon4 = (colon3)?((char *)ets_strstr( (char*)(colon3+1), "\t" )):0; char * extra = colon2; + char mac[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + int bssid_set = 0; + if( colon ) { *colon = 0; colon++; } + if( colon2 ) { *colon2 = 0; colon2++; } + if( colon3 ) { *colon3 = 0; colon3++; } + if( colon4 ) { *colon4 = 0; colon4++; } + + if( colon ) { c1l = ets_strlen( colon ); } + if( colon2 ) { c2l = ets_strlen( colon2 ); } + if( colon3 ) + { + bssid_set = ets_str2macaddr( mac, colon3 )?1:0; + if( ( mac[0] == 0x00 || mac[0] == 0xff ) && + ( mac[1] == 0x00 || mac[1] == 0xff ) && + ( mac[2] == 0x00 || mac[2] == 0xff ) && + ( mac[3] == 0x00 || mac[3] == 0xff ) && + ( mac[4] == 0x00 || mac[4] == 0xff ) && + ( mac[5] == 0x00 || mac[5] == 0xff ) ) bssid_set = 0; + } + if( extra ) { for( ; *extra; extra++ ) @@ -178,79 +216,139 @@ int ICACHE_FLASH_ATTR issue_command(char * buffer, int retsize, char *pusrdata, { case '1': //Station mode case '2': //AP Mode - if( colon && colon2 ) + if( colon && colon2 && ets_strlen( colon ) > 1 ) { - int c1l = 0; - int c2l = 0; - *colon = 0; colon++; - *colon2 = 0; colon2++; - c1l = ets_strlen( colon ); - c2l = ets_strlen( colon2 ); - if( c1l > 32 ) c1l = 32; - if( c2l > 32 ) c2l = 32; + if( c1l > 31 ) c1l = 31; + if( c2l > 63 ) c2l = 63; - printf( "Switching to: \"%s\"/\"%s\".\n", colon, colon2 ); + printf( "Switching to: \"%s\"/\"%s\" (%d/%d). BSSID_SET: %d [%c]\n", colon, colon2, c1l, c2l, bssid_set, pusrdata[1] ); if( pusrdata[1] == '1' ) { struct station_config stationConf; - os_bzero( &stationConf, sizeof( stationConf ) ); + wifi_station_get_config(&stationConf); os_memcpy(&stationConf.ssid, colon, c1l); os_memcpy(&stationConf.password, colon2, c2l); + stationConf.ssid[c1l] = 0; + stationConf.password[c2l] = 0; + stationConf.bssid_set = bssid_set; + os_memcpy( stationConf.bssid, mac, 6 ); + + printf( "-->'%s'\n",stationConf.ssid); + printf( "-->'%s'\n",stationConf.password); + + EnterCritical(); +// wifi_station_set_config(&stationConf); wifi_set_opmode( 1 ); wifi_station_set_config(&stationConf); wifi_station_connect(); + ExitCritical(); + +// wifi_station_get_config( &stationConf ); + buffend += ets_sprintf( buffend, "W1\r\n" ); printf( "Switching.\n" ); } else { - wifi_set_opmode_current( 1 ); + struct softap_config config; + char macaddr[6]; + wifi_softap_get_config( &config ); + + wifi_get_macaddr(SOFTAP_IF, macaddr); + + os_memcpy( &config.ssid, colon, c1l ); + os_memcpy( &config.password, colon2, c2l ); + config.ssid_len = c1l; +#if 0 //We don't support encryption. + config.ssid[c1l] = 0; + config.password[c2l] = 0; + + config.authmode = 0; + if( colon3 ) + { + int k; + for( k = 0; enctypes[k]; k++ ) + { + if( strcmp( colon3, enctypes[k] ) == 0 ) + config.authmode = k; + } + } + +#endif + + int chan = (colon4)?my_atoi(colon4):config.channel; + if( chan == 0 || chan > 13 ) chan = 1; + config.channel = chan; + +// printf( "Mode now. %s %s %d %d %d %d %d\n", config.ssid, config.password, config.ssid_len, config.channel, config.authmode, config.max_connection ); +// printf( "Mode Set. %d\n", wifi_get_opmode() ); + + EnterCritical(); + wifi_softap_set_config(&config); wifi_set_opmode( 2 ); + ExitCritical(); + printf( "Switching SoftAP: %d %d.\n", chan, config.authmode ); + buffend += ets_sprintf( buffend, "W2\r\n" ); } } break; case 'I': { + char macmap[15]; int mode = wifi_get_opmode(); buffend += ets_sprintf( buffend, "WI%d", mode ); if( mode == 2 ) { + uint8_t mac[6]; struct softap_config ap; wifi_softap_get_config( &ap ); - buffend += ets_sprintf( buffend, "\t%s\t%s\t%s\t%d", ap.ssid, ap.password, enctypes[ap.authmode], ap.channel ); + wifi_get_macaddr( 1, mac ); + ets_sprintf( macmap, MACSTR, MAC2STR( mac ) ); + buffend += ets_sprintf( buffend, "\t%s\t%s\t%s\t%d", ap.ssid, ap.password, macmap, ap.channel ); } else { struct station_config sc; wifi_station_get_config( &sc ); - buffend += ets_sprintf( buffend, "\t%s\t%s\tna\t%d", sc.ssid, sc.password, wifi_get_channel() ); + if( sc.bssid_set ) + ets_sprintf( macmap, MACSTR, MAC2STR( sc.bssid ) ); + else + macmap[0] = 0; + buffend += ets_sprintf( buffend, "\t%s\t%s\t%s\t%d", sc.ssid, sc.password, macmap, wifi_get_channel() ); } } break; + case 'X': case 'x': + buffend += ets_sprintf( buffend, "WX%d", wifi_station_get_rssi() ); + break; case 'S': case 's': { int i, r; + struct scan_config sc; scanplace = 0; + sc.ssid = 0; + sc.bssid = 0; + sc.channel = 0; + sc.show_hidden = 1; + EnterCritical(); if( wifi_get_opmode() == SOFTAP_MODE ) { wifi_set_opmode_current( STATION_MODE ); need_to_switch_back_to_soft_ap = 1; - r = wifi_station_scan(0, scandone ); - } - else - { - r = wifi_station_scan(0, scandone ); } + r = wifi_station_scan(&sc, scandone ); + ExitCritical(); + buffend += ets_sprintf( buffend, "WS%d\n", r ); uart0_sendStr(buffer); @@ -386,7 +484,9 @@ void CSTick( int slowtick ) if( need_to_switch_back_to_soft_ap == 2 ) { need_to_switch_back_to_soft_ap = 0; + EnterCritical(); wifi_set_opmode_current( SOFTAP_MODE ); + ExitCritical(); } HTTPTick(0); diff --git a/embedded8266/common/http.c b/embedded8266/common/http.c index a889f3b..08545af 100644 --- a/embedded8266/common/http.c +++ b/embedded8266/common/http.c @@ -7,6 +7,9 @@ #define HTDEBUG( x... ) printf( x ) +//#define ISKEEPALIVE "keep-alive" +#define ISKEEPALIVE "close" + struct HTTPConnection HTTPConnections[HTTP_CONNECTIONS]; struct HTTPConnection * curhttp; uint8 * curdata; @@ -208,7 +211,7 @@ void ICACHE_FLASH_ATTR HTTPHandleInternalCallback( ) if( curhttp->bytesleft < 0xfffffffe ) { - PushString("Connection: keep-alive\r\nContent-Length: "); + PushString("Connection: "ISKEEPALIVE"\r\nContent-Length: "); Uint32To10Str( stto, curhttp->bytesleft ); PushBlob( stto, os_strlen( stto ) ); curhttp->keep_alive = 1; diff --git a/embedded8266/common/http_custom.c b/embedded8266/common/http_custom.c index ff69ac9..4a1ee9d 100644 --- a/embedded8266/common/http_custom.c +++ b/embedded8266/common/http_custom.c @@ -145,7 +145,7 @@ void ICACHE_FLASH_ATTR NewWebSocket() curhttp->rcb = 0; curhttp->rcbDat = (void*)&WSEvalData; } - else if( strcmp( (const char*)curhttp->pathbuffer, "/d/ws/issue" ) == 0 ) + else if( strncmp( (const char*)curhttp->pathbuffer, "/d/ws/issue", 11 ) == 0 ) { curhttp->rcb = 0; curhttp->rcbDat = (void*)&WSCommandData; diff --git a/embedded8266/common/mystuff.c b/embedded8266/common/mystuff.c index a9551ec..21a4aa4 100644 --- a/embedded8266/common/mystuff.c +++ b/embedded8266/common/mystuff.c @@ -4,7 +4,7 @@ #include "mystuff.h" -const char * enctypes[6] = { "open", "wep", "wpa", "wpa2", "wpa_wpa2", "max" }; +const char * enctypes[6] = { "open", "wep", "wpa", "wpa2", "wpa_wpa2", 0 }; char generic_print_buffer[384]; char generic_buffer[1500]; diff --git a/embedded8266/common/mystuff.h b/embedded8266/common/mystuff.h index 745fef7..122ca73 100644 --- a/embedded8266/common/mystuff.h +++ b/embedded8266/common/mystuff.h @@ -13,7 +13,7 @@ extern char generic_print_buffer[384]; -extern const char * enctypes[6];// = { "open", "wep", "wpa", "wpa2", "wpa_wpa2", "max" }; +extern const char * enctypes[6];// = { "open", "wep", "wpa", "wpa2", "wpa_wpa2", 0 }; #define printf( ... ) ets_sprintf( generic_print_buffer, __VA_ARGS__ ); uart0_sendStr( generic_print_buffer ); diff --git a/embedded8266/image.elf b/embedded8266/image.elf index d3807da..4bf4060 100755 Binary files a/embedded8266/image.elf and b/embedded8266/image.elf differ diff --git a/embedded8266/user/custom_commands.c b/embedded8266/user/custom_commands.c index 2bdfcbf..b49913f 100644 --- a/embedded8266/user/custom_commands.c +++ b/embedded8266/user/custom_commands.c @@ -2,6 +2,7 @@ #include #include #include +#include "mystuff.h" #include #include #include @@ -10,6 +11,8 @@ extern volatile uint8_t sounddata[]; extern volatile uint16_t soundhead; +#define CONFIGURABLES 16 //(plus1) + extern uint8_t RootNoteOffset; //Set to define what the root note is. 0 = A. uint8_t gDFTIIR = 6; uint8_t gFUZZ_IIR_BITS = 1; @@ -24,17 +27,37 @@ uint8_t gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR = 64; uint8_t gNOTE_FINAL_AMP = 12; uint8_t gNERF_NOTE_PORP = 15; uint8_t gUSE_NUM_LIN_LEDS = NUM_LIN_LEDS; +uint8_t gCOLORCHORD_ACTIVE = 1; +struct SaveLoad +{ + uint8_t configs[CONFIGURABLES]; +} settings; -uint8_t * gConfigurables[] = { &RootNoteOffset, &gDFTIIR, &gFUZZ_IIR_BITS, &gFILTER_BLUR_PASSES, +uint8_t gConfigDefaults[CONFIGURABLES] = { 0, 6, 1, 2, 3, 4, 7, 4, 2, 80, 64, 12, 15, NUM_LIN_LEDS, 1, 0 }; + +uint8_t * gConfigurables[CONFIGURABLES] = { &RootNoteOffset, &gDFTIIR, &gFUZZ_IIR_BITS, &gFILTER_BLUR_PASSES, &gSEMIBITSPERBIN, &gMAX_JUMP_DISTANCE, &gMAX_COMBINE_DISTANCE, &gAMP_1_IIR_BITS, &gAMP_2_IIR_BITS, &gMIN_AMP_FOR_NOTE, &gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR, &gNOTE_FINAL_AMP, - &gNERF_NOTE_PORP, &gUSE_NUM_LIN_LEDS, 0 }; + &gNERF_NOTE_PORP, &gUSE_NUM_LIN_LEDS, &gCOLORCHORD_ACTIVE, 0 }; -char * gConfigurableNames[] = { "gROOT_NOTE_OFFSET", "gDFTIIR", "gFUZZ_IIR_BITS", "gFILTER_BLUR_PASSES", +char * gConfigurableNames[CONFIGURABLES] = { "gROOT_NOTE_OFFSET", "gDFTIIR", "gFUZZ_IIR_BITS", "gFILTER_BLUR_PASSES", "gSEMIBITSPERBIN", "gMAX_JUMP_DISTANCE", "gMAX_COMBINE_DISTANCE", "gAMP_1_IIR_BITS", "gAMP_2_IIR_BITS", "gMIN_AMP_FOR_NOTE", "gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR", "gNOTE_FINAL_AMP", - "gNERF_NOTE_PORP", "gUSE_NUM_LIN_LEDS", 0 }; + "gNERF_NOTE_PORP", "gUSE_NUM_LIN_LEDS", "gCOLORCHORD_ACTIVE", 0 }; + +void ICACHE_FLASH_ATTR CustomStart( ) +{ + int i; + spi_flash_read( 0x3D000, (uint32*)&settings, sizeof( settings ) ); + for( i = 0; i < CONFIGURABLES; i++ ) + { + if( gConfigurables[i] ) + { + *gConfigurables[i] = settings.configs[i]; + } + } +} int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata, unsigned short len) { @@ -50,6 +73,7 @@ int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata, int whichSel = my_atoi( &pusrdata[2] ); uint16_t * which = 0; + uint16_t qty = FIXBINS; switch( whichSel ) { case 0: @@ -57,13 +81,14 @@ int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata, case 1: which = fuzzed_bins; break; case 2: + qty = FIXBPERO; which = folded_bins; break; default: buffend += ets_sprintf( buffend, "!CB" ); return buffend-buffer; } - buffend += ets_sprintf( buffend, "CB%d:%d:", whichSel, FIXBINS ); + buffend += ets_sprintf( buffend, "CB%d:%d:", whichSel, qty ); for( i = 0; i < FIXBINS; i++ ) { uint16_t samp = which[i]; @@ -76,6 +101,22 @@ int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata, } + case 'l': case 'L': //LEDs + { + int i, it = 0; + buffend += ets_sprintf( buffend, "CL:%d:", gUSE_NUM_LIN_LEDS ); + uint16_t toledsvals = gUSE_NUM_LIN_LEDS*3; + if( toledsvals > 600 ) toledsvals = 600; + for( i = 0; i < toledsvals; i++ ) + { + uint8_t samp = ledOut[it++]; + *(buffend++) = tohex1( samp>>4 ); + *(buffend++) = tohex1( samp&0x0f ); + } + return buffend-buffer; + } + + case 'm': case 'M': //Oscilloscope { int i, it = soundhead; @@ -118,6 +159,61 @@ int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata, } + case 's': case 'S': + { + switch (pusrdata[2] ) + { + + case 'd': case 'D': + { + int i; + for( i = 0; i < CONFIGURABLES-1; i++ ) + { + if( gConfigurables[i] ) + *gConfigurables[i] = gConfigDefaults[i]; + } + buffend += ets_sprintf( buffend, "CD" ); + return buffend-buffer; + } + + case 'r': case 'R': + { + int i; + for( i = 0; i < CONFIGURABLES-1; i++ ) + { + if( gConfigurables[i] ) + *gConfigurables[i] = settings.configs[i]; + } + buffend += ets_sprintf( buffend, "CSR" ); + return buffend-buffer; + } + + case 's': case 'S': + { + int i; + + for( i = 0; i < CONFIGURABLES-1; i++ ) + { + if( gConfigurables[i] ) + settings.configs[i] = *gConfigurables[i]; + } + + EnterCritical(); + ets_intr_lock(); + spi_flash_erase_sector( 0x3D000/4096 ); + spi_flash_write( 0x3D000, (uint32*)&settings, ((sizeof( settings )-1)&(~0xf))+0x10 ); + ets_intr_unlock(); + ExitCritical(); + + buffend += ets_sprintf( buffend, "CS" ); + return buffend-buffer; + } + } + buffend += ets_sprintf( buffend, "!CS" ); + return buffend-buffer; + } + + case 'v': case 'V': //ColorChord Values { @@ -125,10 +221,7 @@ int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata, { int i; - buffend += ets_sprintf( buffend, "CVR:rBASE_FREQ=%d:rDFREQ=%d:rOCTAVES=%d:rFIXBPERO=%d:NOTERANGE=%d:", - (int)BASE_FREQ, (int)DFREQ, (int)OCTAVES, (int)FIXBPERO, (int)(NOTERANGE) ); - buffend += ets_sprintf( buffend, "CVR:rMAXNOTES=%d:rNUM_LIN_LEDS=%d:rLIN_WRAPAROUND=%d:rLIN_WRAPAROUND=%d:", - (int)MAXNOTES, (int)NUM_LIN_LEDS, (int)LIN_WRAPAROUND, (int)LIN_WRAPAROUND ); + buffend += ets_sprintf( buffend, "CVR:" ); i = 0; while( gConfigurableNames[i] ) @@ -137,6 +230,11 @@ int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata, i++; } + buffend += ets_sprintf( buffend, "rBASE_FREQ=%d:rDFREQ=%d:rOCTAVES=%d:rFIXBPERO=%d:rNOTERANGE=%d:rSORT_NOTES=%d:", + (int)BASE_FREQ, (int)DFREQ, (int)OCTAVES, (int)FIXBPERO, (int)(NOTERANGE),(int)SORT_NOTES ); + buffend += ets_sprintf( buffend, "rMAXNOTES=%d:rNUM_LIN_LEDS=%d:rLIN_WRAPAROUND=%d:rLIN_WRAPAROUND=%d:", + (int)MAXNOTES, (int)NUM_LIN_LEDS, (int)LIN_WRAPAROUND, (int)LIN_WRAPAROUND ); + return buffend-buffer; } else if( pusrdata[2] == 'W' || pusrdata[2] == 'w' ) diff --git a/embedded8266/user/user_main.c b/embedded8266/user/user_main.c index ef43fd9..80e3f04 100644 --- a/embedded8266/user/user_main.c +++ b/embedded8266/user/user_main.c @@ -31,10 +31,16 @@ static volatile os_timer_t some_timer; static struct espconn *pUdpServer; +void EnterCritical(); +void ExitCritical(); extern volatile uint8_t sounddata[HPABUFFSIZE]; extern volatile uint16_t soundhead; uint16_t soundtail; +extern uint8_t gCOLORCHORD_ACTIVE; +static uint8_t hpa_running = 0; + +void ICACHE_FLASH_ATTR CustomStart( ); void user_rf_pre_init() { @@ -43,6 +49,8 @@ void user_rf_pre_init() //Call this once we've stacked together one full colorchord frame. static void NewFrame() { + if( !gCOLORCHORD_ACTIVE ) return; + //uint8_t led_outs[NUM_LIN_LEDS*3]; int i; HandleFrameInfo(); @@ -63,6 +71,18 @@ static void procTask(os_event_t *events) { system_os_post(procTaskPrio, 0, 0 ); + if( gCOLORCHORD_ACTIVE && !hpa_running ) + { + ExitCritical(); + hpa_running = 1; + } + + if( !gCOLORCHORD_ACTIVE && hpa_running ) + { + EnterCritical(); + hpa_running = 0; + } + CSTick( 0 ); //For profiling so we can see how much CPU is spent in this loop. @@ -97,7 +117,7 @@ static void procTask(os_event_t *events) int stat = wifi_station_get_connect_status(); -// printf( "STAT: %d\n", stat ); + //printf( "STAT: %d %d\n", stat, wifi_get_opmode() ); if( stat == STATION_WRONG_PASSWORD || stat == STATION_NO_AP_FOUND || stat == STATION_CONNECT_FAIL ) { @@ -142,7 +162,7 @@ static void udpserver_recv(void *arg, char *pusrdata, unsigned short len) // uint8_t ledout[] = { 0x00, 0xff, 0xaa, 0x00, 0xff, 0xaa, }; uart0_sendStr("X"); - ws2812_push( pusrdata, len ); + ws2812_push( pusrdata+3, len ); } void ICACHE_FLASH_ATTR charrx( uint8_t c ) @@ -158,11 +178,37 @@ void ICACHE_FLASH_ATTR user_init(void) uart0_sendStr("\r\nCustom Server\r\n"); +// system_restore(); + CustomStart(); + #ifdef PROFILE GPIO_OUTPUT_SET(GPIO_ID_PIN(0), 0); #endif + int opmode = wifi_get_opmode(); + printf( "Opmode: %d\n", opmode ); + if( opmode == 1 ) + { + struct station_config sc; + wifi_station_get_config(&sc); + printf( "Station mode: \"%s\":\"%s\" (bssid_set:%d)\n", sc.ssid, sc.password, sc.bssid_set ); + if( sc.ssid[0] == 0 && !sc.bssid_set ) + { + wifi_set_opmode( 2 ); + opmode = 2; + } + else + { + wifi_station_connect(); + } + } + if( opmode == 2 ) + { + struct softap_config sc; + wifi_softap_get_config(&sc); + printf( "SoftAP mode: \"%s\":\"%s\"\n", sc.ssid, sc.password ); + } - wifi_set_opmode( 2 ); //We broadcast our ESSID, wait for peopel to join. +// wifi_set_opmode( 2 ); //We broadcast our ESSID, wait for peopel to join. /* struct station_config stationConf; @@ -202,6 +248,7 @@ void ICACHE_FLASH_ATTR user_init(void) InitColorChord(); //Init colorchord StartHPATimer(); //Init the high speed ADC timer. + hpa_running = 1; ws2812_init(); diff --git a/embedded8266/web/Makefile b/embedded8266/web/Makefile index bfeddb3..1c65988 100644 --- a/embedded8266/web/Makefile +++ b/embedded8266/web/Makefile @@ -1,9 +1,12 @@ all : execute_reflash page.dat push +IP?=192.168.4.1 + mfsmaker : mfsmaker.c gcc -o $@ $^ page.dat : mfsmaker page +# cat to_compress/*.js | gzip -9 > page/compressed.js.gz ./mfsmaker page page.dat pushtodev : pushtodev.c @@ -13,7 +16,7 @@ execute_reflash : execute_reflash.c md5.c gcc -o $@ $^ push : pushtodev page.dat - ./pushtodev 192.168.4.1 1048576 page.dat + ./pushtodev $(IP) 1048576 page.dat clean : rm -rf mfsmaker page.dat pushtodev execute_reflash diff --git a/embedded8266/web/execute_reflash.c b/embedded8266/web/execute_reflash.c index 652ccc6..ef83c67 100644 --- a/embedded8266/web/execute_reflash.c +++ b/embedded8266/web/execute_reflash.c @@ -127,7 +127,8 @@ uint32_t Push( uint32_t offset, const char * file ) fprintf( stderr, "Error: Timeout in communications.\n" ); exit( -6 ); } - devo += sendsize; + if( reads != 0 ) + devo += sendsize; } return devo; diff --git a/embedded8266/web/page/colorchord.html b/embedded8266/web/page/colorchord.html deleted file mode 100644 index e3c7494..0000000 --- a/embedded8266/web/page/colorchord.html +++ /dev/null @@ -1,103 +0,0 @@ - - -ColorChord Control Panel - - - - - - -

ColorChord: Embedded

-
- - - - - - - - - - - - - - - - - - - - - - -
- -
-
-
-
- -
-
-System Info...
line2
line3 -
- -
-
-Current Configuration:
- - - - - - - -
Type:Station (Connect to infrastructure)
AP (Broadcast a new AP)
SSID:
PASS:
Enc:Open
WPA2-PSK (Ignored in Station mode)
Chan: (Ignored in Station mode)
-Scanned Stations: -
- -
- -
-
-Command: -
- -
- -
- - - - - - - - - - - - -
012345...12131415
- -
-
- -
- -
-
- -
- - - - - - diff --git a/embedded8266/web/page/colorchord.js b/embedded8266/web/page/colorchord.js deleted file mode 100644 index 532447a..0000000 --- a/embedded8266/web/page/colorchord.js +++ /dev/null @@ -1,477 +0,0 @@ -var wsUri = "ws://" + location.host + "/d/ws/issue"; -var output; -var websocket; -var commsup = 0; - -//Push objects that have: -// .request -// .callback = function( ref (this object), data ); - -var workqueue = []; -var workarray = {}; -var lastitem; - -function QueueOperation( command, callback ) -{ - if( workarray[command] == 1 ) - { - return; - } - - workarray[command] = 1; - var vp = new Object(); - vp.callback = callback; - vp.request = command; - workqueue.push( vp ); -} - - -function init() -{ - $( ".collapsible" ).each(function( index ) { - if( localStorage["sh" + this.id] > 0.5 ) - { - $( this ).show().toggleClass( 'opened' ); -// console.log( "OPEN: " + this.id ); - } - }); - - $("#custom_command_response").val( "" ); - - - output = document.getElementById("output"); - Ticker(); - - KickWifiTicker(); - GPIODataTickerStart(); - KickOscilloscope(); - KickDFT(); -} - -function StartWebSocket() -{ - output.innerHTML = "Connecting..."; - if( websocket ) websocket.close(); - workqueue = []; - lastitem = null; - websocket = new WebSocket(wsUri); - websocket.onopen = function(evt) { onOpen(evt) }; - websocket.onclose = function(evt) { onClose(evt) }; - websocket.onmessage = function(evt) { onMessage(evt) }; - websocket.onerror = function(evt) { onError(evt) }; -} - -function onOpen(evt) -{ - doSend('e' ); -} - -function onClose(evt) -{ - $('#SystemStatusClicker').css("color", "red" ); - commsup = 0; -} - -var msg = 0; -var tickmessage = 0; -var lasthz = 0; - -function Ticker() -{ - lasthz = (msg - tickmessage); - tickmessage = msg; - if( lasthz == 0 ) - { - $('#SystemStatusClicker').css("color", "red" ); - commsup = 0; - StartWebSocket(); - } - - setTimeout( Ticker, 1000 ); -} - -function onMessage(evt) -{ - msg++; - output.innerHTML = "

Messages: " + msg + "

Hz:" + lasthz + "

"; - if( commsup != 1 ) - { - commsup = 1; - $('#SystemStatusClicker').css("color", "green" ); - } - - if( lastitem && lastitem.callback ) - { - lastitem.callback( lastitem, evt.data ); - lastitem = null; - } - - if( workqueue.length ) - { - var elem = workqueue.shift(); - delete workarray[elem.request]; - if( elem.request ) - { - doSend( elem.request ); - lastitem = elem; - return; - } - } - - - doSend('e'); -} - -function onError(evt) -{ - $('#SystemStatusClicker').css("color", "red" ); - commsup = 0; -} - -function doSend(message) -{ - websocket.send(message); -} - -function IsTabOpen( objname ) -{ - var obj = $( "#" + objname ); - var opened = obj.is( '.opened' ); - return opened != 0; -} - -function ShowHideEvent( objname ) -{ - var obj = $( "#" + objname ); - obj.slideToggle( 'fast' ).toggleClass( 'opened' ); - var opened = obj.is( '.opened' ); - localStorage["sh" + objname] = opened?1:0; - return opened!=0; -} - - -function IssueCustomCommand() -{ - QueueOperation( $("#custom_command").val(), function( req,data) { $("#custom_command_response").val( data ); } ); -} - - - -window.addEventListener("load", init, false); - - - - - - - -///////// Various functions that are not core appear down here. - -is_oscilloscope_running = false; -pause_oscilloscope = false; - -function KickOscilloscope() -{ - $( "#OScopePauseButton" ).css( "background-color", (is_oscilloscope_running&&pause_oscilloscope)?"green":"red" ); - if( !is_oscilloscope_running && !pause_oscilloscope) - OScopeDataTicker(); -} - -function ToggleOScopePause() -{ - pause_oscilloscope = !pause_oscilloscope; - KickOscilloscope(); -} - -function GotOScope(req,data) -{ - var canvas = document.getElementById('OScopeCanvas'); - var ctx = canvas.getContext('2d'); - var h = canvas.height; - var w = canvas.width; - if( ctx.canvas.width != canvas.clientWidth ) ctx.canvas.width = canvas.clientWidth; - if( ctx.canvas.height != canvas.clientHeight ) ctx.canvas.height = canvas.clientHeight; - - $( "#OScopePauseButton" ).css( "background-color", "green" ); - - var secs = data.split( ":" ); - - var samps = Number( secs[1] ); - var data = secs[2]; - var lastsamp = parseInt( data.substr(0,2),16 ); - ctx.clearRect( 0, 0, canvas.width, canvas.height ); - ctx.beginPath(); - for( var i = 0; i < samps; i++ ) - { - var x2 = (i+1) * canvas.clientWidth / samps; - var samp = parseInt( data.substr(i*2+2,2),16 ); - var y2 = ( 1.-samp / 255 ) * canvas.clientHeight; - - if( i == 0 ) - { - var x1 = i * canvas.clientWidth / samps; - var y1 = ( 1.-lastsamp / 255 ) * canvas.clientHeight; - ctx.moveTo( x1, y1 ); - } - - ctx.lineTo( x2, y2 ); - - lastsamp = samp; - } - ctx.stroke(); - - var samp = parseInt( data.substr(i*2,2),16 ); - - OScopeDataTicker(); -} - -function OScopeDataTicker() -{ - if( IsTabOpen('OScope') && !pause_oscilloscope ) - { - is_oscilloscope_running = true; - QueueOperation( "CM", GotOScope ); - } - else - { - is_oscilloscope_running = 0; - } - $( "#OScopePauseButton" ).css( "background-color", (is_oscilloscope_running&&!pause_oscilloscope)?"green":"red" ); -} - - - - - - - - - -is_dft_running = false; - -function KickDFT() -{ - if( !is_dft_running ) - DFTDataTicker(); - -} - -function GotDFT(req,data) -{ - var canvas = document.getElementById('DFTCanvas'); - var ctx = canvas.getContext('2d'); - var h = canvas.height; - var w = canvas.width; - if( ctx.canvas.width != canvas.clientWidth ) ctx.canvas.width = canvas.clientWidth; - if( ctx.canvas.height != canvas.clientHeight ) ctx.canvas.height = canvas.clientHeight; - - var secs = data.split( ":" ); - - var samps = Number( secs[1] ); - var data = secs[2]; - var lastsamp = parseInt( data.substr(0,4),16 ); - ctx.clearRect( 0, 0, canvas.width, canvas.height ); - ctx.beginPath(); - for( var i = 0; i < samps; i++ ) - { - var x2 = (i+1) * canvas.clientWidth / samps; - var samp = parseInt( data.substr(i*4+4,4),16 ); - var y2 = ( 1.-samp / 2047 ) * canvas.clientHeight; - - if( i == 0 ) - { - var x1 = i * canvas.clientWidth / samps; - var y1 = ( 1.-lastsamp / 2047 ) * canvas.clientHeight; - ctx.moveTo( x1, y1 ); - } - - ctx.lineTo( x2, y2 ); - - lastsamp = samp; - } - ctx.stroke(); - - var samp = parseInt( data.substr(i*2,2),16 ); - - DFTDataTicker(); -} - -function DFTDataTicker() -{ - if( IsTabOpen('DFT') ) - { - is_dft_running = true; - QueueOperation( "CB", GotDFT ); - } - else - { - is_dft_running = 0; - } -} - - - - - - - - - - - - - - -did_wifi_get_config = false; -is_data_ticker_running = false; - -function KickWifiTicker() -{ - if( !is_data_ticker_running ) - WifiDataTicker(); -} - -function WifiDataTicker() -{ - if( IsTabOpen('WifiSettings') ) - { - is_data_ticker_running = true; - - if( !did_wifi_get_config ) - { - QueueOperation( "WI", function(req,data) - { - var params = data.split( "\t" ); - - document.wifisection.wifitype.value = Number( params[0].substr(2) ); - document.wifisection.wificurname.value = params[1]; - document.wifisection.wificurpassword.value = params[2]; - document.wifisection.wificurenctype.value = params[3]; - document.wifisection.wificurchannel.value = Number( params[4] ); - - did_wifi_get_config = true; - } ); - } - - - QueueOperation( "WR", function(req,data) { - var lines = data.split( "\n" ); - var innerhtml; - if( lines.length < 3 ) - { - innerhtml = "No APs found. Did you scan?"; - } - else - { - innerhtml = "" - for( i = 1; i < lines.length-1; i++ ) - { - var dats = lines[i].split( "\t" ); - innerhtml += ""; - } - } - innerhtml += "
SSIDMACRSChEnc
" + dats[0] + "" + dats[1] + "" + dats[2] + "" + dats[3] + "" + dats[4] + "
"; - document.getElementById("WifiStations").innerHTML = innerhtml; - } ); - setTimeout( WifiDataTicker, 500 ); - } - else - { - is_data_ticker_running = 0; - } -} - -function ChangeWifiConfig() -{ - - var st = "W"; - st += document.wifisection.wifitype.value; - st += ":" + document.wifisection.wificurname.value; - st += ":" + document.wifisection.wificurpassword.value; - QueueOperation( st ); - did_wifi_get_config = false; -} - - - - -function TwiddleGPIO( gp ) -{ - var st = "GF"; - st += gp; - QueueOperation( st ); -} - -function GPIOInput( gp ) -{ - var st = "GI"; - st += gp; - QueueOperation( st ); -} - -function GPIOUpdate(req,data) { - var secs = data.split( ":" ); - var op = 0; - var n = Number(secs[2]); - var m = Number(secs[1]); - - for( op = 0; op < 16; op++ ) - { - var b = $( "#ButtonGPIO" + op ); - if( b ) - { - if( 1< - -Hello! This is a test page.
+ + +ColorChord Control Panel + + + + + + +

ColorChord: Embedded

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+
+ +
+
+

Welcome to the ColorChord: Embedded ESP8266 Web-based GUI.

+

This GUI uses WebSockets, and has only been tested under the newest (as of August, 2015) Chrome and Firefox browsers.

+

For more information about ColorChord, visit it on github, here: https://github.com/cnlohr/colorchord

+
+ +
+
+Current Configuration: (May deviate from default configuration, reset here if in doubt)
+ + + + + + + +
Type:Station (Connect to infrastructure)
AP (Broadcast a new AP)
SSID:
PASS:
MAC: (Ignored in softAP mode)
Chan: (Ignored in Station mode)
(Automatically saves to flash)
+Scanned Stations: +
+ +
+ +
+
+Command: +
+ +
+ +
+ + + + + + + + + + + + +
012345...12131415
+ +
+
+ +
+ +
+
+ + +
+ +
+ +
+
+ +
+ +
+
+ +
+
+ +
+
+ + + + - - - diff --git a/embedded8266/web/page/jquery-2.1.4.min.js.gz b/embedded8266/web/page/jquery-2.1.4.min.js.gz index 23f28ab..b9125eb 100644 Binary files a/embedded8266/web/page/jquery-2.1.4.min.js.gz and b/embedded8266/web/page/jquery-2.1.4.min.js.gz differ diff --git a/embedded8266/web/page/main.js b/embedded8266/web/page/main.js new file mode 100644 index 0000000..c6e4619 --- /dev/null +++ b/embedded8266/web/page/main.js @@ -0,0 +1,884 @@ +var wsUri = "ws://" + location.host + "/d/ws/issue"; +var output; +var websocket; +var commsup = 0; +globalParams = {}; + +//Push objects that have: +// .request +// .callback = function( ref (this object), data ); + +var workqueue = []; +var wifilines = []; +var workarray = {}; +var lastitem; + +function QueueOperation( command, callback ) +{ + if( workarray[command] == 1 ) + { + return; + } + + workarray[command] = 1; + var vp = new Object(); + vp.callback = callback; + vp.request = command; + workqueue.push( vp ); +} + + +function init() +{ + $( ".collapsible" ).each(function( index ) { + if( localStorage["sh" + this.id] > 0.5 ) + { + $( this ).show().toggleClass( 'opened' ); +// console.log( "OPEN: " + this.id ); + } + }); + + $("#custom_command_response").val( "" ); + + + output = document.getElementById("output"); + Ticker(); + + KickWifiTicker(); + GPIODataTickerStart(); + KickOscilloscope(); + KickDFT(); + KickNotes(); + KickLEDs(); +} + +function StartWebSocket() +{ + output.innerHTML = "Connecting..."; + if( websocket ) websocket.close(); + workarray = {}; + workqueue = []; + lastitem = null; + websocket = new WebSocket(wsUri); + websocket.onopen = function(evt) { onOpen(evt) }; + websocket.onclose = function(evt) { onClose(evt) }; + websocket.onmessage = function(evt) { onMessage(evt) }; + websocket.onerror = function(evt) { onError(evt) }; +} + +function onOpen(evt) +{ + doSend('e' ); +} + +function onClose(evt) +{ + $('#SystemStatusClicker').css("color", "red" ); + commsup = 0; +} + +var msg = 0; +var tickmessage = 0; +var lasthz = 0; + +function Ticker() +{ + setTimeout( Ticker, 1000 ); + + lasthz = (msg - tickmessage); + tickmessage = msg; + if( lasthz == 0 ) + { + $('#SystemStatusClicker').css("color", "red" ); + $('#SystemStatusClicker').prop( "value", "System Offline" ); + commsup = 0; + StartWebSocket(); + } + else + { + $('#SystemStatusClicker').prop( "value", "System " + lasthz + "Hz" ); + } + + + QueueOperation( "CVR", ReceiveParameters ); +} + + +function onMessage(evt) +{ + msg++; + + + if( commsup != 1 ) + { + commsup = 1; + $('#SystemStatusClicker').css("color", "green" ); + } + + + if( lastitem ) + { + if( lastitem.callback ) + { + lastitem.callback( lastitem, evt.data ); + lastitem = null; + } + } + else + { + output.innerHTML = "

Messages: " + msg + "

RSSI: " + evt.data.substr(2) + "

"; + } + + + if( workqueue.length ) + { + var elem = workqueue.shift(); + delete workarray[elem.request]; + + if( elem.request ) + { + doSend( elem.request ); + lastitem = elem; + return; + } + } + + doSend('wx'); //Request RSSI. +} + +function onError(evt) +{ + $('#SystemStatusClicker').css("color", "red" ); + commsup = 0; +} + +function doSend(message) +{ + websocket.send(message); +} + +function IsTabOpen( objname ) +{ + var obj = $( "#" + objname ); + var opened = obj.is( '.opened' ); + return opened != 0; +} + +function ShowHideEvent( objname ) +{ + var obj = $( "#" + objname ); + obj.slideToggle( 'fast' ).toggleClass( 'opened' ); + var opened = obj.is( '.opened' ); + localStorage["sh" + objname] = opened?1:0; + return opened!=0; +} + + +function IssueCustomCommand() +{ + QueueOperation( $("#custom_command").val(), function( req,data) { $("#custom_command_response").val( data ); } ); +} + + + +window.addEventListener("load", init, false); + + + + + + + +///////// Various functions that are not core appear down here. + + + + + + + + + + + +function ChangeParam( p ) +{ + var num = Number( p.value ); + var elem = p.id.substr( 5 ); + QueueOperation( "CVW:" + elem + ":" + num ); +} + + +var hasCreateParams = false; +function ReceiveParameters(req,data) { + var elems = data.split( ":" ); + + for( var v = 0; v < elems.length; v++ ) + { + var pair = elems[v].split( "=" ); + if( pair.length == 2 ) + { + globalParams[pair[0]] = Number( pair[1] ); + } + } + + if( !hasCreateParams ) + { + hasCreateParams = true; + var htv = ""; + + for( var v in globalParams ) + { + var vp = globalParams[v]; + htv += ""; + } + + $("#InnerParameters").html( htv + "
ValueParameter
" + v + "
" ); + + for( var v in globalParams ) + { + if( v.substr(0,1) == 'r' ) + { + $("#param" + v).prop( "disabled", true ); + } + } + + } + + for( var v in globalParams ) + { + var vp = globalParams[v]; + var p = $("#param"+v); + if( !p.is(":focus" ) ) + p.val(vp); + } + +} + + + + + + + + + +is_oscilloscope_running = false; +pause_oscilloscope = false; + +function KickOscilloscope() +{ + $( "#OScopePauseButton" ).css( "background-color", (is_oscilloscope_running&&pause_oscilloscope)?"green":"red" ); + if( !is_oscilloscope_running && !pause_oscilloscope) + OScopeDataTicker(); +} + +function ToggleOScopePause() +{ + pause_oscilloscope = !pause_oscilloscope; + KickOscilloscope(); +} + +function GotOScope(req,data) +{ + var canvas = document.getElementById('OScopeCanvas'); + var ctx = canvas.getContext('2d'); + var h = canvas.height; + var w = canvas.width; + if( ctx.canvas.width != canvas.clientWidth ) ctx.canvas.width = canvas.clientWidth; + if( ctx.canvas.height != canvas.clientHeight ) ctx.canvas.height = canvas.clientHeight; + + $( "#OScopePauseButton" ).css( "background-color", "green" ); + + var secs = data.split( ":" ); + + var samps = Number( secs[1] ); + var data = secs[2]; + var lastsamp = parseInt( data.substr(0,2),16 ); + ctx.clearRect( 0, 0, canvas.width, canvas.height ); + ctx.beginPath(); + for( var i = 0; i < samps; i++ ) + { + var x2 = (i+1) * canvas.clientWidth / samps; + var samp = parseInt( data.substr(i*2+2,2),16 ); + var y2 = ( 1.-samp / 255 ) * canvas.clientHeight; + + if( i == 0 ) + { + var x1 = i * canvas.clientWidth / samps; + var y1 = ( 1.-lastsamp / 255 ) * canvas.clientHeight; + ctx.moveTo( x1, y1 ); + } + + ctx.lineTo( x2, y2 ); + + lastsamp = samp; + } + ctx.stroke(); + + var samp = parseInt( data.substr(i*2,2),16 ); + + OScopeDataTicker(); +} + +function OScopeDataTicker() +{ + if( IsTabOpen('OScope') && !pause_oscilloscope ) + { + is_oscilloscope_running = true; + QueueOperation( "CM", GotOScope ); + } + else + { + is_oscilloscope_running = 0; + } + $( "#OScopePauseButton" ).css( "background-color", (is_oscilloscope_running&&!pause_oscilloscope)?"green":"red" ); +} + + + + + + + + + +is_dft_running = false; +pause_dft = false; + +function KickDFT() +{ + $( "#DFTPauseButton" ).css( "background-color", (is_dft_running&&!pause_dft)?"green":"red" ); + if( !is_dft_running && !pause_dft ) + DFTDataTicker(); +} + + + +function ToggleDFTPause() +{ + pause_dft = !pause_dft; + KickDFT(); +} + +function GotDFT(req,data) +{ + var canvas = document.getElementById('DFTCanvas'); + var ctx = canvas.getContext('2d'); + var h = canvas.height; + var w = canvas.width; + if( ctx.canvas.width != canvas.clientWidth ) ctx.canvas.width = canvas.clientWidth; + if( ctx.canvas.height != canvas.clientHeight ) ctx.canvas.height = canvas.clientHeight; + + var secs = data.split( ":" ); + + $( "#DFTPauseButton" ).css( "background-color", "green" ); + + var samps = Number( secs[1] ); + var data = secs[2]; + var lastsamp = parseInt( data.substr(0,4),16 ); + ctx.clearRect( 0, 0, canvas.width, canvas.height ); + ctx.beginPath(); + + for( var i = 0; i < samps; i++ ) + { + var x2 = i * canvas.clientWidth / samps; + var samp = parseInt( data.substr(i*4,4),16 ); + var y2 = ( 1.-samp / 2047 ) * canvas.clientHeight; + + ctx.fillStyle = CCColor( i % globalParams["rFIXBPERO"] ); + ctx.fillRect( x2, y2, canvas.clientWidth / samps, canvas.clientHeight-y2 ); + + ctx.strokeStyle = "#000000"; + ctx.strokeRect( x2, y2, canvas.clientWidth / samps, canvas.clientHeight-y2 ); + } + ctx.stroke(); + + var samp = parseInt( data.substr(i*2,2),16 ); + + DFTDataTicker(); +} + +function DFTDataTicker() +{ + if( IsTabOpen('DFT') && !pause_dft ) + { + is_dft_running = true; + QueueOperation( "CB" + $("#WhichCanvas").val(), GotDFT ); + } + else + { + is_dft_running = 0; + } + $( "#DFTPauseButton" ).css( "background-color", (is_dft_running&&!pause_dft)?"green":"red" ); +} + + + + + + + +is_leds_running = false; +pause_led = false; + +function KickLEDs() +{ + $( "#LEDPauseButton" ).css( "background-color", (is_leds_running&&!pause_led)?"green":"red" ); + + if( !is_leds_running && !pause_led ) + LEDDataTicker(); + +} + +function ToggleLEDPause() +{ + pause_led = !pause_led; + KickLEDs(); +} + + +function GotLED(req,data) +{ + var ls = document.getElementById('LEDCanvasHolder'); + var canvas = document.getElementById('LEDCanvas'); + var ctx = canvas.getContext('2d'); + var h = ls.height; + var w = ls.width; + if( canvas.width != ls.clientWidth-10 ) canvas.width = ls.clientWidth-10; + if( ctx.canvas.width != canvas.clientWidth ) ctx.canvas.width = canvas.clientWidth; + + var secs = data.split( ":" ); + + $( "#LEDPauseButton" ).css( "background-color", "green" ); + + var samps = Number( secs[1] ); + var data = secs[2]; + var lastsamp = parseInt( data.substr(0,4),16 ); + ctx.clearRect( 0, 0, canvas.width, canvas.height ); + + for( var i = 0; i < samps; i++ ) + { + var x2 = i * canvas.clientWidth / samps; + var samp = data.substr(i*6,6); + var y2 = ( 1.-samp / 2047 ) * canvas.clientHeight; + + ctx.fillStyle = "#" + samp.substr( 2, 2 ) + samp.substr( 0, 2 ) + samp.substr( 4, 2 ); + ctx.lineWidth = 0; + ctx.fillRect( x2, 0, canvas.clientWidth / samps+1, canvas.clientHeight ); + } + + var samp = parseInt( data.substr(i*2,2),16 ); + + LEDDataTicker(); +} + +function LEDDataTicker() +{ + if( IsTabOpen('LEDs') && !pause_led ) + { + is_leds_running = true; + QueueOperation( "CL", GotLED ); + } + else + { + is_leds_running = 0; + } + $( "#LEDPauseButton" ).css( "background-color", (is_leds_running&&!pause_led)?"green":"red" ); + +} + + + + + + + + + + +is_notes_running = false; +pause_notes = false; + +function KickNotes() +{ + $( "#NotesPauseButton" ).css( "background-color", (is_notes_running&&!pause_notes)?"green":"red" ); + + if( !is_notes_running && !pause_notes ) + NotesTicker(); +} + + + +function ToggleNotesPause() +{ + pause_notes = !pause_notes; + KickNotes(); +} + +function GotNotes(req,data) +{ + var canvas = document.getElementById('NotesCanvas'); + var ctx = canvas.getContext('2d'); + + var secs = data.split( ":" ); + + var elems = Number(secs[1] ); + + ctx.canvas.width = 400; + ctx.canvas.height = elems*25; + + + $( "#NotesPauseButton" ).css( "background-color", "green" ); + + var data = secs[2]; + ctx.fillStyle = "#000000"; + ctx.font = "18px serif" + ctx.fillRect( 0, 0, canvas.width, canvas.height ); + + for( var i = 0; i < elems; i++ ) + { + var peak = parseInt( data.substr(i*12+0,2),16 ); + var amped = parseInt( data.substr(i*12+2,4),16 ); + var amped2 = parseInt( data.substr(i*12+6,4),16 ); + var jump = parseInt( data.substr(i*12+10,2),16 ); + + if( peak == 255 ) + { + ctx.fillStyle = "#ffffff"; + ctx.fillText( jump, 10, i*25 + 20 ); + continue; + } + + ctx.fillStyle = CCColorDetail( peak ); + ctx.lineWidth = 0; + ctx.fillRect( 0, i*25, 100,25); + ctx.fillRect( 101, i*25, amped/200,25); + ctx.fillRect( 229, i*25, amped2/200,25); + + ctx.fillStyle = "#000000"; + ctx.fillText( peak, 10, i*25 + 20 ); + ctx.fillStyle = "#ffffff"; + ctx.fillText( amped, 121, i*25 + 20 ); + ctx.fillText( amped2, 240, i*25 + 20 ); + } + + var samp = parseInt( data.substr(i*2,2),16 ); + + NotesTicker(); +} + +function NotesTicker() +{ + if( IsTabOpen('Notes')&& !pause_notes ) + { + is_notes_running = true; + QueueOperation( "CN", GotNotes ); + } + else + { + is_notes_running = 0; + } + $( "#NotesPauseButton" ).css( "background-color", (is_notes_running&&!pause_notes)?"green":"red" ); +} + + + + + + +did_wifi_get_config = false; +is_data_ticker_running = false; + +function KickWifiTicker() +{ + if( !is_data_ticker_running ) + WifiDataTicker(); +} + +function BSSIDClick( i ) +{ + var tlines = wifilines[i]; + document.wifisection.wifitype.value = 1; + document.wifisection.wificurname.value = tlines[0].substr(1); + document.wifisection.wificurpassword.value = ""; + document.wifisection.wifimac.value = tlines[1]; + document.wifisection.wificurchannel.value = 0; + + return false; +} + +function WifiDataTicker() +{ + if( IsTabOpen('WifiSettings') ) + { + is_data_ticker_running = true; + + if( !did_wifi_get_config ) + { + QueueOperation( "WI", function(req,data) + { + var params = data.split( "\t" ); + + document.wifisection.wifitype.value = Number( params[0].substr(2) ); + document.wifisection.wificurname.value = params[1]; + document.wifisection.wificurpassword.value = params[2]; + document.wifisection.wifimac.value = params[3]; + document.wifisection.wificurchannel.value = Number( params[4] ); + + did_wifi_get_config = true; + } ); + } + + QueueOperation( "WR", function(req,data) { + var lines = data.split( "\n" ); + var innerhtml; + if( lines.length < 3 ) + { + innerhtml = "No APs found. Did you scan?"; + } + else + { + innerhtml = "" + wifilines = []; + for( i = 1; i < lines.length-1; i++ ) + { + tlines = lines[i].split( "\t" ); + wifilines.push(tlines); + var bssidval = "" + tlines[1]; + innerhtml += ""; + } + } + innerhtml += "
SSIDMACRSChEnc
" + tlines[0].substr(1) + "" + bssidval + "" + tlines[2] + "" + tlines[3] + "" + tlines[4] + "
"; + document.getElementById("WifiStations").innerHTML = innerhtml; + } ); + setTimeout( WifiDataTicker, 500 ); + } + else + { + is_data_ticker_running = 0; + } +} + +function ChangeWifiConfig() +{ + + var st = "W"; + st += document.wifisection.wifitype.value; + st += "\t" + document.wifisection.wificurname.value; + st += "\t" + document.wifisection.wificurpassword.value; + st += "\t" + document.wifisection.wifimac.value; + st += "\t" + document.wifisection.wificurchannel.value; + QueueOperation( st ); + did_wifi_get_config = false; +} + + + + +function TwiddleGPIO( gp ) +{ + var st = "GF"; + st += gp; + QueueOperation( st ); +} + +function GPIOInput( gp ) +{ + var st = "GI"; + st += gp; + QueueOperation( st ); +} + +function GPIOUpdate(req,data) { + var secs = data.split( ":" ); + var op = 0; + var n = Number(secs[2]); + var m = Number(secs[1]); + + for( op = 0; op < 16; op++ ) + { + var b = $( "#ButtonGPIO" + op ); + if( b ) + { + if( 1<> 1; + } + else if( renote < (third<<1) ) + { + //Red to Blue + hue = (third-renote); + } + else + { + //hue = ((((65535-renote)>>8) * (uint32_t)(third>>8)) >> 1) + (third<<1); + hue = (((65536-renote)<<16) / (third<<1)) + (third>>1); // ((((65535-renote)>>8) * (uint32_t)(third>>8)) >> 1) + (third<<1); + } + hue >>= 8; + + return EHSVtoHEX( hue, sat, val ); +} + +function EHSVtoHEX( hue, sat, val ) //0..255 for all +{ + var SIXTH1 = 43; + var SIXTH2 = 85; + var SIXTH3 = 128; + var SIXTH4 = 171; + var SIXTH5 = 213; + + var or = 0, og = 0, ob = 0; + + hue -= SIXTH1; //Off by 60 degrees. + + hue = (hue+256)%256; + //TODO: There are colors that overlap here, consider + //tweaking this to make the best use of the colorspace. + + if( hue < SIXTH1 ) //Ok: Yellow->Red. + { + or = 255; + og = 255 - (hue * 255) / (SIXTH1); + } + else if( hue < SIXTH2 ) //Ok: Red->Purple + { + or = 255; + ob = hue*255 / SIXTH1 - 255; + } + else if( hue < SIXTH3 ) //Ok: Purple->Blue + { + ob = 255; + or = ((SIXTH3-hue) * 255) / (SIXTH1); + } + else if( hue < SIXTH4 ) //Ok: Blue->Cyan + { + ob = 255; + og = (hue - SIXTH3)*255 / SIXTH1; + } + else if( hue < SIXTH5 ) //Ok: Cyan->Green. + { + og = 255; + ob = ((SIXTH5-hue)*255) / SIXTH1; + } + else //Green->Yellow + { + og = 255; + or = (hue - SIXTH5) * 255 / SIXTH1; + } + + var rv = val; + if( rv > 128 ) rv++; + var rs = sat; + if( rs > 128 ) rs++; + + //or, og, ob range from 0...255 now. + //Need to apply saturation and value. + + or = (or * val)>>8; + og = (og * val)>>8; + ob = (ob * val)>>8; + + //OR..OB == 0..65025 + or = or * rs + 255 * (256-rs); + og = og * rs + 255 * (256-rs); + ob = ob * rs + 255 * (256-rs); +//printf( "__%d %d %d =-> %d\n", or, og, ob, rs ); + + or >>= 8; + og >>= 8; + ob >>= 8; + + if( or > 255 ) or = 255; + if( og > 255 ) og = 255; + if( ob > 255 ) ob = 255; + + return "#" + tohex8(og) + tohex8(or) + tohex8(ob); +} + +function tohex8( c ) +{ + var hex = c.toString(16); + return hex.length == 1 ? "0" + hex : hex; +} diff --git a/embedded8266/web/page/test.txt b/embedded8266/web/page/test.txt deleted file mode 100644 index 9daeafb..0000000 --- a/embedded8266/web/page/test.txt +++ /dev/null @@ -1 +0,0 @@ -test diff --git a/embedded8266/web/page/wstest.html b/embedded8266/web/page/wstest.html deleted file mode 100644 index cbc343c..0000000 --- a/embedded8266/web/page/wstest.html +++ /dev/null @@ -1,10 +0,0 @@ - - -WebSocket Test - - - -

WebSocket Test

-
- - diff --git a/embedded8266/web/page/wstest.js b/embedded8266/web/page/wstest.js deleted file mode 100644 index 661ed2c..0000000 --- a/embedded8266/web/page/wstest.js +++ /dev/null @@ -1,86 +0,0 @@ -var wsUri = "ws://" + location.host + "/d/ws/echo"; - -var output; - -function init() -{ - output = document.getElementById("output"); - console.log( wsUri ); - testWebSocket(); -} - -function testWebSocket() -{ - websocket = new WebSocket(wsUri); - websocket.onopen = function(evt) { onOpen(evt) }; - websocket.onclose = function(evt) { onClose(evt) }; - websocket.onmessage = function(evt) { onMessage(evt) }; - websocket.onerror = function(evt) { onError(evt) }; -} - -function repeatsend() -{ - doSend('Hello!' ); - setTimeout( repeatsend, 1000 ); -} - -function onOpen(evt) -{ - writeToScreen("CONNECTED"); - doSend('Hello.' ); - //repeatsend(); - // doSend('{"args": ["entity", 1000], "kwargs": {}, "op": "ClientUpdater__requestUpdates", "seq": 1, "context": ["ClientUpdater", 0]}'); -} - -function onClose(evt) -{ - writeToScreen("DISCONNECTED"); -} - -var msg = 0; -var tickmessage = 0; -var lasthz = 0; - -function Ticker() -{ - lasthz = msg - tickmessage; - tickmessage = msg; - setTimeout( Ticker, 1000 ); -} - -function onMessage(evt) -{ -// eval( evt.data ); - - output.innerHTML = msg++ + " " + lasthz; - doSend('x' ); - - // obj = JSON.parse(evt.data); - // console.log( obj ); - // writeToScreen('RESPONSE: ' + evt.data+''); - // websocket.close(); -} - -function onError(evt) -{ - writeToScreen('ERROR: ' + evt.data); -} - -function doSend(message) -{ - writeToScreen("SENT: " + message); - websocket.send(message); -} - -function writeToScreen(message) -{ - var pre = document.createElement("p"); - pre.style.wordWrap = "break-word"; - pre.innerHTML = message; - output.appendChild(pre); -} - -window.addEventListener("load", init, false); - -Ticker(); - diff --git a/embedded8266/web/pushtodev.c b/embedded8266/web/pushtodev.c index 615db44..6373b1b 100644 --- a/embedded8266/web/pushtodev.c +++ b/embedded8266/web/pushtodev.c @@ -84,7 +84,7 @@ int main(int argc, char**argv) servaddr.sin_port=htons(7878); int devo = 0; - int lastsector = -1; + int lastsector_block = -1; int resend_times = 0; int r; while( !feof( f ) ) @@ -96,9 +96,10 @@ int main(int argc, char**argv) int reads = fread( buffer, 1, 1024, f ); int sendplace = offset + devo; int sendsize = reads; - int sector = sendplace / sector_SIZE; - if( sector != lastsector ) +#ifdef SECTOR + int sector = sendplace / sector_SIZE; + if( sector != lastsector_block ) { char se[64]; int sel = sprintf( se, "FE%d\r\n", sector ); @@ -120,9 +121,36 @@ int main(int argc, char**argv) exit( -6 ); } - lastsector = sector; + lastsector_block = sector; } +#else //block + int block = sendplace / 65536; + if( block != lastsector_block ) + { + char se[64]; + int sel = sprintf( se, "FB%d\r\n", block ); + + thissuccess = 0; + for( tries = 0; tries < 10; tries++ ) + { + char match[75]; + printf( "Erase: %d\n", block ); + sendto( sockfd, se, sel, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr)); + sprintf( match, "FB%d", block ); + + if( PushMatch(match) == 0 ) { thissuccess = 1; break; } + printf( "Retry.\n" ); + } + if( !thissuccess ) + { + fprintf( stderr, "Error: Timeout in communications.\n" ); + exit( -6 ); + } + + lastsector_block = block; + } +#endif resend_times = 0; resend: r = sprintf( bufferout, "FW%d:%d:", sendplace, sendsize );