These are the extended Peek/Poke functions so far:-
-------------Listing---------------
// here create an extended peek/poke interface for blassic
// address = location to peek/poke
// value of command or poke
// returns 123 or
// here led includes
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <syslog.h>
//i2c
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/i2c.h>
int expeekpoke( char cmd, int address, char value)
{
static int i2c; // i2c file pointer
static int i2cPORT ; // i2c chip address
static int i2cADDRESS; // i2c memory ic address
static char i2cBUF[10]; // i2c driver command buffer
char RetVal; // value to be returned
switch (cmd)
{
case 0 :
if (address ==32)
{ //print version info
printf("\nPeek&Poke extensions V0.91\n");
printf("poke 0-21, 0 or 1 to set or reset gpio\n");
printf("peek (0-21) read gpio\n");
printf("peek or poke location 34 to set\n");
printf("i2c read or write device ADDRESS\n");
printf("example 2048bit eeprom at $50\n");
printf("poke 34,80 - set device ADDRESS\n");
printf("peek or poke address 256-511\n");
printf("to read or write i2cEEprom(0-255)\n");
printf("\n");
}
// write a value
if (address ==34)
{ // writing i2c PORT
i2cPORT = value ;
}
if (address ==35) // send 1 byte to i2c PORT
{
i2c = open("/dev/i2c/0",O_RDWR);
ioctl(i2c,I2C_SLAVE, i2cPORT);
i2cBUF[0] = value;
write(i2c,i2cBUF,1);
i2c=close(i2c);
}
if (address > 255)
{ // store 1 byte in i2ceeprom (2048bit)
i2c = open("/dev/i2c/0",O_RDWR);
//printf("i2cOpen\n");
i2cADDRESS = address - 256 ;
//printf("i2c-poke %d with %d\n",i2cAddress, value) ;
ioctl(i2c,I2C_SLAVE, i2cPORT); /* set the i2c chip address eeprom == 50*/
i2cBUF[0] = i2cADDRESS ;
i2cBUF[1] = value;
write(i2c,i2cBUF,2); /* send the byte */
i2c=close(i2c);
//printf("i2cClose\n");
}
// end of any writes
RetVal=0; break;
case 1 :
// Read a value
if (address ==34)
{ // read i2cPORT
RetVal=i2cPORT;
}
if (address ==35) // read 1 byte from port
{
i2c = open("/dev/i2c/0",O_RDWR);
ioctl(i2c,I2C_SLAVE, i2cPORT);
read(i2c,i2cBUF,1);
i2c = close(i2c);
RetVal = i2cBUF[0] ;
}
if (address > 255) {
i2cADDRESS = address - 256 ;
//printf("i2c-peek %d \n",addr) ;
i2c = open("/dev/i2c/0",O_RDWR); //printf("i2cOpen\n");
ioctl(i2c,I2C_SLAVE, i2cPORT); /* set the i2c-chip address eeprom == 50*/
i2cBUF[0] = i2cADDRESS ;
i2cBUF[1] = 0 ;// just to be sure
//i2cbuf[1] = value;
write(i2c,i2cBUF,1); /* send the byte */
read(i2c,i2cBUF,1) ; /* get the byte */
i2c = close(i2c); //printf("i2cClose\n");
RetVal = i2cBUF[0] ;
}
break; // end of any reads
default: RetVal=123;
}
return RetVal;
}
-------------- Here the modified peek instruction (runnerline_impl.cpp)
void RunnerLineImpl::val_PEEK (BlResult & result)
{
//getparenarg (result);
gettoken ();
//valparen (result);
valbase (result);
// BlChar * addr= (BlChar *) size_t (result.number () );
//result= BlNumber (size_t (* addr) );
// extend peek function
// result= BlInteger (size_t (* addr) );
int address = size_t(result.number());
result = expeekpoke( 1, address, 0) ; // 1 = read
}
------------- Here the Modified Poke Instruction (runnerline_instructions.cpp -----------
bool RunnerLineImpl::do_POKE ()
{
BlNumber bnAddr= expectnum ();
requiretoken (',');
//BlChar * addr= (BlChar *) (unsigned int) bnAddr;
BlChar * addr= (BlChar *) (size_t) bnAddr;
BlNumber bnValue= expectnum ();
require_endsentence ();
BlChar value= (BlChar) (unsigned int) bnValue;
// * addr= value;
// here, call our extended peek/poke function
expeekpoke( 0, bnAddr, value) ; // 0 = write
return false;
}
----------End--------------------