Merge branch 'm0110_editor_rev2' into gh-pages
This commit is contained in:
commit
2fadc96d3f
@ -1,7 +1,341 @@
|
||||
/*
|
||||
* TMK keymap editor
|
||||
*/
|
||||
// key id under editing
|
||||
var editing_key;
|
||||
// layer under editing
|
||||
var editing_layer = 0;
|
||||
|
||||
// load keymap on keyboard key buttons
|
||||
var load_keymap_on_keyboard = function(layer, keymap) {
|
||||
for (var row in keymap) {
|
||||
for (var col in keymap[row]) {
|
||||
var code = keymap[row][col];
|
||||
var key = keycodes[code];
|
||||
// row and column takes range of 0-32(0-9a-v)
|
||||
$("#key-" + parseInt(row).toString(32) + parseInt(col).toString(32)).text(key.name);
|
||||
$("#key-" + parseInt(row).toString(32) + parseInt(col).toString(32)).attr({ title: key.desc });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$(function() {
|
||||
// Title
|
||||
document.title = "TMK Keymap Editor for " + KEYBOARD_DESC;
|
||||
$("#page-title").text("TMK Keymap Editor for " + KEYBOARD_DESC);
|
||||
|
||||
/*
|
||||
* load keymap from URL hash
|
||||
*/
|
||||
var decoded = decode_keymap(document.location.hash.substring(1));
|
||||
if (decoded != null) {
|
||||
keymaps = decoded['keymaps'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Layer selector
|
||||
*/
|
||||
$("#layer_radio").buttonset();
|
||||
|
||||
// layer change
|
||||
$(".layer").click(function(ev, ui) {
|
||||
var layer = parseInt($(this).attr('id').match(/layer-(\d+)/)[1]);
|
||||
editing_layer = layer;
|
||||
load_keymap_on_keyboard(layer, keymaps[layer]);
|
||||
});
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Keyboard(key buttons)
|
||||
*/
|
||||
// load default keymap on startup
|
||||
load_keymap_on_keyboard(0, keymaps[0]);
|
||||
|
||||
// Select key button to edit
|
||||
$(".key").click(function(ev, ui) {
|
||||
editing_key = $(this).attr('id');
|
||||
|
||||
// grey-out key to indicate being under editing
|
||||
$(".key").removeClass("key-editing");
|
||||
$(this).addClass("key-editing");
|
||||
}).focus(function(ev, ui) {
|
||||
// select editing_key with tab key focus
|
||||
$(this).click();
|
||||
});
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Keycodes button tab
|
||||
*/
|
||||
$("#keycode_tabs").tabs({
|
||||
heightStyle: "auto",
|
||||
});
|
||||
|
||||
// Keycodes: read name and description from code table
|
||||
$(".action").each(function(index) {
|
||||
// get code from code button id: code-[0x]CCCC where CCCC is dec or hex number
|
||||
var code = parseInt($(this).attr('id').match(/code-((0x){0,1}[0-9a-fA-F]+)/)[1]);
|
||||
$(this).text(keycodes[code].name);
|
||||
$(this).attr({ title: keycodes[code].desc });
|
||||
});
|
||||
|
||||
$(".action").click(function(ev,ui) {
|
||||
if (!editing_key) return;
|
||||
|
||||
// get matrix position from key id: key-RC where R is row and C is column in "0-v"(radix 32)
|
||||
var pos = editing_key.match(/key-([0-9a-v])([0-9a-v])/i);
|
||||
if (!pos) return;
|
||||
var row = parseInt(pos[1], 32), col = parseInt(pos[2], 32);
|
||||
|
||||
// set text and tooltip to key button under editing
|
||||
$("#" + editing_key).text($(this).text());
|
||||
$("#" + editing_key).attr({ title: $(this).attr('title'), });
|
||||
|
||||
// change keymap array
|
||||
// get code from keycode button id: code-[0x]CC where CC is dec or hex number
|
||||
var code = $(this).attr('id').match(/code-((0x){0,1}[0-9a-fA-F]+)/)[1];
|
||||
keymaps[editing_layer][row][col] = parseInt(code);
|
||||
|
||||
// give focus on editing_key for next tab key operation
|
||||
$("#" + editing_key).focus();
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
* Share URL
|
||||
*/
|
||||
// Share URL
|
||||
$("#keymap-share").click(function(ev, ui) {
|
||||
var hash = encode_keymap({ keymaps: keymaps });
|
||||
$("#share-url").text(document.location.origin + document.location.pathname + "#" + hash);
|
||||
});
|
||||
|
||||
// Shorten URL
|
||||
$("#shorten-url").click(function(ev, ui) {
|
||||
var hash = encode_keymap({ keymaps: keymaps });
|
||||
var editor_url = document.location.origin + document.location.pathname;
|
||||
window.open("https://bitly.com/shorten/?url=" + encodeURIComponent(editor_url + "#" + hash));
|
||||
//window.open("http://tinyurl.com/create.php?url=" + encodeURIComponent(editor_url + "#" + hash));
|
||||
});
|
||||
|
||||
|
||||
// Hex Save
|
||||
$("#keymap-download").click(function(ev, ui) {
|
||||
var keymap_data = fn_actions.concat(keymaps);
|
||||
var content = firmware_hex() +
|
||||
hex_output(KEYMAP_START_ADDRESS, keymap_data) +
|
||||
hex_eof();
|
||||
|
||||
// download hex file
|
||||
var blob = new Blob([content], {type: "application/octet-stream"});
|
||||
var hex_link = $("#hex-download");
|
||||
hex_link.attr('href', window.URL.createObjectURL(blob));
|
||||
hex_link.attr('download', KEYBOARD_ID + "_firmware.hex");
|
||||
// jQuery click() doesn't work straight for 'a' element
|
||||
// http://stackoverflow.com/questions/1694595/
|
||||
hex_link[0].click();
|
||||
});
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Output options
|
||||
*/
|
||||
//$("#keymap-output").resizable(); // resizable textarea
|
||||
|
||||
// Hex output
|
||||
$("#keymap-hex-generate").click(function(ev, ui) {
|
||||
var keymap_data = fn_actions.concat(keymaps);
|
||||
$("#keymap-output").text(hex_output(KEYMAP_START_ADDRESS, keymap_data));
|
||||
});
|
||||
|
||||
// C source output
|
||||
$("#keymap-source-generate").click(function(ev, ui) {
|
||||
$("#keymap-output").text(source_output(keymaps));
|
||||
});
|
||||
|
||||
// JSON output
|
||||
//$("#keymap-json-generate").css('display', 'none'); // hide
|
||||
$("#keymap-json-generate").click(function(ev, ui) {
|
||||
var keymap_output;
|
||||
//keymap_output = JSON.stringify(keymaps, null, 4);
|
||||
keymap_output = JSON.stringify({ keymaps: keymaps });
|
||||
$("#keymap-output").text(keymap_output);
|
||||
});
|
||||
|
||||
// encode keymap
|
||||
$("#keymap-encode").click(function(ev, ui) {
|
||||
var keymap_output = encode_keymap({ keymaps: keymaps });
|
||||
$("#keymap-output").text(keymap_output);
|
||||
});
|
||||
|
||||
// decode keymap
|
||||
$("#keymap-decode").click(function(ev, ui) {
|
||||
var hash = $("#keymap-output").text();
|
||||
var keymap_output = decode_keymap(hash);
|
||||
$("#keymap-output").text(JSON.stringify(keymap_output));
|
||||
});
|
||||
|
||||
|
||||
|
||||
// lost keymap under edting when leave the page
|
||||
// TODO: needed only if keymap is changed
|
||||
$(window).bind('beforeunload', function(){
|
||||
return 'CAUTION: You will lost your change.';
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Share URL
|
||||
*/
|
||||
function encode_keymap(obj)
|
||||
{
|
||||
if (typeof LZString != "undefined" && typeof Base64 != "undefined") {
|
||||
return Base64.encode(LZString.compress(JSON.stringify(obj)));
|
||||
}
|
||||
return window.btoa(JSON.stringify(obj));
|
||||
}
|
||||
|
||||
function decode_keymap(str)
|
||||
{
|
||||
try {
|
||||
/* lz-string-1.3.3.js: LZString.decompress() runs away if given short string. */
|
||||
if (str == null || typeof str != "string" || str.length < 30) return null;
|
||||
|
||||
if (typeof LZString != "undefined" && typeof Base64 != "undefined") {
|
||||
return JSON.parse(LZString.decompress(Base64.decode(str)));
|
||||
}
|
||||
return JSON.parse(window.atob(str));
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Hex file
|
||||
*/
|
||||
function hexstr2(b)
|
||||
{
|
||||
return ('0'+ b.toString(16)).substr(-2).toUpperCase();
|
||||
}
|
||||
|
||||
function hex_line(address, record_type, data)
|
||||
{
|
||||
var sum = 0;
|
||||
sum += data.length;
|
||||
sum += (address >> 8);
|
||||
sum += (address & 0xff);
|
||||
sum += record_type;
|
||||
|
||||
var line = '';
|
||||
line += ':';
|
||||
line += hexstr2(data.length);
|
||||
line += hexstr2(address >> 8);
|
||||
line += hexstr2(address & 0xff);
|
||||
line += hexstr2(record_type);
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
sum = (sum + data[i]);
|
||||
line += hexstr2(data[i]);
|
||||
}
|
||||
line += hexstr2((~sum + 1)&0xff); // Checksum
|
||||
line +="\r\n";
|
||||
return line;
|
||||
}
|
||||
|
||||
function hex_eof()
|
||||
{
|
||||
return ":00000001FF\r\n";
|
||||
}
|
||||
|
||||
function hex_output(address, data) {
|
||||
var output = '';
|
||||
var line = [];
|
||||
|
||||
// TODO: refine: flatten data into one dimension array
|
||||
[].concat.apply([], [].concat.apply([], data)).forEach(function(e) {
|
||||
line.push(e);
|
||||
if (line.length == 16) {
|
||||
output += hex_line(address, 0x00, line);
|
||||
address += 16;
|
||||
line.length = 0; // clear array
|
||||
}
|
||||
});
|
||||
if (line.length > 0) {
|
||||
output += hex_line(address, 0x00, line);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Source file
|
||||
*/
|
||||
function source_output(keymaps) {
|
||||
var output = '';
|
||||
// fn actions
|
||||
output += "/*\n";
|
||||
output += " * Keymap for " + KEYBOARD_DESC + "\n";;
|
||||
output += " * generated by tmk keymap editor\n";
|
||||
output += " */\n";
|
||||
output += "#include <stdint.h>\n";
|
||||
output += "#include <stdbool.h>\n";
|
||||
output += "#include <avr/pgmspace.h>\n";
|
||||
output += "#include \"keycode.h\"\n";
|
||||
output += "#include \"action.h\"\n";
|
||||
output += "#include \"action_macro.h\"\n";
|
||||
output += "#include \"keymap.h\"\n\n";
|
||||
|
||||
output += "#ifdef KEYMAP_SECTION_ENABLE\n";
|
||||
output += "const uint16_t fn_actions[] __attribute__ ((section (\".keymap.fn_actions\"))) = {\n";
|
||||
output += "#else\n";
|
||||
output += "static const uint16_t fn_actions[] PROGMEM = {\n";
|
||||
output += "#endif\n";
|
||||
output += fn_actions_source;
|
||||
output += "};\n\n";
|
||||
|
||||
// keymaps
|
||||
output += "#ifdef KEYMAP_SECTION_ENABLE\n";
|
||||
output += "const uint8_t keymaps[][";
|
||||
output += keymaps[0].length; // row
|
||||
output += "][";
|
||||
output += keymaps[0][0].length; // col
|
||||
output += "] __attribute__ ((section (\".keymap.keymaps\"))) = {\n";
|
||||
output += "#else\n";
|
||||
output += "static const uint8_t keymaps[][";
|
||||
output += keymaps[0].length; // row
|
||||
output += "][";
|
||||
output += keymaps[0][0].length; // col
|
||||
output += "] PROGMEM = {\n";
|
||||
output += "#endif\n";
|
||||
for (var i in keymaps) {
|
||||
output += " {\n";
|
||||
for (var j in keymaps[i]) {
|
||||
output += " { ";
|
||||
for (var k in keymaps[i][j]) {
|
||||
output += '0x' + ('0' + keymaps[i][j][k].toString(16)).substr(-2);
|
||||
output += ',';
|
||||
}
|
||||
output += " },\n";
|
||||
}
|
||||
output += " },\n";
|
||||
}
|
||||
output += "};\n";
|
||||
return output;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* keycodes
|
||||
*/
|
||||
keycodes = [
|
||||
var keycodes = [
|
||||
// {id, name(text), description(tooltip)}
|
||||
{id: 'NO ', name: 'NO', desc: 'No action'},
|
||||
{id: 'TRNS', name: 'TRNS', desc: 'Transparent'},
|
||||
@ -159,7 +493,7 @@ keycodes = [
|
||||
{id: 'ALT_ERASE', name: 'ALT_ERASE', desc: 'ALT_ERASE'},
|
||||
{id: 'SYSREQ', name: 'SYSREQ', desc: 'SYSREQ'},
|
||||
{id: 'CANCEL', name: 'CANCEL', desc: 'CANCEL'},
|
||||
{id: 'CLEAR', name: 'Clear', desc: 'Clear'},
|
||||
{id: 'CLEAR', name: 'CLEAR', desc: 'CLEAR'},
|
||||
{id: 'PRIOR', name: 'PRIOR', desc: 'PRIOR'},
|
||||
{id: 'RETURN', name: 'RETURN', desc: 'RETURN'},
|
||||
{id: 'SEPARATOR', name: 'SEPARATOR', desc: 'SEPARATOR'},
|
||||
@ -192,8 +526,8 @@ keycodes = [
|
||||
{id: 'WSTP', name: 'Web Stop', desc: 'WWW Stop'},
|
||||
{id: 'WREF', name: 'Web Refresh', desc: 'WWW Refresh'},
|
||||
{id: 'WFAV', name: 'Web Favorites', desc: 'WWW Favorites'},
|
||||
{id: 'RESERVED-187', name: 'RESERVED-187', desc: 'RESERVED-187'},
|
||||
{id: 'RESERVED-188', name: 'RESERVED-188', desc: 'RESERVED-188'},
|
||||
{id: 'MFFD', name: 'Fast Forward', desc: 'Media Fast Forward(Mac)'},
|
||||
{id: 'MRWD', name: 'Rewind', desc: 'Media Rewind(Mac)'},
|
||||
{id: 'RESERVED-189', name: 'RESERVED-189', desc: 'RESERVED-189'},
|
||||
{id: 'RESERVED-190', name: 'RESERVED-190', desc: 'RESERVED-190'},
|
||||
{id: 'RESERVED-191', name: 'RESERVED-191', desc: 'RESERVED-191'},
|
||||
@ -335,4 +669,3 @@ keycodes = [
|
||||
{id: 'ACL1', name: 'Mouse Medium', desc: 'Mouse Medium'},
|
||||
{id: 'ACL2', name: 'Mouse Fast', desc: 'Mouse Fast'},
|
||||
];
|
||||
|
@ -1,142 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Base64 encode / decode
|
||||
* http://www.webtoolkit.info/
|
||||
*
|
||||
**/
|
||||
|
||||
var Base64 = {
|
||||
|
||||
// private property
|
||||
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
||||
|
||||
// public method for encoding
|
||||
encode : function (input) {
|
||||
var output = "";
|
||||
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
||||
var i = 0;
|
||||
|
||||
input = Base64._utf8_encode(input);
|
||||
|
||||
while (i < input.length) {
|
||||
|
||||
chr1 = input.charCodeAt(i++);
|
||||
chr2 = input.charCodeAt(i++);
|
||||
chr3 = input.charCodeAt(i++);
|
||||
|
||||
enc1 = chr1 >> 2;
|
||||
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
||||
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
||||
enc4 = chr3 & 63;
|
||||
|
||||
if (isNaN(chr2)) {
|
||||
enc3 = enc4 = 64;
|
||||
} else if (isNaN(chr3)) {
|
||||
enc4 = 64;
|
||||
}
|
||||
|
||||
output = output +
|
||||
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
|
||||
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
|
||||
|
||||
}
|
||||
|
||||
return output;
|
||||
},
|
||||
|
||||
// public method for decoding
|
||||
decode : function (input) {
|
||||
var output = "";
|
||||
var chr1, chr2, chr3;
|
||||
var enc1, enc2, enc3, enc4;
|
||||
var i = 0;
|
||||
|
||||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
||||
|
||||
while (i < input.length) {
|
||||
|
||||
enc1 = this._keyStr.indexOf(input.charAt(i++));
|
||||
enc2 = this._keyStr.indexOf(input.charAt(i++));
|
||||
enc3 = this._keyStr.indexOf(input.charAt(i++));
|
||||
enc4 = this._keyStr.indexOf(input.charAt(i++));
|
||||
|
||||
chr1 = (enc1 << 2) | (enc2 >> 4);
|
||||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
||||
chr3 = ((enc3 & 3) << 6) | enc4;
|
||||
|
||||
output = output + String.fromCharCode(chr1);
|
||||
|
||||
if (enc3 != 64) {
|
||||
output = output + String.fromCharCode(chr2);
|
||||
}
|
||||
if (enc4 != 64) {
|
||||
output = output + String.fromCharCode(chr3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
output = Base64._utf8_decode(output);
|
||||
|
||||
return output;
|
||||
|
||||
},
|
||||
|
||||
// private method for UTF-8 encoding
|
||||
_utf8_encode : function (string) {
|
||||
string = string.replace(/\r\n/g,"\n");
|
||||
var utftext = "";
|
||||
|
||||
for (var n = 0; n < string.length; n++) {
|
||||
|
||||
var c = string.charCodeAt(n);
|
||||
|
||||
if (c < 128) {
|
||||
utftext += String.fromCharCode(c);
|
||||
}
|
||||
else if((c > 127) && (c < 2048)) {
|
||||
utftext += String.fromCharCode((c >> 6) | 192);
|
||||
utftext += String.fromCharCode((c & 63) | 128);
|
||||
}
|
||||
else {
|
||||
utftext += String.fromCharCode((c >> 12) | 224);
|
||||
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
||||
utftext += String.fromCharCode((c & 63) | 128);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return utftext;
|
||||
},
|
||||
|
||||
// private method for UTF-8 decoding
|
||||
_utf8_decode : function (utftext) {
|
||||
var string = "";
|
||||
var i = 0;
|
||||
var c = c1 = c2 = 0;
|
||||
|
||||
while ( i < utftext.length ) {
|
||||
|
||||
c = utftext.charCodeAt(i);
|
||||
|
||||
if (c < 128) {
|
||||
string += String.fromCharCode(c);
|
||||
i++;
|
||||
}
|
||||
else if((c > 191) && (c < 224)) {
|
||||
c2 = utftext.charCodeAt(i+1);
|
||||
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
||||
i += 2;
|
||||
}
|
||||
else {
|
||||
c2 = utftext.charCodeAt(i+1);
|
||||
c3 = utftext.charCodeAt(i+2);
|
||||
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
||||
i += 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
}
|
2643
editor/m0110/firmware.js
Normal file
2643
editor/m0110/firmware.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,346 +0,0 @@
|
||||
/*
|
||||
* TMK keymap editor
|
||||
*/
|
||||
// key id under editing
|
||||
var editing_key;
|
||||
// layer under editing
|
||||
var editing_layer = 0;
|
||||
|
||||
// load keymap on keyboard key buttons
|
||||
var load_keymap_on_keyboard = function(layer, keymap) {
|
||||
for (var row in keymap) {
|
||||
for (var col in keymap[row]) {
|
||||
var code = keymap[row][col];
|
||||
var key = keycodes[code];
|
||||
// row and column takes range of 0-32(0-9a-v)
|
||||
$("#key-" + parseInt(row).toString(32) + parseInt(col).toString(32)).text(key.name);
|
||||
$("#key-" + parseInt(row).toString(32) + parseInt(col).toString(32)).attr({ title: key.desc });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$(function() {
|
||||
// Title
|
||||
document.title = "TMK Keymap Editor for " + KEYBOARD_ID;
|
||||
$("#page-title").text("TMK Keymap Editor for " + KEYBOARD_ID);
|
||||
|
||||
/*
|
||||
* load keymap from URL hash
|
||||
*/
|
||||
var decoded = decode_keymap(document.location.hash.substring(1));
|
||||
if (decoded != null) {
|
||||
keymaps = decoded['keymaps'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Layer selector
|
||||
*/
|
||||
$("#layer_radio").buttonset();
|
||||
|
||||
// layer change
|
||||
$(".layer").click(function(ev, ui) {
|
||||
var layer = parseInt($(this).attr('id').match(/layer-(\d+)/)[1]);
|
||||
editing_layer = layer;
|
||||
load_keymap_on_keyboard(layer, keymaps[layer]);
|
||||
});
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Keyboard(key buttons)
|
||||
*/
|
||||
// load default keymap on startup
|
||||
load_keymap_on_keyboard(0, keymaps[0]);
|
||||
|
||||
// Select key button to edit
|
||||
$(".key").click(function(ev, ui) {
|
||||
editing_key = $(this).attr('id');
|
||||
|
||||
// grey-out key to indicate being under editing
|
||||
$(".key").removeClass("key-editing");
|
||||
$(this).addClass("key-editing");
|
||||
}).focus(function(ev, ui) {
|
||||
// select editing_key with tab key focus
|
||||
$(this).click();
|
||||
});
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Keycodes button tab
|
||||
*/
|
||||
$("#keycode_tabs").tabs({
|
||||
heightStyle: "auto",
|
||||
});
|
||||
|
||||
// Keycodes: read name and description from code table
|
||||
$(".action").each(function(index) {
|
||||
// get code from code button id: code-[0x]CCCC where CCCC is dec or hex number
|
||||
var code = parseInt($(this).attr('id').match(/code-((0x){0,1}[0-9a-fA-F]+)/)[1]);
|
||||
$(this).text(keycodes[code].name);
|
||||
$(this).attr({ title: keycodes[code].desc });
|
||||
});
|
||||
|
||||
$(".action").click(function(ev,ui) {
|
||||
if (!editing_key) return;
|
||||
|
||||
// get matrix position from key id: key-RC where R is row and C is column in "0-v"(radix 32)
|
||||
var pos = editing_key.match(/key-([0-9a-v])([0-9a-v])/i);
|
||||
if (!pos) return;
|
||||
var row = parseInt(pos[1], 32), col = parseInt(pos[2], 32);
|
||||
|
||||
// set text and tooltip to key button under editing
|
||||
$("#" + editing_key).text($(this).text());
|
||||
$("#" + editing_key).attr({ title: $(this).attr('title'), });
|
||||
|
||||
// change keymap array
|
||||
// get code from keycode button id: code-[0x]CC where CC is dec or hex number
|
||||
var code = $(this).attr('id').match(/code-((0x){0,1}[0-9a-fA-F]+)/)[1];
|
||||
keymaps[editing_layer][row][col] = parseInt(code);
|
||||
|
||||
// give focus on editing_key for next tab key operation
|
||||
$("#" + editing_key).focus();
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
* Share URL
|
||||
*/
|
||||
// Share URL
|
||||
$("#keymap-share").click(function(ev, ui) {
|
||||
var hash = encode_keymap({ keymaps: keymaps });
|
||||
$("#share-url").text(document.location.origin + document.location.pathname + "#" + hash);
|
||||
});
|
||||
|
||||
// Shorten URL
|
||||
$("#shorten-url").click(function(ev, ui) {
|
||||
var hash = encode_keymap({ keymaps: keymaps });
|
||||
var editor_url = document.location.origin + document.location.pathname;
|
||||
window.open("https://bitly.com/shorten/?url=" + encodeURIComponent(editor_url + "#" + hash));
|
||||
//window.open("http://tinyurl.com/create.php?url=" + encodeURIComponent(editor_url + "#" + hash));
|
||||
});
|
||||
|
||||
|
||||
// Hex Save
|
||||
$("#keymap-download").click(function(ev, ui) {
|
||||
var keymap_data = fn_actions.concat(keymaps);
|
||||
var content = firmware_hex() +
|
||||
hex_output(KEYMAP_START_ADDRESS, keymap_data) +
|
||||
hex_eof();
|
||||
|
||||
// download hex file
|
||||
var blob = new Blob([content], {type: "application/octet-stream"});
|
||||
var hex_link = $("#hex-download");
|
||||
hex_link.attr('href', window.URL.createObjectURL(blob));
|
||||
hex_link.attr('download', KEYBOARD_ID + "_firmware.hex");
|
||||
// jQuery click() doesn't work straight for 'a' element
|
||||
// http://stackoverflow.com/questions/1694595/
|
||||
hex_link[0].click();
|
||||
});
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Output options
|
||||
*/
|
||||
//$("#keymap-output").resizable(); // resizable textarea
|
||||
|
||||
// Hex output
|
||||
$("#keymap-hex-generate").click(function(ev, ui) {
|
||||
var keymap_data = fn_actions.concat(keymaps);
|
||||
$("#keymap-output").text(hex_output(KEYMAP_START_ADDRESS, keymap_data));
|
||||
});
|
||||
|
||||
// C source output
|
||||
$("#keymap-source-generate").click(function(ev, ui) {
|
||||
$("#keymap-output").text(source_output(keymaps));
|
||||
});
|
||||
|
||||
// JSON output
|
||||
//$("#keymap-json-generate").css('display', 'none'); // hide
|
||||
$("#keymap-json-generate").click(function(ev, ui) {
|
||||
var keymap_output;
|
||||
//keymap_output = JSON.stringify(keymaps, null, 4);
|
||||
keymap_output = JSON.stringify({ keymaps: keymaps });
|
||||
$("#keymap-output").text(keymap_output);
|
||||
});
|
||||
|
||||
// encode keymap
|
||||
$("#keymap-encode").click(function(ev, ui) {
|
||||
var keymap_output = encode_keymap({ keymaps: keymaps });
|
||||
$("#keymap-output").text(keymap_output);
|
||||
});
|
||||
|
||||
// decode keymap
|
||||
$("#keymap-decode").click(function(ev, ui) {
|
||||
var hash = $("#keymap-output").text();
|
||||
var keymap_output = decode_keymap(hash);
|
||||
$("#keymap-output").text(JSON.stringify(keymap_output));
|
||||
});
|
||||
|
||||
|
||||
|
||||
// lost keymap under edting when leave the page
|
||||
/* TODO: Needed when released
|
||||
$(window).bind('beforeunload', function(){
|
||||
return 'CAUTION: You will lost your change.';
|
||||
});
|
||||
*/
|
||||
});
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Share URL
|
||||
*/
|
||||
function encode_keymap(obj)
|
||||
{
|
||||
if (typeof LZString != "undefined" && typeof Base64 != "undefined") {
|
||||
return Base64.encode(LZString.compress(JSON.stringify(obj)));
|
||||
}
|
||||
return window.btoa(JSON.stringify(obj));
|
||||
}
|
||||
|
||||
function decode_keymap(str)
|
||||
{
|
||||
try {
|
||||
/* lz-string-1.3.3.js: LZString.decompress() runs away if given short string. */
|
||||
if (str == null || typeof str != "string" || str.length < 30) return null;
|
||||
|
||||
if (typeof LZString != "undefined" && typeof Base64 != "undefined") {
|
||||
return JSON.parse(LZString.decompress(Base64.decode(str)));
|
||||
}
|
||||
return JSON.parse(window.atob(str));
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Hex file
|
||||
*/
|
||||
function hexstr2(b)
|
||||
{
|
||||
return ('0'+ b.toString(16)).substr(-2).toUpperCase();
|
||||
}
|
||||
|
||||
function hex_line(address, record_type, data)
|
||||
{
|
||||
var sum = 0;
|
||||
sum += data.length;
|
||||
sum += (address >> 8);
|
||||
sum += (address & 0xff);
|
||||
sum += record_type;
|
||||
|
||||
var line = '';
|
||||
line += ':';
|
||||
line += hexstr2(data.length);
|
||||
line += hexstr2(address >> 8);
|
||||
line += hexstr2(address & 0xff);
|
||||
line += hexstr2(record_type);
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
sum = (sum + data[i]);
|
||||
line += hexstr2(data[i]);
|
||||
}
|
||||
line += hexstr2((~sum + 1)&0xff); // Checksum
|
||||
line +="\r\n";
|
||||
return line;
|
||||
}
|
||||
|
||||
function hex_eof()
|
||||
{
|
||||
return ":00000001FF\r\n";
|
||||
}
|
||||
|
||||
function hex_output(address, data) {
|
||||
var output = '';
|
||||
var line = [];
|
||||
|
||||
// TODO: refine: flatten data into one dimension array
|
||||
[].concat.apply([], [].concat.apply([], data)).forEach(function(e) {
|
||||
line.push(e);
|
||||
if (line.length == 16) {
|
||||
output += hex_line(address, 0x00, line);
|
||||
address += 16;
|
||||
line.length = 0; // clear array
|
||||
}
|
||||
});
|
||||
if (line.length > 0) {
|
||||
output += hex_line(address, 0x00, line);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Source file
|
||||
*/
|
||||
function source_output(keymaps) {
|
||||
var output = '';
|
||||
// fn actions
|
||||
output += "/*\n";
|
||||
output += " * Keymap for " + KEYBOARD_ID + "\n";;
|
||||
output += " * generated by tmk keymap editor\n";
|
||||
output += " */\n";
|
||||
output += "#include <stdint.h>\n";
|
||||
output += "#include <stdbool.h>\n";
|
||||
output += "#include <avr/pgmspace.h>\n";
|
||||
output += "#include \"keycode.h\"\n";
|
||||
output += "#include \"action.h\"\n";
|
||||
output += "#include \"action_macro.h\"\n";
|
||||
output += "#include \"keymap.h\"\n\n";
|
||||
|
||||
output += "#ifdef KEYMAP_SECTION_ENABLE\n";
|
||||
output += "const uint16_t fn_actions[] __attribute__ ((section (\".keymap.fn_actions\"))) = {\n";
|
||||
output += "#else\n";
|
||||
output += "static const uint16_t fn_actions[] PROGMEM = {\n";
|
||||
output += "#endif\n";
|
||||
output += fn_actions_source;
|
||||
output += "};\n\n";
|
||||
|
||||
// keymaps
|
||||
output += "#ifdef KEYMAP_SECTION_ENABLE\n";
|
||||
output += "const uint8_t keymaps[][";
|
||||
output += keymaps[0].length; // row
|
||||
output += "][";
|
||||
output += keymaps[0][0].length; // col
|
||||
output += "] __attribute__ ((section (\".keymap.keymaps\"))) = {\n";
|
||||
output += "#else\n";
|
||||
output += "static const uint8_t keymaps[][";
|
||||
output += keymaps[0].length; // row
|
||||
output += "][";
|
||||
output += keymaps[0][0].length; // col
|
||||
output += "] PROGMEM = {\n";
|
||||
output += "#endif\n";
|
||||
for (var i in keymaps) {
|
||||
output += " {\n";
|
||||
for (var j in keymaps[i]) {
|
||||
output += " { ";
|
||||
for (var k in keymaps[i][j]) {
|
||||
output += '0x' + ('0' + keymaps[i][j][k].toString(16)).substr(-2);
|
||||
output += ',';
|
||||
}
|
||||
output += " },\n";
|
||||
}
|
||||
output += " },\n";
|
||||
}
|
||||
output += "};\n";
|
||||
output += "\n";
|
||||
output += "/* translates key to keycode */\n";
|
||||
output += "uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)\n";
|
||||
output += "{\n";
|
||||
output += " return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);\n";
|
||||
output += "}\n";
|
||||
output += "\n";
|
||||
output += "/* translates Fn index to action */\n";
|
||||
output += "action_t keymap_fn_to_action(uint8_t keycode)\n";
|
||||
output += "{\n";
|
||||
output += " action_t action;\n";
|
||||
output += " action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);\n";
|
||||
output += " return action;\n";
|
||||
output += "}\n";
|
||||
return output;
|
||||
};
|
@ -1,204 +0,0 @@
|
||||
// Copyright © 2013 Pieroxy <pieroxy@pieroxy.net>
|
||||
// This work is free. You can redistribute it and/or modify it
|
||||
// under the terms of the WTFPL, Version 2
|
||||
// For more information see LICENSE.txt or http://www.wtfpl.net/
|
||||
//
|
||||
// LZ-based compression algorithm, version 1.0.2-rc1
|
||||
var LZString = {
|
||||
|
||||
writeBit : function(value, data) {
|
||||
data.val = (data.val << 1) | value;
|
||||
if (data.position == 15) {
|
||||
data.position = 0;
|
||||
data.string += String.fromCharCode(data.val);
|
||||
data.val = 0;
|
||||
} else {
|
||||
data.position++;
|
||||
}
|
||||
},
|
||||
|
||||
writeBits : function(numBits, value, data) {
|
||||
if (typeof(value)=="string")
|
||||
value = value.charCodeAt(0);
|
||||
for (var i=0 ; i<numBits ; i++) {
|
||||
this.writeBit(value&1, data);
|
||||
value = value >> 1;
|
||||
}
|
||||
},
|
||||
|
||||
produceW : function (context) {
|
||||
if (Object.prototype.hasOwnProperty.call(context.dictionaryToCreate,context.w)) {
|
||||
if (context.w.charCodeAt(0)<256) {
|
||||
this.writeBits(context.numBits, 0, context.data);
|
||||
this.writeBits(8, context.w, context.data);
|
||||
} else {
|
||||
this.writeBits(context.numBits, 1, context.data);
|
||||
this.writeBits(16, context.w, context.data);
|
||||
}
|
||||
this.decrementEnlargeIn(context);
|
||||
delete context.dictionaryToCreate[context.w];
|
||||
} else {
|
||||
this.writeBits(context.numBits, context.dictionary[context.w], context.data);
|
||||
}
|
||||
this.decrementEnlargeIn(context);
|
||||
},
|
||||
|
||||
decrementEnlargeIn : function(context) {
|
||||
context.enlargeIn--;
|
||||
if (context.enlargeIn == 0) {
|
||||
context.enlargeIn = Math.pow(2, context.numBits);
|
||||
context.numBits++;
|
||||
}
|
||||
},
|
||||
|
||||
compress: function (uncompressed) {
|
||||
var context = {
|
||||
dictionary: {},
|
||||
dictionaryToCreate: {},
|
||||
c:"",
|
||||
wc:"",
|
||||
w:"",
|
||||
enlargeIn: 2, // Compensate for the first entry which should not count
|
||||
dictSize: 3,
|
||||
numBits: 2,
|
||||
result: "",
|
||||
data: {string:"", val:0, position:0}
|
||||
}, i;
|
||||
|
||||
for (i = 0; i < uncompressed.length; i += 1) {
|
||||
context.c = uncompressed.charAt(i);
|
||||
if (!Object.prototype.hasOwnProperty.call(context.dictionary,context.c)) {
|
||||
context.dictionary[context.c] = context.dictSize++;
|
||||
context.dictionaryToCreate[context.c] = true;
|
||||
}
|
||||
|
||||
context.wc = context.w + context.c;
|
||||
if (Object.prototype.hasOwnProperty.call(context.dictionary,context.wc)) {
|
||||
context.w = context.wc;
|
||||
} else {
|
||||
this.produceW(context);
|
||||
// Add wc to the dictionary.
|
||||
context.dictionary[context.wc] = context.dictSize++;
|
||||
context.w = String(context.c);
|
||||
}
|
||||
}
|
||||
|
||||
// Output the code for w.
|
||||
if (context.w !== "") {
|
||||
this.produceW(context);
|
||||
}
|
||||
|
||||
// Mark the end of the stream
|
||||
this.writeBits(context.numBits, 2, context.data);
|
||||
|
||||
// Flush the last char
|
||||
while (context.data.val>0) this.writeBit(0,context.data)
|
||||
return context.data.string;
|
||||
},
|
||||
|
||||
readBit : function(data) {
|
||||
var res = data.val & data.position;
|
||||
data.position >>= 1;
|
||||
if (data.position == 0) {
|
||||
data.position = 32768;
|
||||
data.val = data.string.charCodeAt(data.index++);
|
||||
}
|
||||
//data.val = (data.val << 1);
|
||||
return res>0 ? 1 : 0;
|
||||
},
|
||||
|
||||
readBits : function(numBits, data) {
|
||||
var res = 0;
|
||||
var maxpower = Math.pow(2,numBits);
|
||||
var power=1;
|
||||
while (power!=maxpower) {
|
||||
res |= this.readBit(data) * power;
|
||||
power <<= 1;
|
||||
}
|
||||
return res;
|
||||
},
|
||||
|
||||
decompress: function (compressed) {
|
||||
var dictionary = {},
|
||||
next,
|
||||
enlargeIn = 4,
|
||||
dictSize = 4,
|
||||
numBits = 3,
|
||||
entry = "",
|
||||
result = "",
|
||||
i,
|
||||
w,
|
||||
c,
|
||||
errorCount=0,
|
||||
literal,
|
||||
data = {string:compressed, val:compressed.charCodeAt(0), position:32768, index:1};
|
||||
|
||||
for (i = 0; i < 3; i += 1) {
|
||||
dictionary[i] = i;
|
||||
}
|
||||
|
||||
next = this.readBits(2, data);
|
||||
switch (next) {
|
||||
case 0:
|
||||
c = String.fromCharCode(this.readBits(8, data));
|
||||
break;
|
||||
case 1:
|
||||
c = String.fromCharCode(this.readBits(16, data));
|
||||
break;
|
||||
case 2:
|
||||
return "";
|
||||
}
|
||||
dictionary[3] = c;
|
||||
w = result = c;
|
||||
while (true) {
|
||||
c = this.readBits(numBits, data);
|
||||
|
||||
switch (c) {
|
||||
case 0:
|
||||
if (errorCount++ > 10000) return "Error";
|
||||
c = String.fromCharCode(this.readBits(8, data));
|
||||
dictionary[dictSize++] = c;
|
||||
c = dictSize-1;
|
||||
enlargeIn--;
|
||||
break;
|
||||
case 1:
|
||||
c = String.fromCharCode(this.readBits(16, data));
|
||||
dictionary[dictSize++] = c;
|
||||
c = dictSize-1;
|
||||
enlargeIn--;
|
||||
break;
|
||||
case 2:
|
||||
return result;
|
||||
}
|
||||
|
||||
if (enlargeIn == 0) {
|
||||
enlargeIn = Math.pow(2, numBits);
|
||||
numBits++;
|
||||
}
|
||||
|
||||
if (dictionary[c]) {
|
||||
entry = dictionary[c];
|
||||
} else {
|
||||
if (c === dictSize) {
|
||||
entry = w + w.charAt(0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
result += entry;
|
||||
|
||||
// Add w+entry[0] to the dictionary.
|
||||
dictionary[dictSize++] = w + entry.charAt(0);
|
||||
enlargeIn--;
|
||||
|
||||
w = entry;
|
||||
|
||||
if (enlargeIn == 0) {
|
||||
enlargeIn = Math.pow(2, numBits);
|
||||
numBits++;
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
@ -5,19 +5,23 @@
|
||||
<link rel="stylesheet" href="keymap_editor.css" type="text/css">
|
||||
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
|
||||
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
|
||||
<script src="keymap_editor.js"></script>
|
||||
<script src="keycodes.js"></script>
|
||||
<script src="m0110.js"></script>
|
||||
<script src="../common/keymap_editor.js"></script>
|
||||
<!-- lz-string-1.3.3.js: LZString.decompress() runs away if given short string. -->
|
||||
<script src="lz-string-1.0.2.js"></script>
|
||||
<script src="base64.js"></script>
|
||||
<script src="../common/lz-string-1.0.2.js"></script>
|
||||
<script src="../common/base64.js"></script>
|
||||
<script src="firmware.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1 id="page-title">TMK Keymap Editor</h1>
|
||||
<div align="right">for TMK Converter Rev.1(ATMega32U4)</div>
|
||||
<div align="right">Converter Revision(See <a href="https://geekhack.org/index.php?topic=24965.msg470309#msg470309" target="_blank">this</a>):
|
||||
<select id=revision>
|
||||
<option value="rev1">Rev.1</option>
|
||||
<option value="rev2" selected>Rev.2</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<h2>M0110 + M0120</h2>
|
||||
<h2>Apple Macintosh M0110 + M0120</h2>
|
||||
<div id="keyboard-pane" class="keyboard-pane">
|
||||
<form>
|
||||
<div id="layer_radio">
|
||||
@ -139,12 +143,13 @@
|
||||
<div class="key spc100"></div>
|
||||
<div id="key-a2" class="key btn200" tabindex="9"></div>
|
||||
<div id="key-81" class="key" tabindex="9"></div>
|
||||
<div id="key-nc94" class="key-nc"></div>
|
||||
<div id="key-nc94" class="key-nc">*3</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<p>*1: identical to Left Shift key</p>
|
||||
<p>*2: identical to Left Alt(Opt) key</p>
|
||||
<p>*3: not existent</p>
|
||||
</div>
|
||||
|
||||
|
||||
@ -414,6 +419,8 @@
|
||||
<button class="action" id="code-174"></button>
|
||||
<button class="action" id="code-175"></button>
|
||||
<button class="action" id="code-176"></button>
|
||||
<button class="action" id="code-187"></button>
|
||||
<button class="action" id="code-188"></button>
|
||||
<br>
|
||||
|
||||
Application:<br>
|
||||
@ -433,8 +440,6 @@
|
||||
<br>
|
||||
|
||||
<!--
|
||||
<button class="action" id="code-187"></button>
|
||||
<button class="action" id="code-188"></button>
|
||||
<button class="action" id="code-189"></button>
|
||||
<button class="action" id="code-190"></button>
|
||||
<button class="action" id="code-191"></button>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,19 +5,23 @@
|
||||
<link rel="stylesheet" href="keymap_editor.css" type="text/css">
|
||||
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
|
||||
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
|
||||
<script src="keymap_editor.js"></script>
|
||||
<script src="keycodes.js"></script>
|
||||
<script src="m0110.js"></script>
|
||||
<script src="../common/keymap_editor.js"></script>
|
||||
<!-- lz-string-1.3.3.js: LZString.decompress() runs away if given short string. -->
|
||||
<script src="lz-string-1.0.2.js"></script>
|
||||
<script src="base64.js"></script>
|
||||
<script src="../common/lz-string-1.0.2.js"></script>
|
||||
<script src="../common/base64.js"></script>
|
||||
<script src="firmware.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1 id="page-title">TMK Keymap Editor</h1>
|
||||
<div align="right">for TMK Converter Rev.1(ATMega32U4)</div>
|
||||
<div align="right">Converter Revision(See <a href="https://geekhack.org/index.php?topic=24965.msg470309#msg470309" target="_blank">this</a>):
|
||||
<select id=revision>
|
||||
<option value="rev1">Rev.1</option>
|
||||
<option value="rev2" selected>Rev.2</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<h2>M0110A</h2>
|
||||
<h2>Apple Macintosh M0110A</h2>
|
||||
<div id="keyboard-pane" class="keyboard-pane">
|
||||
<form>
|
||||
<div id="layer_radio">
|
||||
@ -140,7 +144,7 @@
|
||||
<div class="key spc100"></div>
|
||||
<div id="key-a2" class="key btn200" tabindex="9"></div>
|
||||
<div id="key-81" class="key" tabindex="9"></div>
|
||||
<div id="key-nc94" class="key-nc"></div>
|
||||
<div id="key-nc94" class="key-nc">*2</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@ -415,6 +419,8 @@
|
||||
<button class="action" id="code-174"></button>
|
||||
<button class="action" id="code-175"></button>
|
||||
<button class="action" id="code-176"></button>
|
||||
<button class="action" id="code-187"></button>
|
||||
<button class="action" id="code-188"></button>
|
||||
<br>
|
||||
|
||||
Application:<br>
|
||||
@ -434,8 +440,6 @@
|
||||
<br>
|
||||
|
||||
<!--
|
||||
<button class="action" id="code-187"></button>
|
||||
<button class="action" id="code-188"></button>
|
||||
<button class="action" id="code-189"></button>
|
||||
<button class="action" id="code-190"></button>
|
||||
<button class="action" id="code-191"></button>
|
||||
|
Loading…
Reference in New Issue
Block a user