I’m porting some i2c code from adafruit (see my previous post), and I ran into a funky line that doesn’t translate well to squirrel.
writeRegister(CAP1188_MAIN, readRegister(CAP1188_MAIN) & ~CAP1188_MAIN_INT);
Note that the writeRegister function has the i2c device address hard coded (specified elsewhere), and takes the register and value to be written to that register as arguments, respectively. I think this line clears some sort of interrupt, but that’s a separate problem of figuring out what exactly this does and why.
So, I need to write the CAP1188_MAIN register value, that’s no problem.
i2c.write(i2c_addr, CAP1188_MAIN);
But when I have to write the value to go in the register, I have an issue. Here’s what I tried
`local val = i2c.read(i2c_addr, CAP1188_MAIN, 1);
local val2 = val & ~CAP1188_MAIN_INT;
i2c.write(i2c_addr, CAP1188_MAIN);
i2c.write(i2c_addr, val2);`
I get an error with this line
local val2 = val & ~CAP1188_MAIN_INT;
because I can’t do bitwise ops on strings, and i2c.read() returns strings.
So I guess that was a long winded way of asking if its possible to convert strings to a format that I can perform bitwise ops on. Or perhaps there’s a better way to do this in general.
Thanks!