To use this file copy and paste this:
// #URL-lib "http://pin1.org/forthlib/flb/I2C/i2c-Terminal.fth" into BV Terminal 3
or here to download.
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// I2-Terminal
// This is intended to be loaded as a stand alone file so that it can
// be used for debugging and the like. It still needs more work
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// REQUIRES:
// #URL-Lib "http://pin1.org/forthlib/flb/General/soft1.flb"
// #URL-Lib "http://pin1.org/forthlib/flb/General/pinsel.flb" sid=101
// #URL-Lib "http://pin1.org/forthlib/flb/I2C/i2c.flb" sid=103
// #url-lib "http://pin1.org/forthlib/flb/General/strings.flb" sid=0
//
// #currentSID sid=245
// CONSTANTS:
integer device // global to hold current device address
integer i2debug // if set to 1 then text accompanies commands
Full Contents of File
integer  device   
integer  i2debug 
: Aproc
        1+  ?number 
        if
                =>  device
        else
                ."  Error  number  should  follow  address  thus  A&70  "
        then               
;
       
: Sproc
        dup  length  1  >
        if 
                1+  ?number  drop  =>  device 
        then
        device  S               
        i2debug  if  device  cr  ."  start  address  "  ph.  then
;       
     
: Pproc
        P             
        i2debug  if  cr  ."  Stop  "  then
;       
: RSproc
        device  1+  RS       
        i2debug  if  cr  ."  re-start  address  "  device  1+  ph.  then 
;       
: Rproc
        1+  ?number
        if
                dup  1  =
                if
                        drop
                        RL           
                        i2debug  if  cr  ."  Last  read  "  .  then
                else       
                        i2debug
                        if
                                1-  for  cr  ."  read  "  RN  .  next
                                cr  ."  Last  read  "  RL  .
                        else
                                1-  for  RN  next  RL
                        then               
                then       
        else
                ."  Error  -  syntax  RLn"  cr
        then
;                       
: <0>i2-parse
int:  count  adr
        begin
                bl  string  count  +  tab    >r   
                =>  adr                 
                r>  dup  1+  +>  count 
        while
                adr  ?number
                if
                        dup  SB           
                        i2debug  if  cr  ."  send  byte  "  .  else  drop  then
                else
                        adr  toupper  c@
                        case
                        [char]  A  of  adr  Aproc  endof
                        [char]  S  of  adr  Sproc  endof
                        [char]  P  of  Pproc  endof
                        [char]  R  of  RSproc  endof
                        [char]  G  of  adr  Rproc  endof
                        otherwise  ."  unrecognised  command"
                        endcase       
                then
        repeat               
;
: i2-t-help
    cr  ."  I2  Term  Usage  "
    cr  ."  Example  to  send  2  bytes  to  I2C" 
    cr  ."  with  address  of  &42"
    cr  ."  s&42  2  55  p"
    cr  ."  S[nn]  =  start  with  optional  address"
    cr  ."  nn  =  number  on  its  own  will  be  sent  to  i2c"
    cr  ."  Ann  =  change  the  current  address  to  nn"
    cr  ."  P  =  send  stop  condition"
    cr  ."  R  =  restart  condition  uses  address  +  1"
    cr  ."  Gnn  =  gets  number  of  bytes  form  i2c"
    cr
    cr  ."  Example  to  send  value  20  then" 
    cr  ."  read  5  bytes  to  current  address"
    cr  ."  s  20  r  g5  p"
    cr
;   
: <0>i2-term
        cr  ."  End  session  with  E  "
        i2-t-help
        i2-init
        1  =>  i2debug
        begin
                cr  ."  Current  address  set  to  "  device  ph.
                cr  ."  >"
                here  80  accept 
                0  <>
                if
                        here  c@  [char]  E  =  if  escape  then 
                        here  i2-parse 
                then                           
        again
;