//=============================================== // ver 2.05s (ported to SLCD5) //=============================================== // These macros implement an Imitation KeyBoard // with an appearance that makes the name 'iKB' // seem appropriate. // There are a few differences between the iKB // and it's 'mentor': the characters '"' & '\' // (double-quote & backslash) can't be used be- // cause they must be stored as the pairs '\"' // & '\\', which is incompatible with the code. // The '€'(euro) character is not available in // the standard SLCD character sets, so it was // replaced by the '¢' (cent) symbol. Double- // quote & backslash were replaced by 'º' (deg) // and '²' ('squared'), and 'µ' was also added, // as were '¼' and '½' ('quarter' and 'half'). // The 'symbol KB' was rearranged a bit so that // the currency symbols (¢,£,¥) can be replaced // by the 'math operators' (²,×,±) w/a coherent // layout. See the 'symbols_kb' macro for lines // to comment/un-comment if you prefer (¢,£,¥). // Finally, the 5 'punctuation' symbols (.,?!') // on the 'symbols KB' (which were duplicates) // were replaced by often used foreign-language // chars: '«', '»', '¿', '¡', and '·'. // Note: the order of the punctuation marks was // reversed to better match that of a normal US // keyboard; this improves accuracy for 'touch // typists'. The '$' & '@' chars were switched // with '#' & '%'. This (a) groups the currency // symbols together and (b) puts '#' & '%' on // the 'numbers' KB, which is a more convenient // place for them (e.g. #12, 10%). // It is unknown if there are copyright issues, // so if this is a concern, YOU are responsible // for all the legal stuff. // Otherwise, these macros are hereby placed in // the public domain for use & enjoyment by all // Reach Tech customers. // Special thanks to Steve Peterson @ ReachTech // who made some great suggestions for improved // (and more reliable) performance, and who put // considerable effort into finding and fixing // several bugs in the SLCD firmware related to // keyboards with shift keys. // (C) 2010 by Jim van Zee (02 Nov 2010) // Lab Data Systems // 268 NE 42nd Street, Seattle, WA 98105 // jim(dot)van(dot)zee(at)gmail(dot)com //=============================================== // This version has 'generic' special keys and // 'math' symbols. Only bmp's #1-5 are needed. //=============================================== //=============================================== // Calling macro for the iKB demo (#1 so it will // 'play' if RX & TX are jumpered at power-up). #define iKB_demo s 0 1 z // black on light grey (s 0 10) S 000000 D5D2D5 o `(`Xc`-240)` `(`Yc`-136)` r 0 0 479 271 1 D5D2D5 p1 r -1 -1 480 272 r -2 -2 481 273 // Buttons 10:42 are used by the KB (with // a few omissions). Buttons 128:133 are // used by the Help/About macros. f 16B // we use this font throughout the demo ta CT t "Imitation KeyBoard (iKB)" 240 8 m draw_help_about_buttons // Set repeat freq for DEL & SPACE //typematic 75 10 // Note: beep volume can be changed on the // Help screen m alpha_kb_lower // clear string memory mpop -1 // display '_' to show where string goes m keypress "" // clear 's0' (holds scrolled line - v.i.) set s0 "" // start with slow scrolling set i0 1 // iKB uses 'i0', 'p0' & 's0', the latter // to hold the line that scrolls up. 'i0' // selects the scroll rate: 0=fast,1=slow // This can be changed on the 'Help' page // and would not normally be an option. // If multi-line output is not necessary, // then 'p0' is the only variable needed. #end //=============================================== //=============================================== // macro called by all KB chars // set up with an 'xaq' command // arg = character #define keypress mpush "`0`" t "`M`_" 3 90 #end //=============================================== //=============================================== // macro called by the 'Del' key #define delete_key mpop 1 //t "`M`_" 3 90 saves a macro call m keypress "" // change to BG color S D5D2D5 D5D2D5 // Wipe out deleted char t "W" S 000000 D5D2D5 // 'W' is the Widest char #end //=============================================== //=============================================== // Macro to remove the prompt char: '_' // Here to facilitate matching x,y loc #define remove_prompt // match x,y with 'keypress' t "`M`" 3 90 S D5D2D5 D5D2D5 t "__" S 000000 D5D2D5 #end //=============================================== //=============================================== // macro to set up KB keys // p0 is current position // which is incremented each time // arg2 = 'button number' // arg3 = 'button caption' #define drawkey bdc `2` `p0` 1 "`3`" 1 1 xaq `2` p keypress "`3`" // increment x loc of key set p0 `(`0`+48)` `1` #end // macro to set up punc keys // same as drawkey, w/bigger incr #define drawpnc bdc `2` `p0` 1 "`3`" 2 2 xaq `2` p keypress "`3`" // punc keys are wider set p0 `(`0`+68)` `1` #end // put all row coordinates here // row spacing is 48 pixels but // alpha & numeric KBs have dif // row2 starting points #define set_row :r1 set p0 3 123 :r2a set p0 27 161 :r2n set p0 3 161 :r3 set p0 75 199 :r30 set p0 3 199 :r4 set p0 3 237 #end //=============================================== //=============================================== // called when switching from alpha to // numeric layouts (and vice versa) or // when returning from Help/About. #define clear_kb // clear KB area to dark grey r 0 118 479 271 1 999 // enable 'Help' & 'About' m setup_help_about_keys // remove keys not used in alpha mode //:a bc 20 // remove keys not used in numeric " //:n bc 36 bc 37 #end //=============================================== //=============================================== // Enter gives us multi-line output, // and is also used to signal 'done' // to the host (hold down for ~1s). // Del & Space are 'permanent' keys. // Both are 'typematic', w/one beep. // These 3 keys are added after draw- // ing the alpha/numeric shift key on // Row 4 ('p0' is passed so '1'=p0.y) #define delete_space_enter // white on grey S FFFFFF D5D2D5 bdc 39 422 `(`1`-38)` 30 "Del" 4 4 // use this for a fancier 'del' key //bdc 39 422 `(`1`-38)` 30 "" 7 7 xmq 39 delete_key // Enter provides multi-line output // Hold for ~1s to signal last line //f 24 // match fancier fonts bdc 42 389 `1` 5 "Enter" 5 5 //f 24BC xmq 42 Enter_key_dn scroll_line_up // black on grey S 000000 D5D2D5 bdc 41 99 `1` 30 "space" 3 3 // use this for a fancier 'sp' key //bdc 41 99 `1` 30 "" 14 14 xaq 41 p keypress " " #end //=============================================== //=============================================== // macros for the 'Enter' key (scroll & exit) //=============================================== // Hold Enter down for ~1s to exit // from KBdemo after the last line // Releasing the key before the ~1s // wait is over performs the normal // scrolling function. #define Enter_key_dn w 1000 // disable Enter to avoid a scroll xe 42 // chime to say 'Last Line Entered' al 3 450 // tell Host that user is done - // Host then retrieves 'M' with // 'm get_M'. // out "KB done\r" m simulate_KBdone_action // Another choice here: put 'M' // in 's0' [set s0 "`M`"], then // send 'x42' instead of 'r42'. // The same host 'get line' rou- // tine can then be used to read // s0 (& add to previous lines). #end // 'm get_M' retrieves the last // line - almost like 'get s0', // which retrieves the scrolled // line (see comment above). #define get_M out "`M`\r" #end //'Enter' moves existing lines up, // either quickly or slowly (1/4s) // Called when Enter is released!! #define scroll_line_up touch off m remove_prompt // i0=0=fast, i0=1=slow m do_scroll:s`i0` // save old line in 's0' set s0 "`M`" // reset input string ('M') mpop -1 // display prompt m keypress "" // optional (to recover 's0') //out "r42\r" // 'r42' is conventional for key #42 // but you can do anything you like. // Host responds with 'get s0' to // recover the string. NB: internal // strings are limited to 80 chars, // but Host can piece them together. touch on #end // Demo offers 'fast'/'slow' choice. // Actual usage would not need this // option - just remove the one you // don't want & eliminate use of i0. // Note: scroll region and # pixels // will probably need to be changed // for actual use and other fonts.. #define do_scroll // f 16B is 26 pixels tall :s0 // scroll 26 pixels in one go k 0 42 479 114 26u :s1 // scroll one-pixel-at-a-time m scroll_up_4 m scroll_up_4 m scroll_up_4 m scroll_up_4 m scroll_up_4 m scroll_up_4 m scroll_up_2 #end // Note: 6x4 combo = 14 cmds // while 4x6 combo = 16 cmds // and 3x8 combo = 19 cmds // but 8x3 combo = 14 cmds #define scroll_up_2 // 10 msec/shift - change as desired k 0 42 479 114 1u w 10 k 0 42 479 114 1u w 10 #end #define scroll_up_4 // 10 msec/shift - change as desired k 0 42 479 114 1u w 10 k 0 42 479 114 1u w 10 k 0 42 479 114 1u w 10 k 0 42 479 114 1u w 10 #end //=============================================== //=============================================== // These macros draw the 'alpha' keyboard // This is the initial 'draw KB' macro, called // from 'outside', by the Alpha shift key, and // by 'Help/About' #define alpha_kb_lower touch off m clear_kb m lower_case_kb m finish_alpha 0 #end // only called by 'Help/About' #define alpha_kb_upper touch off m clear_kb m upper_case_kb m finish_alpha 1 #end #define finish_alpha m set_row:r30 // white chars on grey S FFFFFF D5D2D5 // arg defines up/dn shift state // 2`0` = 20 or 21 bdc 30 `p0` 2`0` "SHF" "shf" 4 4 // use this for a fancier 'shf' key //bdc 30 `p0` 2`0` "" "" 8 9 xmq 30 upper_case_kb lower_case_kb m set_row:r4 // show 'numeric' shift key bdc 40 `p0` 1 ".?123" 5 5 // use this for a fancier 'numeric' key //bdc 40 `p0` 1 "" 13 13 xmq 40 numeric_kb_numbers // black chars on grey S 000000 D5D2D5 // pass Row4 'y' value in '1' m delete_space_enter `p0` // use p0.x to identify KB (0|1) // only used by 'Help' / 'About' set p0 `0` 0 touch on #end //=============================================== //=============================================== // These macros draw the 'numeric' keyboard // called by Numeric Shift key & 'Help/About' #define numeric_kb_numbers touch off m clear_kb m numbers_kb m finish_numeric 0 #end // only called by 'Help/About' #define numeric_kb_symbols touch off m clear_kb m symbols_kb m finish_numeric 1 #end #define finish_numeric m set_row:r30 // white chars on grey S FFFFFF D5D2D5 // arg defines up/dn shift state // 2`0` = 20 or 21 bdc 30 `p0` 2`0` "$+=" "123" 4 4 // use this for fancier 'shf' keys //bdc 30 `p0` 2`0` "" "" 10 11 xmq 30 symbols_kb numbers_kb m set_row:r4 // show 'alpha' shift key bdc 40 `p0` 1 "ABC" 5 5 // use this for a fancier 'alpha' key //bdc 40 `p0` 1 "" 12 12 xmq 40 alpha_kb_lower // black chars on grey S 000000 D5D2D5 // pass Row4 'y' value in '1' m delete_space_enter `p0` // use p0.x to identify KB (2|3) // only used by 'Help' / 'About' set p0 `(`0`+2)` 1 touch on #end //=============================================== //=============================================== // default alpha KB #define lower_case_kb m set_row:r1 m drawkey `p0` 10 q m drawkey `p0` 11 w m drawkey `p0` 12 e m drawkey `p0` 13 r m drawkey `p0` 14 t m drawkey `p0` 15 y m drawkey `p0` 16 u m drawkey `p0` 17 i m drawkey `p0` 18 o m drawkey `p0` 19 p m set_row:r2a m drawkey `p0` 21 a m drawkey `p0` 22 s m drawkey `p0` 23 d m drawkey `p0` 24 f m drawkey `p0` 25 g m drawkey `p0` 26 h m drawkey `p0` 27 j m drawkey `p0` 28 k m drawkey `p0` 29 l m set_row:r3 m drawkey `p0` 31 z m drawkey `p0` 32 x m drawkey `p0` 33 c m drawkey `p0` 34 v m drawkey `p0` 35 b m drawkey `p0` 36 n m drawkey `p0` 37 m // p0 remembers the KB //(only for Help/About) set p0 0 0 #end //=============================================== //=============================================== // alternate alpha KB #define upper_case_kb m set_row:r1 m drawkey `p0` 10 Q m drawkey `p0` 11 W m drawkey `p0` 12 E m drawkey `p0` 13 R m drawkey `p0` 14 T m drawkey `p0` 15 Y m drawkey `p0` 16 U m drawkey `p0` 17 I m drawkey `p0` 18 O m drawkey `p0` 19 P m set_row:r2a m drawkey `p0` 21 A m drawkey `p0` 22 S m drawkey `p0` 23 D m drawkey `p0` 24 F m drawkey `p0` 25 G m drawkey `p0` 26 H m drawkey `p0` 27 J m drawkey `p0` 28 K m drawkey `p0` 29 L m set_row:r3 m drawkey `p0` 31 Z m drawkey `p0` 32 X m drawkey `p0` 33 C m drawkey `p0` 34 V m drawkey `p0` 35 B m drawkey `p0` 36 N m drawkey `p0` 37 M // p0 remembers the KB //(only for Help/About) set p0 1 0 #end //=============================================== //=============================================== // default numeric KB #define numbers_kb m set_row:r1 m drawkey `p0` 10 1 m drawkey `p0` 11 2 m drawkey `p0` 12 3 m drawkey `p0` 13 4 m drawkey `p0` 14 5 m drawkey `p0` 15 6 m drawkey `p0` 16 7 m drawkey `p0` 17 8 m drawkey `p0` 18 9 m drawkey `p0` 19 0 m set_row:r2n m drawkey `p0` 20 - // This is the '/' key, but the // current version of BMPload // fails if you don't quote it! m drawkey `p0` 21 "/" m drawkey `p0` 22 : m drawkey `p0` 23 ; m drawkey `p0` 24 ( m drawkey `p0` 25 ) m drawkey `p0` 26 & m drawkey `p0` 27 # m drawkey `p0` 28 % // This is the '°' (deg) key m drawkey `p0` 29 \xB0 // It replaces '"' (dbl-quote) // which can't be implemented // since it must be stored as // two chars (\"). m set_row:r3 m drawpnc `p0` 31 ' m drawpnc `p0` 32 ! m drawpnc `p0` 33 ? m drawpnc `p0` 34 , m drawpnc `p0` 35 . // p0 remembers the KB //(only for Help/About) set p0 2 1 #end //=============================================== //=============================================== // alternate numeric KB #define symbols_kb m set_row:r1 m drawkey `p0` 10 [ m drawkey `p0` 11 ] m drawkey `p0` 12 { m drawkey `p0` 13 } m drawkey `p0` 14 < m drawkey `p0` 15 > m drawkey `p0` 16 ^ m drawkey `p0` 17 * m drawkey `p0` 18 + m drawkey `p0` 19 = m set_row:r2n // This is the '¼' key m drawkey `p0` 20 \xBC // This is the '½' key m drawkey `p0` 21 \xBD // This is the 'µ' key m drawkey `p0` 22 \xB5 // This is a 'slashed zero' (Ø) //m drawkey `p0` 23 \xD8 // The vertical bar '|' replaces // backslash '\', which can't be // used with this implementation // 'cuz it must be stored as two // chars (\\). m drawkey `p0` 23 | m drawkey `p0` 24 @ m drawkey `p0` 25 $ //----------------------------- // The 'currency' keys //----------------------------- // This is the '¢' (cent) key // SLCD doesn't currently have // a '€' (euro) symbol (ouch!) //m drawkey `p0` 26 \xA2 // This is the '£' (pound) key //m drawkey `p0` 27 \xA3 // This is the '¥' (yen) key //m drawkey `p0` 28 \xA5 //----------------------------- // can be replaced by //----------------------------- // This is '÷' (divide) //m drawkey `p0` 26 \xF7 // This is 'power-of-two' (²) m drawkey `p0` 26 \xB2 // This is '×' (times) m drawkey `p0` 27 \xD7 // This is '±' (plus/minus) m drawkey `p0` 28 \xB1 //----------------------------- m drawkey `p0` 29 ~ m set_row:r3 // This is a 'centered dot' (·) m drawpnc `p0` 31 \xB7 // This is '¡' (inverted !) m drawpnc `p0` 32 \xA1 // This is '¿' (inverted ?) m drawpnc `p0` 33 \xBF // This is '«' (left angle-quote) m drawpnc `p0` 34 \xAB // This is '»' (right angle-quote) m drawpnc `p0` 35 \xBB // p0 remembers the KB //(only for Help/About) set p0 3 1 #end //=============================================== // End of iKB - additional for Help & About //=============================================== //=============================================== // 'Help' & 'About' routines (>extra<) //=============================================== // only called by initial setup #define draw_help_about_buttons // blue chars on grey (s 9 0) S 838183 D5D2D5 ef 32 16 29 14 ef 448 16 29 14 // white chars on blue (s 1 9) S FFFFFF 838183 f 12 t "Help" 16 7 t "About" 426 7 // black chars on grey S 000000 D5D2D5 f 16B m setup_help_about_keys #end // call after 'xc all' to restore the 'Help' & 'About' keys #define setup_help_about_keys xs 128 0 0 63 32 xmq 128 iKB_help xs 129 430 0 479 32 xmq 129 iKB_about // disable internal Help touch areas xc 130 xc 131 xc 132 xc 133 xc 134 #end #define clear_help_area r 0 118 479 271 1 999 xc all m setup_help_about_keys // set font, color & location of Help/About text f 12 S FFF 999 sc 3 121 #end #define iKB_about touch off m clear_help_area t "iKB was written by:" t "Ver 2.05s" 408 121 t "\xB9with some Good Ideas from Steve Peterson @Reach Technology." 3 253 f 16B ta CT t "Jim van Zee\xB9" 240 125 ta CT t "Lab Data Systems" 240 149 ta CT t "Seattle, WA 98105" 240 173 ta CT t "Jim.van.Zee@gmail.com" 240 197 ta CT t "-> iKB is in the Public Domain! <-" 240 226 // black chars on grey S 000000 D5D2D5 // restore alpha (p0=0,1) or numeric (p0=2,3) m select_kb_demo:n`p0` 129 // de-activate 'Help' and 'Demo' buttons xc 128 xc 132 touch on #end #define iKB_help touch off m clear_help_area t "iKB has two shift keys: the lower key selects alpha/numeric mode\n" t "('ABC' or '.?123'), while the top key selects upper/lower case in\n" t "alpha mode ('SHF|shf') and numbers/symbols ('123' or '#+=') in\n" t "numeric mode, for a total of four keyboard layouts.\n" sc 3 200 t "'Enter' shifts the current line up (three lines shown) using either\n" t "a SLOW or FAST scroll (try DEMO ). Press 'Enter' for ~1\n" t "sec to close iKB\nand return text." // Add sliders to adjust beep and backlight t "Beep -" 150 243 t "+" 275 243 sl 133 15 200 248 16 0 1 0 0 255 0 sv 133 `V` xmq 133 adj_beep t "Light -" 338 243 t "+" 465 243 sl 134 15 390 248 16 0 1 0 0 255 0 sv 134 `B` xmq 134 adj_backlight // draw boxes around SLOW | FAST and DEMO m select_speed_box:n`i0` r 213 218 265 235 f 16B // black chars on grey S 000000 D5D2D5 // restore alpha (p0=0,1) or numeric (p0=2,3) m select_kb_demo:n`p0` 128 // de-activate 'About' button xc 129 touch on #end // Action Macros for the two sliders #define adj_beep bvs `L133` #end #define adj_backlight xbbs `L134` #end // pick the correct KB for Help/About to re-draw // index is 'p0', thus '0' is p0.y and arg is '1' // arg selects either 'Help' or 'About' key #define select_kb_demo xs 132 213 218 265 235 :n0 xmq 132 alpha_demo xmq `1` alpha_kb_lower :n1 xmq 132 alpha_demo xmq `1` alpha_kb_upper :n2 xmq 132 number_demo xmq `1` numeric_kb_numbers :n3 xmq 132 number_demo xmq `1` numeric_kb_symbols #end // Touch areas in 'Help' select scroll speed #define select_speed_box // create SLOW/FAST hot zones xs 130 17 218 70 235 xmq 130 set_slow_fast:x130 xs 131 95 218 140 235 xmq 131 set_slow_fast:x131 // highlight the >current< SLOW/FAST option p 1 :n0 r 95 218 140 235 :n1 r 17 218 70 235 #end #define set_slow_fast // toggle SLOW/FAST switch & highlighted box S 999 999 :x130 set i0 1 // erase old box r 95 218 140 235 S FFF 999 // draw new box r 17 218 70 235 // black chars on grey S 000000 D5D2D5 :x131 set i0 0 // erase old box r 17 218 70 235 S FFF 999 // draw new box r 95 218 140 235 // black chars on grey S 000000 D5D2D5 #end #define alpha_demo mpop -1 mpush "The quick brown fox jumped over lazy dogs." m scroll_line_up mpush "Are you sure? I find that hard to believe!" m scroll_line_up mpush "Well, my friend Bob actually saw it happen." m keypress "" #end #define number_demo mpop -1 mpush "Here are examples of numbers and symbols:" m scroll_line_up mpush "y=a\xB7x\xB2+b\xB7x+c, \xBD(2\xD72)=2, Vcc=4.97\xB10.05V" m scroll_line_up mpush "\xBFNo es genial? \xAB1\xB5L=0.001mL\xBB T=`T`\xB0C" m keypress "" #end // Come here on exit from iKB (holding 'Enter' down for // 1s). For demo purposes we display the last two lines // ('s0','M'), and then let the user re-start iKB_demo. // In practice when the user is finished with iKB, the // host would pick up the last line & then re-draw the // screen appropriately for the application. #define simulate_KBdone_action xc all // small delay here 'feels' better w 400 S 000 EEE r 0 0 479 271 1 EEE f 16B sc 10 30 t "To close >iKB<, hold the 'Enter' key down\n" t "for ~1 sec. The last two lines typed were:" S 00F EEE sc 10 110 t "`s0`" sc 10 140 t "`M`" f 12 S 000 EEE ta CT t "[Press anywhere to restart iKB demo]" 240 250 xs 128 0 0 479 271 xmq 128 iKB_demo #end //===============================================