// Keyboard wiring var KEYROW = [B10,B13,B14,B15, B6,B5,B4,B3]; var KEYCOL = [A4,A3,A2,A1, B9,B8,A8,B7]; // Key Maps for Keyboard var KEYMAPLOWER = [ "`1234567890-=\x08", "\tqwertyuiop[]\n", "\0asdfghjkl;'#\x84\x82\x85", "\x01\\zxcvbnm,./ \x80\x83\x81", ]; var KEYMAPUPPER = [ "¬!\"£$%^&*()_+\x08", "\tQWERTYUIOP{}\n", "\0ASDFGHJKL:@~\x84\x82\x85", "\x01|ZXCVBNM<>? \x80\x83\x81", ]; /* If a char in the keymap is >=128, subtract 128 and look in this array for multi-character key codes*/ var KEYEXTRA = [ String.fromCharCode(27,91,68), // 0x80 left String.fromCharCode(27,91,67), // 0x81 right String.fromCharCode(27,91,65), // 0x82 up String.fromCharCode(27,91,66), // 0x83 down String.fromCharCode(27,91,53,126), // 0x84 page up String.fromCharCode(27,91,54,126), // 0x85 page down ]; // Shift status var hasShift = false; function setShift(s) { hasShift = s; digitalWrite(LED1, s); } // Convert an actual key into a sequence of characters // And send to Loopback (where the console is) function handleKeyPress(e) { var kx = e>>3; var ky = e&7; if (ky>3) { // turn into long row kx+=8; ky-=4; } var key = hasShift ? KEYMAPUPPER[ky][kx] : KEYMAPLOWER[ky][kx]; if (key=="\x01") { setShift(!hasShift); } else { setShift(false); if (key && key.length) { if (key.charCodeAt(0)>127) key = KEYEXTRA[key.charCodeAt(0)-128]; //USB.write(JSON.stringify(key)+"\r\n"); // debug LoopbackB.write(key); } } } var term; // the terminal var g; // graphics function onInit() { // set up the keypad require("KeyPad").connect(KEYROW, KEYCOL, handleKeyPress); // Start TV out g = require('tv').setup({ type : "vga", video : A7, hsync : A6, vsync : A5, width : 320, height : 240, repeat : 2, // amount of times to repeat each line }); // use a larger font instead of the default require("Font8x12").add(Graphics); g.setFont8x12(); // Set up the terminal term = require("VT100").connect(g, { charWidth : 8, charHeight : 12, marginTop : 10, // might want to tweak these depending on your monitor marginLeft : 20, marginBottom : 16 }); // take characters from Espruino, and push them into the VT100 terminal LoopbackB.on('data',function(e){ for (var i in e) term.char(e[i]); }); // copy characters coming down USB into the 'loopback' device USB.on('data',function(e){ LoopbackB.write(e); }); // Now move the console to Loopback LoopbackA.setConsole(); }