|
|
@ -1182,141 +1182,90 @@ function tr(key) { return _tr[key] || '?'+key+'?'; } |
|
|
|
w.init = wifiInit; |
|
|
|
w.init = wifiInit; |
|
|
|
w.startScanning = startScanning; |
|
|
|
w.startScanning = startScanning; |
|
|
|
})(window.WiFi = {}); |
|
|
|
})(window.WiFi = {}); |
|
|
|
(function() { |
|
|
|
var Screen = (function () { |
|
|
|
/** |
|
|
|
var W, H; // dimensions
|
|
|
|
* Terminal module |
|
|
|
var inited = false; |
|
|
|
*/ |
|
|
|
|
|
|
|
var Term = (function () { |
|
|
|
var cursor = { |
|
|
|
var W, H; |
|
|
|
a: false, // active (blink state)
|
|
|
|
var cursor = {a: false, x: 0, y: 0, suppress: false, hidden: false}; |
|
|
|
x: 0, // 0-based coordinates
|
|
|
|
|
|
|
|
y: 0, |
|
|
|
|
|
|
|
fg: 7, // colors 0-15
|
|
|
|
|
|
|
|
bg: 0, |
|
|
|
|
|
|
|
bold: false, |
|
|
|
|
|
|
|
suppress: false, // do not turn on in blink interval (for safe moving)
|
|
|
|
|
|
|
|
hidden: false // do not show
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var screen = []; |
|
|
|
var screen = []; |
|
|
|
var blinkIval; |
|
|
|
var blinkIval; |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/** Clear screen */ |
|
|
|
/!** Clear screen *!/ |
|
|
|
function _clear() { |
|
|
|
function cls() { |
|
|
|
for (var i = W*H-1; i>=0; i--) { |
|
|
|
screen.forEach(function(cell, i) { |
|
|
|
var cell = screen[i]; |
|
|
|
cell.t = ' '; |
|
|
|
cell.t = ' '; |
|
|
|
cell.fg = 7; |
|
|
|
cell.bg = cursor.bg; |
|
|
|
cell.bg = 0; |
|
|
|
cell.fg = cursor.fg; |
|
|
|
blit(cell); |
|
|
|
cell.bold = false; |
|
|
|
}); |
|
|
|
_draw(cell); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Set text and color at XY */ |
|
|
|
/** Set text and color at XY */ |
|
|
|
function cellAt(y, x) { |
|
|
|
function _cellAt(y, x) { |
|
|
|
return screen[y*W+x]; |
|
|
|
return screen[y*W+x]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Get cell under cursor */ |
|
|
|
/** Get cell under cursor */ |
|
|
|
function cursorCell() { |
|
|
|
function _curCell() { |
|
|
|
return cellAt(cursor.y, cursor.x); |
|
|
|
return screen[cursor.y*W + cursor.x]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/** Enable or disable cursor visibility */ |
|
|
|
/!** Enable or disable cursor visibility *!/ |
|
|
|
function _cursorEnable(enable) { |
|
|
|
function cursorEnable(enable) { |
|
|
|
|
|
|
|
cursor.hidden = !enable; |
|
|
|
cursor.hidden = !enable; |
|
|
|
cursor.a &= enable; |
|
|
|
cursor.a &= enable; |
|
|
|
blit(cursorCell(), cursor.a); |
|
|
|
_draw(_curCell()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/!** Safely move cursor *!/ |
|
|
|
/** Safely move cursor */ |
|
|
|
function cursorSet(y, x) { |
|
|
|
function cursorSet(y, x) { |
|
|
|
// Hide and prevent from showing up during the move
|
|
|
|
// Hide and prevent from showing up during the move
|
|
|
|
cursor.suppress = true; |
|
|
|
cursor.suppress = true; |
|
|
|
blit(cursorCell(), false); |
|
|
|
_draw(_curCell(), false); |
|
|
|
|
|
|
|
|
|
|
|
cursor.x = x; |
|
|
|
cursor.x = x; |
|
|
|
cursor.y = y; |
|
|
|
cursor.y = y; |
|
|
|
|
|
|
|
|
|
|
|
// Show again
|
|
|
|
// Show again
|
|
|
|
cursor.suppress = false; |
|
|
|
cursor.suppress = false; |
|
|
|
blit(cursorCell(), cursor.a); |
|
|
|
_draw(_curCell()); |
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Update cell on display. inv = invert (for cursor) */ |
|
|
|
/** Update cell on display. inv = invert (for cursor) */ |
|
|
|
function blit(cell, inv) { |
|
|
|
function _draw(cell, inv) { |
|
|
|
|
|
|
|
if (typeof inv == 'undefined') { |
|
|
|
|
|
|
|
inv = cursor.a && cursor.x == cell.x && cursor.y == cell.y; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var e = cell.e, fg, bg; |
|
|
|
var e = cell.e, fg, bg; |
|
|
|
// Colors
|
|
|
|
// Colors
|
|
|
|
fg = inv ? cell.bg : cell.fg; |
|
|
|
fg = inv ? cell.bg : cell.fg; |
|
|
|
bg = inv ? cell.fg : cell.bg; |
|
|
|
bg = inv ? cell.fg : cell.bg; |
|
|
|
// Update
|
|
|
|
// Update
|
|
|
|
e.innerText = (cell.t + ' ')[0]; |
|
|
|
e.innerText = (cell.t + ' ')[0]; |
|
|
|
e.className = 'fg'+fg+' bg'+bg; |
|
|
|
e.className = 'fg' + fg + ' bg' + bg + (cell.bold ? ' bold' : ''); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Show entire screen */ |
|
|
|
/** Show entire screen */ |
|
|
|
function blitAll() { |
|
|
|
function _drawAll() { |
|
|
|
screen.forEach(function(cell, i) { |
|
|
|
for (var i = W*H-1; i>=0; i--) { |
|
|
|
/* Invert if under cursor & cursor active */ |
|
|
|
_draw(screen[i]); |
|
|
|
var inv = cursor.a && (i == cursor.y*W+cursor.x); |
|
|
|
|
|
|
|
blit(cell, inv); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Load screen content from a 'binary' sequence */ |
|
|
|
|
|
|
|
function load(obj) { |
|
|
|
|
|
|
|
cursor.x = obj.x; |
|
|
|
|
|
|
|
cursor.y = obj.y; |
|
|
|
|
|
|
|
cursor.hidden = !obj.cv; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// full re-init if size changed
|
|
|
|
|
|
|
|
if (obj.w != W || obj.h != H) { |
|
|
|
|
|
|
|
Term.init(obj); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Simple compression - hexFG hexBG 'ASCII' (r/s/t/u NUM{1,2,3,4})?
|
|
|
|
|
|
|
|
// comma instead of both colors = same as before
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var i = 0, ci = 0, str = obj.screen; |
|
|
|
|
|
|
|
var fg = 7, bg = 0; |
|
|
|
|
|
|
|
while(i < str.length && ci<W*H) { |
|
|
|
|
|
|
|
var cell = screen[ci++]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var j = str[i]; |
|
|
|
|
|
|
|
if (j != ',') { // comma = repeat last colors
|
|
|
|
|
|
|
|
fg = cell.fg = parseInt(str[i++], 16); |
|
|
|
|
|
|
|
bg = cell.bg = parseInt(str[i++], 16); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
i++; |
|
|
|
|
|
|
|
cell.fg = fg; |
|
|
|
|
|
|
|
cell.bg = bg; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var t = cell.t = str[i++]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var repchars = 0; |
|
|
|
|
|
|
|
switch(str[i]) { |
|
|
|
|
|
|
|
case 'r': repchars = 1; break; |
|
|
|
|
|
|
|
case 's': repchars = 2; break; |
|
|
|
|
|
|
|
case 't': repchars = 3; break; |
|
|
|
|
|
|
|
case 'u': repchars = 4; break; |
|
|
|
|
|
|
|
default: repchars = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (repchars > 0) { |
|
|
|
|
|
|
|
var rep = parseInt(str.substr(i+1,repchars)); |
|
|
|
|
|
|
|
i = i + repchars + 1; |
|
|
|
|
|
|
|
for (; rep>0 && ci<W*H; rep--) { |
|
|
|
|
|
|
|
cell = screen[ci++]; |
|
|
|
|
|
|
|
cell.fg = fg; |
|
|
|
|
|
|
|
cell.bg = bg; |
|
|
|
|
|
|
|
cell.t = t; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
blitAll(); |
|
|
|
function _rebuild(rows, cols) { |
|
|
|
} |
|
|
|
W = cols; |
|
|
|
|
|
|
|
H = rows; |
|
|
|
/** Init the terminal */ |
|
|
|
|
|
|
|
function init(obj) { |
|
|
|
|
|
|
|
W = obj.w; |
|
|
|
|
|
|
|
H = obj.h; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Build screen & show */ |
|
|
|
/* Build screen & show */ |
|
|
|
var e, cell, scr = qs('#screen'); |
|
|
|
var e, cell, scr = qs('#screen'); |
|
|
@ -1344,11 +1293,21 @@ function tr(key) { return _tr[key] || '?'+key+'?'; } |
|
|
|
/* The cell */ |
|
|
|
/* The cell */ |
|
|
|
scr.appendChild(e); |
|
|
|
scr.appendChild(e); |
|
|
|
|
|
|
|
|
|
|
|
cell = {t: ' ', fg: 7, bg: 0, e: e}; |
|
|
|
cell = { |
|
|
|
|
|
|
|
t: ' ', |
|
|
|
|
|
|
|
fg: cursor.fg, |
|
|
|
|
|
|
|
bg: cursor.bg, |
|
|
|
|
|
|
|
e: e, |
|
|
|
|
|
|
|
x: i % W, |
|
|
|
|
|
|
|
y: Math.floor(i / W), |
|
|
|
|
|
|
|
}; |
|
|
|
screen.push(cell); |
|
|
|
screen.push(cell); |
|
|
|
blit(cell); |
|
|
|
_draw(cell); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Init the terminal */ |
|
|
|
|
|
|
|
function _init() { |
|
|
|
/* Cursor blinking */ |
|
|
|
/* Cursor blinking */ |
|
|
|
clearInterval(blinkIval); |
|
|
|
clearInterval(blinkIval); |
|
|
|
blinkIval = setInterval(function () { |
|
|
|
blinkIval = setInterval(function () { |
|
|
@ -1358,17 +1317,91 @@ function tr(key) { return _tr[key] || '?'+key+'?'; } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!cursor.suppress) { |
|
|
|
if (!cursor.suppress) { |
|
|
|
blit(cursorCell(), cursor.a); |
|
|
|
_draw(_curCell(), cursor.a); |
|
|
|
} |
|
|
|
} |
|
|
|
}, 500); |
|
|
|
}, 500); |
|
|
|
|
|
|
|
inited = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Decode two-byte number */ |
|
|
|
|
|
|
|
function parse2B(s, i) { |
|
|
|
|
|
|
|
return (s.charCodeAt(i++) - 1) + (s.charCodeAt(i) - 1) * 127; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var SEQ_SET_COLOR = 1; |
|
|
|
|
|
|
|
var SEQ_REPEAT = 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Load screen content from a binary sequence (new) */ |
|
|
|
|
|
|
|
function load(str) { |
|
|
|
|
|
|
|
var i = 0, ci = 0, j, jc, num, num2, t = ' ', fg, bg, bold, cell; |
|
|
|
|
|
|
|
|
|
|
|
load(obj); |
|
|
|
if (!inited) _init(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set size
|
|
|
|
|
|
|
|
num = parse2B(str, i); i += 2; |
|
|
|
|
|
|
|
num2 = parse2B(str, i); i += 2; |
|
|
|
|
|
|
|
if (num != H || num2 != W) { |
|
|
|
|
|
|
|
_rebuild(num, num2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
console.log("Size ",num, num2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Cursor position
|
|
|
|
|
|
|
|
num = parse2B(str, i); i += 2; |
|
|
|
|
|
|
|
num2 = parse2B(str, i); i += 2; |
|
|
|
|
|
|
|
cursorSet(num, num2); |
|
|
|
|
|
|
|
console.log("Cursor at ",num, num2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Attributes
|
|
|
|
|
|
|
|
num = parse2B(str, i); i += 2; |
|
|
|
|
|
|
|
cursor.fg = num & 0x0F; |
|
|
|
|
|
|
|
cursor.bg = (num & 0xF0) >> 4; |
|
|
|
|
|
|
|
cursor.bold = !!(num & 0x100); |
|
|
|
|
|
|
|
cursor.hidden = !(num & 0x200); |
|
|
|
|
|
|
|
console.log("FG ",cursor.fg, ", BG ", cursor.bg,", BOLD ", cursor.bold, ", HIDE ", cursor.hidden); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fg = cursor.fg; |
|
|
|
|
|
|
|
bg = cursor.bg; |
|
|
|
|
|
|
|
bold = cursor.bold; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Here come the content
|
|
|
|
|
|
|
|
while(i < str.length && ci<W*H) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
j = str[i++]; |
|
|
|
|
|
|
|
jc = j.charCodeAt(0); |
|
|
|
|
|
|
|
if (jc == SEQ_SET_COLOR) { |
|
|
|
|
|
|
|
num = parse2B(str, i); i += 2; |
|
|
|
|
|
|
|
fg = num & 0x0F; |
|
|
|
|
|
|
|
bg = (num & 0xF0) >> 4; |
|
|
|
|
|
|
|
bold = !!(num & 0x100); |
|
|
|
|
|
|
|
console.log("Switch to ",fg,bg,bold); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (jc == SEQ_REPEAT) { |
|
|
|
|
|
|
|
num = parse2B(str, i); i += 2; |
|
|
|
|
|
|
|
console.log("Repeat x ",num); |
|
|
|
|
|
|
|
for (; num>0 && ci<W*H; num--) { |
|
|
|
|
|
|
|
cell = screen[ci++]; |
|
|
|
|
|
|
|
cell.fg = fg; |
|
|
|
|
|
|
|
cell.bg = bg; |
|
|
|
|
|
|
|
cell.t = t; |
|
|
|
|
|
|
|
cell.bold = bold; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
cell = screen[ci++]; |
|
|
|
|
|
|
|
// Unique cell character
|
|
|
|
|
|
|
|
t = cell.t = j; |
|
|
|
|
|
|
|
cell.fg = fg; |
|
|
|
|
|
|
|
cell.bg = bg; |
|
|
|
|
|
|
|
cell.bold = bold; |
|
|
|
|
|
|
|
console.log("Symbol ", j); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_drawAll(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// publish
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
init: init, |
|
|
|
load: load, // full load (string)
|
|
|
|
load: load |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
@ -1391,7 +1424,7 @@ function tr(key) { return _tr[key] || '?'+key+'?'; } |
|
|
|
try { |
|
|
|
try { |
|
|
|
console.log("RX: ", evt.data); |
|
|
|
console.log("RX: ", evt.data); |
|
|
|
// Assume all our messages are screen updates
|
|
|
|
// Assume all our messages are screen updates
|
|
|
|
Term.load(JSON.parse(evt.data)); |
|
|
|
Screen.load(evt.data); |
|
|
|
} catch(e) { |
|
|
|
} catch(e) { |
|
|
|
console.error(e); |
|
|
|
console.error(e); |
|
|
|
} |
|
|
|
} |
|
|
@ -1399,6 +1432,7 @@ function tr(key) { return _tr[key] || '?'+key+'?'; } |
|
|
|
|
|
|
|
|
|
|
|
function doSend(message) { |
|
|
|
function doSend(message) { |
|
|
|
console.log("TX: ", message); |
|
|
|
console.log("TX: ", message); |
|
|
|
|
|
|
|
if (!ws) return; // for dry testing
|
|
|
|
if (ws.readyState != 1) { |
|
|
|
if (ws.readyState != 1) { |
|
|
|
console.error("Socket not ready"); |
|
|
|
console.error("Socket not ready"); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -1425,9 +1459,7 @@ function tr(key) { return _tr[key] || '?'+key+'?'; } |
|
|
|
}; |
|
|
|
}; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
/** User input */ |
|
|
|
// Keyboard (& mouse) input
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
var Input = (function() { |
|
|
|
var Input = (function() { |
|
|
|
function sendStrMsg(str) { |
|
|
|
function sendStrMsg(str) { |
|
|
|
Conn.send("STR:"+str); |
|
|
|
Conn.send("STR:"+str); |
|
|
@ -1456,6 +1488,7 @@ function tr(key) { return _tr[key] || '?'+key+'?'; } |
|
|
|
//console.log("Down ", code, e);
|
|
|
|
//console.log("Down ", code, e);
|
|
|
|
switch(code) { |
|
|
|
switch(code) { |
|
|
|
case 8: sendStrMsg('\x08'); break; |
|
|
|
case 8: sendStrMsg('\x08'); break; |
|
|
|
|
|
|
|
case 10: |
|
|
|
case 13: sendStrMsg('\x0d\x0a'); break; |
|
|
|
case 13: sendStrMsg('\x0d\x0a'); break; |
|
|
|
case 27: sendStrMsg('\x1b'); break; // this allows to directly enter control sequences
|
|
|
|
case 27: sendStrMsg('\x1b'); break; // this allows to directly enter control sequences
|
|
|
|
case 37: sendStrMsg('\x1b[D'); break; |
|
|
|
case 37: sendStrMsg('\x1b[D'); break; |
|
|
@ -1478,10 +1511,8 @@ function tr(key) { return _tr[key] || '?'+key+'?'; } |
|
|
|
}; |
|
|
|
}; |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.termInit = function (str) { |
|
|
|
window.termInit = function (obj) { |
|
|
|
Screen.load(str); |
|
|
|
Term.init(obj); |
|
|
|
|
|
|
|
Conn.init(); |
|
|
|
Conn.init(); |
|
|
|
Input.init(); |
|
|
|
Input.init(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
})(); |
|
|
|
|
|
|
|