Hi, I wonder if you can advise me on a thing. I've just started using I2c in my Bela program, following some generic online examples. The i2c port is read in an aux task, not in the main render loop. That all seems to work.
The trouble is, ever since I added the code in setup() that opens the i2c device, I find that the Bela IDE is unable to shut down my program. Now instead of just clicking stop, I have to ssh in to Bela and kill -9 in order to iterate code.
I don't know what the shutdown process entails ... probably some signal gets sent? And possibly the i2c thread isn't exiting because it's blocking on a read? Really I don't know how to debug this stuff any more ... unix used to be so simple. =) Any suggestions would be much appreciated. Should I do something in cleanup() ?
Here's how the device is opened:
int i2cfile;
#define I2C_DEV "/dev/i2c-1"
bool i2csetup(){
if ((i2cfile = open(I2C_DEV, O_RDWR)) < 0) {
perror("Failed to open the i2c bus");
return false;
}
int addr = 0b00001000; // The I2C address of the slave
if (ioctl(i2cfile, I2C_SLAVE, addr) < 0) {
printf("Failed to acquire bus access and/or talk to slave.\n");
return false;
}
return true;
}
And here's the task that waits for messages from the slave device:
void checki2c(void *) {
char buf[10];
if (unsigned int rc = read(i2cfile,buf,10) > 0) {
rt_printf("i2c midi\n");//DEBUG
for (int i = 0; rc > 0; rc--){
midiparser.parse(buf[i++]);
}
}
}