Yado i've just started to try BASIC Engine NG and i've troubles on my keyboard cause i cant write this character |
do you think is possibile to add italian kryboard support ?
Yes, it is. Please look at this file: https://github.com/uli/basicengine-firmware/blob/nextgen/h3/TKeyboard.cpp
You will find declarations of arrays such as usb2jp
, usb2us
etc. You will have to add a corresponding entry for Italian keyboards (usb2it
) that maps the keys to the right characters, and then add usb2it
to the usb2ascii
array. Make sure that "special" (non-ASCII) characters are preceded by U
, and that your editor saves the file as UTF-8. I would recommend to copy one of the existing layouts and to change the keys that are different.
If Italian keyboards have "AltGr" key combos, you will also have to add some special handling in the process_usb_keyboard()
function. Look at this block for Spanish:
} else if (keyboard_layout == 4 && kev->ALTGR) {
// Spanish Alt Gr combos
switch (kc) {
case 0x35: kev->code = '\\'; break; // grave
case 0x1e: kev->code = '|'; break; // 1
case 0x1f: kev->code = '@'; break; // 2
case 0x20: kev->code = '#'; break; // 3
case 0x21: kev->code = '~'; break; // 4 XXX; dead key
case 0x22: kev->code = U'½'; break; // 5
case 0x08: kev->code = U'€'; break; // e
case 0x23: kev->code = U'¬'; break; // 6
case 0x2f: kev->code = '['; break; // [
case 0x30: kev->code = ']'; break; // ]
case 0x34: kev->code = '{'; break; // '
case 0x31: kev->code = '}'; break; // backslash
default: kev->code = 0; break;
}
Add a block like that for the Italian layout:
} else if (keyboard_layout == 5 && kev->ALTGR) {
// Italian AltGr combos
switch (kc) {
[insert key combos here]
default: kev->code = 0; break;
}
The values (the 0x35
in case 0x35:
, for instance) are USB scan codes. Here's a table: https://gist.github.com/ekaitz-zarraga/2b25b94b711684ba4e969e5a5723969b
You will then have to look at https://github.com/uli/basicengine-firmware/blob/nextgen/ttbasic/basic_config.cpp and the Basic::iconfig()
method. Go where it says
if (value < 0 || value > 4) {
E_VALUE(0, 4);
and change 4
to 5
to make sure the new layout can actually be selected. Don't forget to add documentation for the new layout where it says
* `1`: Keyboard layout +
Four different keyboard layouts are supported: +
`0` (Japanese), `1` (US English, default), `2` (German), `3` (French)
and `4` (Spanish).
And, presto. Italian keyboard support. Send me the result when you're done. If there is something that doesn't work, I'll fix it up. Thanks. 🙂