Separate out code to handle web menu interface.
This commit is contained in:
parent
6967f23349
commit
3b00d9e087
|
@ -23,8 +23,12 @@ ICACHE_FLASH_ATTR void HTTPHandleInternalCallback( );
|
|||
|
||||
ICACHE_FLASH_ATTR void HTTPClose( )
|
||||
{
|
||||
curhttp->state = HTTP_STATE_NONE;
|
||||
espconn_disconnect( curhttp->socket );
|
||||
//This is dead code, but it is a testament to Charles.
|
||||
//Do not do this here. Wait for the ESP to tell us the
|
||||
//socket is successfully closed.
|
||||
//curhttp->state = HTTP_STATE_NONE;
|
||||
curhttp->state = HTTP_WAIT_CLOSE;
|
||||
espconn_disconnect( curhttp->socket );
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,7 +36,6 @@ void ICACHE_FLASH_ATTR HTTPGotData( )
|
|||
{
|
||||
uint8 c;
|
||||
curhttp->timeout = 0;
|
||||
|
||||
while( curlen-- )
|
||||
{
|
||||
c = HTTPPOP;
|
||||
|
@ -109,7 +112,6 @@ void ICACHE_FLASH_ATTR HTTPGotData( )
|
|||
}
|
||||
else
|
||||
{
|
||||
//printf( "__HTTPCLose1\n" );
|
||||
HTTPClose( );
|
||||
}
|
||||
break;
|
||||
|
@ -149,7 +151,6 @@ static void DoHTTP( uint8_t timed )
|
|||
}
|
||||
else
|
||||
{
|
||||
//printf( "HTTPCLose2\n");
|
||||
HTTPClose( );
|
||||
}
|
||||
}
|
||||
|
@ -165,7 +166,6 @@ static void DoHTTP( uint8_t timed )
|
|||
{
|
||||
if( curhttp->timeout++ > HTTP_SERVER_TIMEOUT )
|
||||
{
|
||||
//printf( "HTTPClose3\n" );
|
||||
HTTPClose( );
|
||||
}
|
||||
}
|
||||
|
@ -177,8 +177,10 @@ void HTTPTick( uint8_t timed )
|
|||
uint8_t i;
|
||||
for( i = 0; i < HTTP_CONNECTIONS; i++ )
|
||||
{
|
||||
if( curhttp ) { printf( "Unexpected Race Condition\n" );}
|
||||
curhttp = &HTTPConnections[i];
|
||||
DoHTTP( timed );
|
||||
curhttp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,7 +268,7 @@ void ICACHE_FLASH_ATTR HTTPHandleInternalCallback( )
|
|||
curhttp->isdone = 1;
|
||||
}
|
||||
|
||||
void InternalStartHTTP( )
|
||||
void ICACHE_FLASH_ATTR InternalStartHTTP( )
|
||||
{
|
||||
int32_t clusterno;
|
||||
int8_t i;
|
||||
|
@ -322,19 +324,24 @@ void InternalStartHTTP( )
|
|||
LOCAL void ICACHE_FLASH_ATTR
|
||||
http_disconnetcb(void *arg) {
|
||||
struct espconn *pespconn = (struct espconn *) arg;
|
||||
curhttp = (struct HTTPConnection * )pespconn->reverse;
|
||||
curhttp->state = 0;
|
||||
((struct HTTPConnection * )pespconn->reverse)->state = 0;
|
||||
}
|
||||
|
||||
LOCAL void ICACHE_FLASH_ATTR
|
||||
http_recvcb(void *arg, char *pusrdata, unsigned short length)
|
||||
LOCAL void http_recvcb(void *arg, char *pusrdata, unsigned short length)
|
||||
{
|
||||
struct espconn *pespconn = (struct espconn *) arg;
|
||||
|
||||
//Though it might be possible for this to interrupt the other
|
||||
//tick task, I don't know if this is actually a probelem.
|
||||
//I'm adding this back-up-the-register just in case.
|
||||
if( curhttp ) { printf( "Unexpected Race Condition\n" );}
|
||||
|
||||
curhttp = (struct HTTPConnection * )pespconn->reverse;
|
||||
curdata = (uint8*)pusrdata;
|
||||
curlen = length;
|
||||
HTTPGotData();
|
||||
curhttp = 0 ;
|
||||
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
|
|
Binary file not shown.
|
@ -83,8 +83,6 @@ static void procTask(os_event_t *events)
|
|||
hpa_running = 0;
|
||||
}
|
||||
|
||||
CSTick( 0 );
|
||||
|
||||
//For profiling so we can see how much CPU is spent in this loop.
|
||||
#ifdef PROFILE
|
||||
WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(0), 1 );
|
||||
|
@ -109,6 +107,8 @@ static void procTask(os_event_t *events)
|
|||
|
||||
if( events->sig == 0 && events->par == 0 )
|
||||
{
|
||||
CSTick( 0 );
|
||||
|
||||
//Idle Event.
|
||||
struct station_config wcfg;
|
||||
char stret[256];
|
||||
|
|
|
@ -45,8 +45,16 @@ Extra copyright info:
|
|||
//Creates an I2S SR of 93,750 Hz, or 3 MHz Bitclock (.333us/sample)
|
||||
// 12000000L/(div*bestbck*2)
|
||||
//It is likely you could speed this up a little.
|
||||
#define WS_I2S_BCK 16
|
||||
|
||||
#ifdef WS2812_THREE_SAMPLE
|
||||
#define WS_I2S_BCK 22 //Seems to work as low as 19, but is shakey at 18.
|
||||
#define WS_I2S_DIV 4
|
||||
#elif defined( WS2812_FOUR_SAMPLE )
|
||||
#define WS_I2S_BCK 17 //Seems to work as low as 14, shoddy at 13.
|
||||
#define WS_I2S_DIV 4
|
||||
#else
|
||||
#error You need to either define WS2812_THREE_SAMPLE or WS2812_FOUR_SAMPLE
|
||||
#endif
|
||||
|
||||
#ifndef i2c_bbpll
|
||||
#define i2c_bbpll 0x67
|
||||
|
@ -400,7 +408,16 @@ void ICACHE_FLASH_ATTR ws2812_init()
|
|||
//All functions below this line are Public Domain 2015 Charles Lohr.
|
||||
//this code may be used by anyone in any way without restriction or limitation.
|
||||
|
||||
#ifdef WS2812_THREE_SAMPLE
|
||||
|
||||
static const uint16_t bitpatterns[16] = {
|
||||
0b100100100100, 0b100100100110, 0b100100110100, 0b100100110110,
|
||||
0b100110100100, 0b100110100110, 0b100110110100, 0b100110110110,
|
||||
0b110100100100, 0b110100100110, 0b110100110100, 0b110100110110,
|
||||
0b110110100100, 0b110110100110, 0b110110110100, 0b110110110110,
|
||||
};
|
||||
|
||||
#elif defined(WS2812_FOUR_SAMPLE)
|
||||
//Tricky, send out WS2812 bits with coded pulses, one nibble, then the other.
|
||||
static const uint16_t bitpatterns[16] = {
|
||||
0b1000100010001000, 0b1000100010001110, 0b1000100011101000, 0b1000100011101110,
|
||||
|
@ -408,14 +425,67 @@ static const uint16_t bitpatterns[16] = {
|
|||
0b1110100010001000, 0b1110100010001110, 0b1110100011101000, 0b1110100011101110,
|
||||
0b1110111010001000, 0b1110111010001110, 0b1110111011101000, 0b1110111011101110,
|
||||
};
|
||||
#endif
|
||||
|
||||
void ws2812_push( uint8_t * buffer, uint16_t buffersize )
|
||||
{
|
||||
uint16_t * bufferpl = (uint16_t*)&i2sBlock[0];
|
||||
uint16_t place;
|
||||
|
||||
// while( !ws2812_dma_complete );
|
||||
|
||||
#ifdef WS2812_THREE_SAMPLE
|
||||
uint8_t * bufferpl = (uint8_t*)&i2sBlock[0];
|
||||
|
||||
// buffersize += 3;
|
||||
// if( buffersize * 4 + 1 > WS_BLOCKSIZE ) return;
|
||||
|
||||
int pl = 0;
|
||||
int quit = 0;
|
||||
|
||||
//Once for each led.
|
||||
for( place = 0; !quit; place++ )
|
||||
{
|
||||
uint8_t b;
|
||||
b = buffer[pl++]; uint16_t c1a = bitpatterns[(b&0x0f)]; uint16_t c1b = bitpatterns[(b>>4)];
|
||||
b = buffer[pl++]; uint16_t c2a = bitpatterns[(b&0x0f)]; uint16_t c2b = bitpatterns[(b>>4)];
|
||||
b = buffer[pl++]; uint16_t c3a = bitpatterns[(b&0x0f)]; uint16_t c3b = bitpatterns[(b>>4)];
|
||||
b = buffer[pl++]; uint16_t c4a = bitpatterns[(b&0x0f)]; uint16_t c4b = bitpatterns[(b>>4)];
|
||||
|
||||
if( pl >= buffersize )
|
||||
{
|
||||
quit = 1;
|
||||
if( pl-1 >= buffersize ) c4a = c4b = 0;
|
||||
if( pl-2 >= buffersize ) c3a = c3b = 0;
|
||||
if( pl-3 >= buffersize ) c2a = c2b = 0;
|
||||
if( pl-4 >= buffersize ) c1a = c1b = 0;
|
||||
}
|
||||
|
||||
//Order of bits on wire: Reverse from how they appear here.
|
||||
#define STEP1(x) (c##x##b >> 4 )
|
||||
#define STEP2(x) ((c##x##b << 4 ) | ( c##x##a>>8 ))
|
||||
#define STEP3(x) (c##x##a & 0xff )
|
||||
|
||||
*(bufferpl++) = STEP1(2);
|
||||
*(bufferpl++) = STEP3(1);
|
||||
*(bufferpl++) = STEP2(1);
|
||||
*(bufferpl++) = STEP1(1);
|
||||
|
||||
*(bufferpl++) = STEP2(3);
|
||||
*(bufferpl++) = STEP1(3);
|
||||
*(bufferpl++) = STEP3(2);
|
||||
*(bufferpl++) = STEP2(2);
|
||||
|
||||
*(bufferpl++) = STEP3(4);
|
||||
*(bufferpl++) = STEP2(4);
|
||||
*(bufferpl++) = STEP1(4);
|
||||
*(bufferpl++) = STEP3(3);
|
||||
}
|
||||
|
||||
while( bufferpl < &((uint8_t*)i2sBlock)[WS_BLOCKSIZE] ) *(bufferpl++) = 0;
|
||||
|
||||
#elif defined(WS2812_FOUR_SAMPLE)
|
||||
uint16_t * bufferpl = (uint16_t*)&i2sBlock[0];
|
||||
|
||||
if( buffersize * 4 > WS_BLOCKSIZE ) return;
|
||||
|
||||
for( place = 0; place < buffersize; place++ )
|
||||
|
@ -424,6 +494,7 @@ void ws2812_push( uint8_t * buffer, uint16_t buffersize )
|
|||
*(bufferpl++) = bitpatterns[(btosend&0x0f)];
|
||||
*(bufferpl++) = bitpatterns[(btosend>>4)&0x0f];
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_2812_INTERRUPTS
|
||||
|
||||
|
|
|
@ -13,9 +13,19 @@
|
|||
//#define I2SDMABUFLEN (32*2) //Length of one buffer, in 32-bit words.
|
||||
|
||||
//NOTE: Blocksize MUST be divisible by 4. Cannot exceed 4092
|
||||
//Each LED takes up 12 block bytes.
|
||||
//Each LED takes up 12 block bytes in WS2812_FOUR_SAMPLE
|
||||
//Or 9 block bytes in WS2812_THREE_SAMPLE
|
||||
#define WS_BLOCKSIZE 4000
|
||||
|
||||
//You can either have 3 or 4 samples per bit for WS2812s.
|
||||
//3 sample can't go quite as fast as 4.
|
||||
//3 sample uses more processing when updating than 4.
|
||||
//4 takes up more RAM per LED than 3.
|
||||
//3 has slightly more restrictve timing requirements.
|
||||
//4 has more DMA load when running.
|
||||
#define WS2812_THREE_SAMPLE
|
||||
//#define WS2812_FOUR_SAMPLE
|
||||
|
||||
void ICACHE_FLASH_ATTR ws2812_init();
|
||||
void ws2812_push( uint8_t * buffer, uint16_t buffersize ); //Buffersize = Nr LEDs * 3
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
<html>
|
||||
<!-- Copyright (C) 2015 <>< Charles Lohr, see LICENSE file for more info.
|
||||
This particular file may be licensed under the MIT/x11, New BSD or ColorChord Licenses. -->
|
||||
<head>
|
||||
<title>ColorChord Control Panel</title>
|
||||
<script language="javascript" type="text/javascript" src=jquery-2.1.4.min.js.gz></script>
|
||||
<script language="javascript" type="text/javascript" src=menuinterface.js></script>
|
||||
<script language="javascript" type="text/javascript" src=main.js></script>
|
||||
<meta charset="UTF-8">
|
||||
<style>
|
||||
|
@ -9,20 +12,16 @@ table { width: 100%; }
|
|||
td { vertical-align: top; }
|
||||
.collapsible { display:none; }
|
||||
.inbutton { background-color:blue; }
|
||||
#SystemMessage { position: fixed; top: 5px; background-color: DarkSlateBlue; color: #ffffff; left: 5px; display:none; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>ColorChord: Embedded</h2>
|
||||
<hr>
|
||||
|
||||
<table>
|
||||
<table id="MainMenu">
|
||||
|
||||
<tr><td width=1>
|
||||
<input type=submit onclick="ShowHideEvent( 'SystemStatus' );" value="System Status" id=SystemStatusClicker></td><td>
|
||||
<div id=SystemStatus class="collapsible">
|
||||
<table width=100% border=1><tr><td>
|
||||
<div id=output>
|
||||
</td></tr></table></div></td></tr>
|
||||
<tbody>
|
||||
|
||||
<tr><td width=1>
|
||||
<input type=submit onclick="ShowHideEvent( 'Introduction' );" value="Introduction"></td><td>
|
||||
|
@ -33,52 +32,6 @@ td { vertical-align: top; }
|
|||
<p>For more information about ColorChord, visit it on github, here: <a href=https://github.com/cnlohr/colorchord>https://github.com/cnlohr/colorchord</a></p>
|
||||
</div></td></tr></table></td></tr>
|
||||
|
||||
<tr><td width=1>
|
||||
<input type=submit onclick="ShowHideEvent( 'WifiSettings' ); KickWifiTicker();" value="Wifi Settings"></td><td>
|
||||
<div id=WifiSettings class="collapsible">
|
||||
<table width=100% border=1><tr><td>
|
||||
Current Configuration: (May deviate from default configuration, reset here if in doubt)<form name="wifisection" action="javascript:ChangeWifiConfig();">
|
||||
<table border=1 width=1%>
|
||||
<tr><td width=1>Type:</td><td><input type="radio" name="wifitype" value=1 onclick="ClickOpmode(1);">Station (Connect to infrastructure)<br><input type="radio" name="wifitype" value=2 onclick="ClickOpmode(2);">AP (Broadcast a new AP)</td></tr>
|
||||
<tr><td>SSID:</td><td><input type="text" id="wificurname"></td></tr>
|
||||
<tr><td>PASS:</td><td><input type="text" id="wificurpassword"></td></tr>
|
||||
<tr><td>MAC:</td><td><input type="text" id="wifimac"> (Ignored in softAP mode)</td></tr>
|
||||
<tr><td>Chan:</td><td><input type="text" id="wificurchannel"> (Ignored in Station mode)</td></tr></tr>
|
||||
<tr><td></td><td><input type=submit value="Change Settings"> (Automatically saves to flash)</td></tr>
|
||||
</table></form>
|
||||
Scanned Stations:
|
||||
<div id=WifiStations></div>
|
||||
<input type=submit onclick="QueueOperation('WS', null);" value="Scan For Stations (Will disconnect!)">
|
||||
</td></tr></table></div></td></tr>
|
||||
|
||||
<tr><td width=1>
|
||||
<input type=submit onclick="ShowHideEvent( 'CustomCommand' );" value="Custom Command"></td><td>
|
||||
<div id=CustomCommand class="collapsible">
|
||||
<table width=100% border=1><tr><td>
|
||||
Command: <input type=text id=custom_command>
|
||||
<input type=submit value="Submit" onclick="IssueCustomCommand()"><br>
|
||||
<textarea id=custom_command_response readonly rows=15 cols=80></textarea>
|
||||
</td></tr></table></td></tr>
|
||||
|
||||
<tr><td width=1>
|
||||
<input type=submit onclick="ShowHideEvent( 'GPIOs' ); GPIODataTicker();" value="GPIOs"></td><td>
|
||||
<div id=GPIOs class="collapsible">
|
||||
<table width=100% border=1><tr>
|
||||
<td align=center>0<input type=button id=ButtonGPIO0 value=0 onclick="TwiddleGPIO(0);"><input type=button id=BGPIOIn0 value=In onclick="GPIOInput(0);" class="inbutton"></td>
|
||||
<td align=center>1<input type=button id=ButtonGPIO1 value=0 onclick="TwiddleGPIO(1);"><input type=button id=BGPIOIn1 value=In onclick="GPIOInput(1);" class="inbutton"></td>
|
||||
<td align=center>2<input type=button id=ButtonGPIO2 value=0 onclick="TwiddleGPIO(2);"><input type=button id=BGPIOIn2 value=In onclick="GPIOInput(2);" class="inbutton"></td>
|
||||
<td align=center>3<input type=button id=ButtonGPIO3 value=0 onclick="TwiddleGPIO(3);"><input type=button id=BGPIOIn3 value=In onclick="GPIOInput(3);" class="inbutton"></td>
|
||||
<td align=center>4<input type=button id=ButtonGPIO4 value=0 onclick="TwiddleGPIO(4);"><input type=button id=BGPIOIn4 value=In onclick="GPIOInput(4);" class="inbutton"></td>
|
||||
<td align=center>5<input type=button id=ButtonGPIO5 value=0 onclick="TwiddleGPIO(5);"><input type=button id=BGPIOIn5 value=In onclick="GPIOInput(5);" class="inbutton"></td>
|
||||
<td>...</td>
|
||||
<td align=center>12<input type=button id=ButtonGPIO12 value=0 onclick="TwiddleGPIO(12);"><input type=button id=BGPIOIn12 value=In onclick="GPIOInput(12);" class="inbutton"></td>
|
||||
<td align=center>13<input type=button id=ButtonGPIO13 value=0 onclick="TwiddleGPIO(13);"><input type=button id=BGPIOIn13 value=In onclick="GPIOInput(13);" class="inbutton"></td>
|
||||
<td align=center>14<input type=button id=ButtonGPIO14 value=0 onclick="TwiddleGPIO(14);"><input type=button id=BGPIOIn14 value=In onclick="GPIOInput(14);" class="inbutton"></td>
|
||||
<td align=center>15<input type=button id=ButtonGPIO15 value=0 onclick="TwiddleGPIO(15);"><input type=button id=BGPIOIn15 value=In onclick="GPIOInput(15);" class="inbutton"></td>
|
||||
</tr></table></div></td></tr>
|
||||
|
||||
|
||||
|
||||
<tr><td width=1>
|
||||
<input type=submit onclick="ShowHideEvent( 'OScope' ); KickOscilloscope();" value="Oscilloscope"></td><td>
|
||||
<div id=OScope class="collapsible">
|
||||
|
@ -117,15 +70,16 @@ Command: <input type=text id=custom_command>
|
|||
<input type=submit onclick="ShowHideEvent( 'Parameters' );" value="Parameters"></td><td>
|
||||
<div id=Parameters class="collapsible">
|
||||
<div id=InnerParameters></div>
|
||||
<input type=button value="Save" onclick='QueueOperation( "CSS" )'> <input type=button value="Revert" onclick='QueueOperation( "CSR" )'> <input type=button value="Restore" onclick='QueueOperation( "CSD" )'>
|
||||
<input type=button value="Save" onclick='QueueOperation( "CSS", function(){IssueSystemMessage("Settings Saved to Flash" );} )'> <input type=button value="Revert" onclick='QueueOperation( "CSR", function() { IssueSystemMessage("Settings Read from Flash" );} )'> <input type=button value="Restore" onclick='QueueOperation( "CSD", function(){IssueSystemMessage("Settings in RAM Reverted to Factory" );} )'>
|
||||
</div>
|
||||
</td></tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
<p><font size=-2>Copyright (C) 2015 <>< Charles Lohr, See LICENSE file for more info.</font></p>
|
||||
<div id=SystemMessage>...</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
|
@ -1,202 +1,27 @@
|
|||
var wsUri = "ws://" + location.host + "/d/ws/issue";
|
||||
var output;
|
||||
var websocket;
|
||||
var commsup = 0;
|
||||
//Copyright (C) 2015 <>< Charles Lohr, see LICENSE file for more info.
|
||||
//
|
||||
//This particular file may be licensed under the MIT/x11, New BSD or ColorChord Licenses.
|
||||
|
||||
globalParams = {};
|
||||
|
||||
//Push objects that have:
|
||||
// .request
|
||||
// .callback = function( ref (this object), data );
|
||||
|
||||
var workqueue = [];
|
||||
var wifilines = [];
|
||||
var workarray = {};
|
||||
var lastitem;
|
||||
|
||||
function QueueOperation( command, callback )
|
||||
function mainticker()
|
||||
{
|
||||
if( workarray[command] == 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
workarray[command] = 1;
|
||||
var vp = new Object();
|
||||
vp.callback = callback;
|
||||
vp.request = command;
|
||||
workqueue.push( vp );
|
||||
QueueOperation( "CVR", ReceiveParameters );
|
||||
setTimeout( mainticker, 1000 );
|
||||
}
|
||||
|
||||
|
||||
function init()
|
||||
function maininit()
|
||||
{
|
||||
$( ".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();
|
||||
setTimeout( mainticker, 1000 );
|
||||
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 = "<p>Messages: " + msg + "</p><p>RSSI: " + evt.data.substr(2) + "</p>";
|
||||
}
|
||||
|
||||
|
||||
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.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
window.addEventListener("load", maininit, false);
|
||||
|
||||
|
||||
|
||||
|
@ -258,11 +83,6 @@ function ReceiveParameters(req,data) {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
is_oscilloscope_running = false;
|
||||
pause_oscilloscope = false;
|
||||
|
||||
|
@ -585,203 +405,6 @@ function NotesTicker()
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
|
||||
ClickOpmode( 1 );
|
||||
return false;
|
||||
}
|
||||
|
||||
function ClickOpmode( i )
|
||||
{
|
||||
if( i == 1 )
|
||||
{
|
||||
document.wifisection.wificurname.disabled = false;
|
||||
document.wifisection.wificurpassword.disabled = false;
|
||||
document.wifisection.wifimac.disabled = false;
|
||||
document.wifisection.wificurchannel.disabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
document.wifisection.wificurname.disabled = false;
|
||||
document.wifisection.wificurpassword.disabled = true;
|
||||
document.wifisection.wificurpassword.value = "";
|
||||
document.wifisection.wifimac.disabled = true;
|
||||
document.wifisection.wificurchannel.disabled = 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" );
|
||||
|
||||
var opmode = Number( params[0].substr(2) );
|
||||
document.wifisection.wifitype.value = opmode;
|
||||
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] );
|
||||
|
||||
ClickOpmode( opmode );
|
||||
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 = "<TABLE border=1><TR><TH>SSID</TH><TH>MAC</TH><TH>RS</TH><TH>Ch</TH><TH>Enc</TH></TR>"
|
||||
wifilines = [];
|
||||
for( i = 1; i < lines.length-1; i++ )
|
||||
{
|
||||
tlines = lines[i].split( "\t" );
|
||||
wifilines.push(tlines);
|
||||
var bssidval = "<a href='javascript:void(0);' onclick='return BSSIDClick(" + (i -1 )+ ")'>" + tlines[1];
|
||||
innerhtml += "<TR><TD>" + tlines[0].substr(1) + "</TD><TD>" + bssidval + "</TD><TD>" + tlines[2] + "</TD><TD>" + tlines[3] + "</TD><TD>" + tlines[4] + "</TD></TR>";
|
||||
}
|
||||
}
|
||||
innerhtml += "</TABLE>";
|
||||
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<<op & n )
|
||||
{
|
||||
b.css("background-color","red" );
|
||||
b.css("color","black" );
|
||||
b.prop( "value", "1" );
|
||||
}
|
||||
else
|
||||
{
|
||||
b.css("background-color","black" );
|
||||
b.css("color","white" );
|
||||
b.prop( "value", "0" );
|
||||
}
|
||||
}
|
||||
|
||||
b = $( "#BGPIOIn" + op );
|
||||
if( b )
|
||||
{
|
||||
if( 1<<op & m )
|
||||
{
|
||||
b.css("background-color","blue" );
|
||||
b.css("color","white" );
|
||||
b.attr( "value", "out" );
|
||||
}
|
||||
else
|
||||
{
|
||||
b.css("background-color","green" );
|
||||
b.css("color","white" );
|
||||
b.attr( "value", "in" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if( IsTabOpen('GPIOs') )
|
||||
QueueOperation( "GS", GPIOUpdate );
|
||||
}
|
||||
|
||||
function GPIODataTicker()
|
||||
{
|
||||
if( !IsTabOpen('GPIOs') ) return;
|
||||
QueueOperation( "GS", GPIOUpdate );
|
||||
setTimeout( GPIODataTicker, 500 );
|
||||
}
|
||||
|
||||
|
||||
function GPIODataTickerStart()
|
||||
{
|
||||
if( IsTabOpen('GPIOs') )
|
||||
GPIODataTicker();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function CCColor( note )
|
||||
{
|
||||
return ECCtoHEX( (note * globalParams["rNOTERANGE"] / globalParams["rFIXBPERO"] + globalParams["gROOT_NOTE_OFFSET"] + globalParams["rNOTERANGE"] )%globalParams["rNOTERANGE"], 255, 255 );
|
||||
|
|
473
embedded8266/web/page/menuinterface.js
Normal file
473
embedded8266/web/page/menuinterface.js
Normal file
|
@ -0,0 +1,473 @@
|
|||
//Copyright (C) 2015 <>< Charles Lohr, see LICENSE file for more info.
|
||||
//
|
||||
//This particular file may be licensed under the MIT/x11, New BSD or ColorChord Licenses.
|
||||
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 wifilines = [];
|
||||
var workarray = {};
|
||||
var lastitem;
|
||||
|
||||
var SystemMessageTimeout = null;
|
||||
function IssueSystemMessage( msg )
|
||||
{
|
||||
var elem = $( "#SystemMessage" );
|
||||
elem.hide();
|
||||
elem.html( "<font size=+2>" + msg + "</font>" );
|
||||
elem.slideToggle( 'fast' );
|
||||
if( SystemMessageTimeout != null ) clearTimeout(SystemMessageTimeout);
|
||||
SystemMessageTimeout = setTimeout( function() { SystemMessageTimeout = null; $( "#SystemMessage" ).fadeOut( 'slow' ) }, 3000 );
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
$('#MainMenu > tbody:first-child').before( "\
|
||||
<tr><td width=1> \
|
||||
<input type=submit onclick=\"ShowHideEvent( 'SystemStatus' );\" value='System Status' id=SystemStatusClicker></td><td> \
|
||||
<div id=SystemStatus class='collapsible'> \
|
||||
<table width=100% border=1><tr><td> \
|
||||
<div id=output> \n </td></tr></table></div></td></tr>" );
|
||||
|
||||
$('#MainMenu > tbody:last-child').after( "\
|
||||
<tr><td width=1> \
|
||||
<input type=submit onclick=\"ShowHideEvent( 'WifiSettings' ); KickWifiTicker();\" value=\"Wifi Settings\"></td><td> \
|
||||
<div id=WifiSettings class=\"collapsible\"> \
|
||||
<table width=100% border=1><tr><td> \
|
||||
Current Configuration: (May deviate from default configuration, reset here if in doubt)<form name=\"wifisection\" action=\"javascript:ChangeWifiConfig();\"> \
|
||||
<table border=1 width=1%> \
|
||||
<tr><td width=1>Type:</td><td><input type=\"radio\" name=\"wifitype\" value=1 onclick=\"ClickOpmode(1);\">Station (Connect to infrastructure)<br><input type=\"radio\" name=\"wifitype\" value=2 onclick=\"ClickOpmode(2);\">AP (Broadcast a new AP)</td></tr> \
|
||||
<tr><td>SSID:</td><td><input type=\"text\" id=\"wificurname\"></td></tr> \
|
||||
<tr><td>PASS:</td><td><input type=\"text\" id=\"wificurpassword\"></td></tr> \
|
||||
<tr><td>MAC:</td><td><input type=\"text\" id=\"wifimac\"> (Ignored in softAP mode)</td></tr> \
|
||||
<tr><td>Chan:</td><td><input type=\"text\" id=\"wificurchannel\"> (Ignored in Station mode)</td></tr></tr> \
|
||||
<tr><td></td><td><input type=submit value=\"Change Settings\"> (Automatically saves to flash)</td></tr> \
|
||||
</table></form> \
|
||||
Scanned Stations: \
|
||||
<div id=WifiStations></div> \
|
||||
<input type=submit onclick=\"ScanForWifi();\" value=\"Scan For Stations (Will disconnect!)\"> \
|
||||
</td></tr></table></div></td></tr> \
|
||||
\
|
||||
<tr><td width=1> \
|
||||
<input type=submit onclick=\"ShowHideEvent( 'CustomCommand' );\" value=\"Custom Command\"></td><td> \
|
||||
<div id=CustomCommand class=\"collapsible\"> \
|
||||
<table width=100% border=1><tr><td> \
|
||||
Command: <input type=text id=custom_command> \
|
||||
<input type=submit value=\"Submit\" onclick=\"IssueCustomCommand()\"><br> \
|
||||
<textarea id=custom_command_response readonly rows=15 cols=80></textarea> \
|
||||
</td></tr></table></td></tr> \
|
||||
\
|
||||
<tr><td width=1> \
|
||||
<input type=submit onclick=\"ShowHideEvent( 'GPIOs' ); GPIODataTicker();\" value=\"GPIOs\"></td><td> \
|
||||
<div id=GPIOs class=\"collapsible\"> \
|
||||
<table width=100% border=1><tr> \
|
||||
<td align=center>0<input type=button id=ButtonGPIO0 value=0 onclick=\"TwiddleGPIO(0);\"><input type=button id=BGPIOIn0 value=In onclick=\"GPIOInput(0);\" class=\"inbutton\"></td> \
|
||||
<td align=center>1<input type=button id=ButtonGPIO1 value=0 onclick=\"TwiddleGPIO(1);\"><input type=button id=BGPIOIn1 value=In onclick=\"GPIOInput(1);\" class=\"inbutton\"></td> \
|
||||
<td align=center>2<input type=button id=ButtonGPIO2 value=0 onclick=\"TwiddleGPIO(2);\"><input type=button id=BGPIOIn2 value=In onclick=\"GPIOInput(2);\" class=\"inbutton\"></td> \
|
||||
<td align=center>3<input type=button id=ButtonGPIO3 value=0 onclick=\"TwiddleGPIO(3);\"><input type=button id=BGPIOIn3 value=In onclick=\"GPIOInput(3);\" class=\"inbutton\"></td> \
|
||||
<td align=center>4<input type=button id=ButtonGPIO4 value=0 onclick=\"TwiddleGPIO(4);\"><input type=button id=BGPIOIn4 value=In onclick=\"GPIOInput(4);\" class=\"inbutton\"></td> \
|
||||
<td align=center>5<input type=button id=ButtonGPIO5 value=0 onclick=\"TwiddleGPIO(5);\"><input type=button id=BGPIOIn5 value=In onclick=\"GPIOInput(5);\" class=\"inbutton\"></td> \
|
||||
<td>...</td> \
|
||||
<td align=center>12<input type=button id=ButtonGPIO12 value=0 onclick=\"TwiddleGPIO(12);\"><input type=button id=BGPIOIn12 value=In onclick=\"GPIOInput(12);\" class=\"inbutton\"></td> \
|
||||
<td align=center>13<input type=button id=ButtonGPIO13 value=0 onclick=\"TwiddleGPIO(13);\"><input type=button id=BGPIOIn13 value=In onclick=\"GPIOInput(13);\" class=\"inbutton\"></td> \
|
||||
<td align=center>14<input type=button id=ButtonGPIO14 value=0 onclick=\"TwiddleGPIO(14);\"><input type=button id=BGPIOIn14 value=In onclick=\"GPIOInput(14);\" class=\"inbutton\"></td> \
|
||||
<td align=center>15<input type=button id=ButtonGPIO15 value=0 onclick=\"TwiddleGPIO(15);\"><input type=button id=BGPIOIn15 value=In onclick=\"GPIOInput(15);\" class=\"inbutton\"></td> \
|
||||
</tr></table></div></td></tr>");
|
||||
|
||||
|
||||
|
||||
|
||||
$( ".collapsible" ).each(function( index ) {
|
||||
if( localStorage["sh" + this.id] > 0.5 )
|
||||
{
|
||||
$( this ).show().toggleClass( 'opened' );
|
||||
}
|
||||
});
|
||||
|
||||
$("#custom_command_response").val( "" );
|
||||
|
||||
|
||||
output = document.getElementById("output");
|
||||
Ticker();
|
||||
|
||||
KickWifiTicker();
|
||||
GPIODataTickerStart();
|
||||
}
|
||||
|
||||
window.addEventListener("load", init, false);
|
||||
|
||||
|
||||
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" );
|
||||
if( commsup != 0 && !is_waiting_on_stations ) IssueSystemMessage( "Comms Lost." );
|
||||
commsup = 0;
|
||||
StartWebSocket();
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#SystemStatusClicker').prop( "value", "System " + lasthz + "Hz" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function onMessage(evt)
|
||||
{
|
||||
msg++;
|
||||
|
||||
|
||||
if( commsup != 1 )
|
||||
{
|
||||
commsup = 1;
|
||||
$('#SystemStatusClicker').css("color", "green" );
|
||||
IssueSystemMessage( "Comms Established." );
|
||||
}
|
||||
|
||||
|
||||
if( lastitem )
|
||||
{
|
||||
if( lastitem.callback )
|
||||
{
|
||||
lastitem.callback( lastitem, evt.data );
|
||||
lastitem = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
output.innerHTML = "<p>Messages: " + msg + "</p><p>RSSI: " + evt.data.substr(2) + "</p>";
|
||||
}
|
||||
|
||||
|
||||
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 ); } );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
did_wifi_get_config = false;
|
||||
is_data_ticker_running = false;
|
||||
is_waiting_on_stations = false;
|
||||
|
||||
function ScanForWifi()
|
||||
{
|
||||
QueueOperation('WS', null);
|
||||
is_waiting_on_stations=true;
|
||||
IssueSystemMessage( "Scanning for Wifi..." );
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
ClickOpmode( 1 );
|
||||
return false;
|
||||
}
|
||||
|
||||
function ClickOpmode( i )
|
||||
{
|
||||
if( i == 1 )
|
||||
{
|
||||
document.wifisection.wificurname.disabled = false;
|
||||
document.wifisection.wificurpassword.disabled = false;
|
||||
document.wifisection.wifimac.disabled = false;
|
||||
document.wifisection.wificurchannel.disabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
document.wifisection.wificurname.disabled = false;
|
||||
document.wifisection.wificurpassword.disabled = true;
|
||||
document.wifisection.wificurpassword.value = "";
|
||||
document.wifisection.wifimac.disabled = true;
|
||||
document.wifisection.wificurchannel.disabled = 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" );
|
||||
|
||||
var opmode = Number( params[0].substr(2) );
|
||||
document.wifisection.wifitype.value = opmode;
|
||||
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] );
|
||||
|
||||
ClickOpmode( opmode );
|
||||
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?";
|
||||
if( is_waiting_on_stations )
|
||||
{
|
||||
IssueSystemMessage( "No APs found." );
|
||||
is_waiting_on_stations = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( is_waiting_on_stations )
|
||||
{
|
||||
IssueSystemMessage( "Scan Complete." );
|
||||
is_waiting_on_stations = false;
|
||||
}
|
||||
|
||||
innerhtml = "<TABLE border=1><TR><TH>SSID</TH><TH>MAC</TH><TH>RS</TH><TH>Ch</TH><TH>Enc</TH></TR>"
|
||||
wifilines = [];
|
||||
for( i = 1; i < lines.length-1; i++ )
|
||||
{
|
||||
tlines = lines[i].split( "\t" );
|
||||
wifilines.push(tlines);
|
||||
var bssidval = "<a href='javascript:void(0);' onclick='return BSSIDClick(" + (i -1 )+ ")'>" + tlines[1];
|
||||
innerhtml += "<TR><TD>" + tlines[0].substr(1) + "</TD><TD>" + bssidval + "</TD><TD>" + tlines[2] + "</TD><TD>" + tlines[3] + "</TD><TD>" + tlines[4] + "</TD></TR>";
|
||||
}
|
||||
}
|
||||
innerhtml += "</TABLE>";
|
||||
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<<op & n )
|
||||
{
|
||||
b.css("background-color","red" );
|
||||
b.css("color","black" );
|
||||
b.prop( "value", "1" );
|
||||
}
|
||||
else
|
||||
{
|
||||
b.css("background-color","black" );
|
||||
b.css("color","white" );
|
||||
b.prop( "value", "0" );
|
||||
}
|
||||
}
|
||||
|
||||
b = $( "#BGPIOIn" + op );
|
||||
if( b )
|
||||
{
|
||||
if( 1<<op & m )
|
||||
{
|
||||
b.css("background-color","blue" );
|
||||
b.css("color","white" );
|
||||
b.attr( "value", "out" );
|
||||
}
|
||||
else
|
||||
{
|
||||
b.css("background-color","green" );
|
||||
b.css("color","white" );
|
||||
b.attr( "value", "in" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if( IsTabOpen('GPIOs') )
|
||||
QueueOperation( "GS", GPIOUpdate );
|
||||
}
|
||||
|
||||
function GPIODataTicker()
|
||||
{
|
||||
if( !IsTabOpen('GPIOs') ) return;
|
||||
QueueOperation( "GS", GPIOUpdate );
|
||||
setTimeout( GPIODataTicker, 500 );
|
||||
}
|
||||
|
||||
|
||||
function GPIODataTickerStart()
|
||||
{
|
||||
if( IsTabOpen('GPIOs') )
|
||||
GPIODataTicker();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function tohex8( c )
|
||||
{
|
||||
var hex = c.toString(16);
|
||||
return hex.length == 1 ? "0" + hex : hex;
|
||||
}
|
Loading…
Reference in a new issue