// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // BV4505 - IASI Keypad Default address 'b' // This will load as a stand alone file or can be used as a library // providing the parent file includes the files in the REQUIRES // section // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // REQUIRES: // #URL-lib "http://pin1.org/forthlib/flb/General/soft1.flb" sid=0 // #URL-lib "http://pin1.org/forthlib/flb/General/pinsel.flb" sid=101 // #URL-lib "http://pin1.org/forthlib/flb/General/strings.flb" // #URL-lib "http://pin1.org/forthlib/flb/IASI2/IASI2-b.flb" // HISTORY: // Nov 2008 *Preliminary // CONSTANTS: integer i-keypad-adr // set this before using // --------------------------------------------------------------- // changes address of keypad : i-key-adr ( adr -- ) => i-keypad-adr ; // --------------------------------------------------------------- // Initialise device to an address, reports back number of devices // connected : i-init-key ( adr -- x ) i-key-adr i-connect ; // --------------------------------------------------------------- // reports number of keys in buffer : i-key? ( -- num ) i-cbuff // clear buffer i-keypad-adr emit1 [char] b emit1 cr1 i-send i-gn 0= if ." device error" abort then ; // --------------------------------------------------------------- // gets value of key // note blocks here until key pressed : i-key ( -- val ) begin i-key? until i-keypad-adr emit1 [char] g emit1 cr1 i-send i-gn drop ; // --------------------------------------------------------------- // returns 1 if key down otherwise returns 0 : i-keydown? ( -- 0|1) i-keypad-adr emit1 [char] d emit1 cr1 i-send i-buffer c@ 48 - ; // --------------------------------------------------------------- // returns -1 if no key down but returns the key value if key // down : i-keydownk? ( -- keyval|-1 ) i-keydown? if i-key else -1 then ; // --------------------------------------------------------------- // clears key buffer : i-keyclear i-keypad-adr emit1 [char] c emit1 cr1 i-send ;