Skip to content

Commit

Permalink
Updated changeI2Caddress_Callback() to add progam/switch_only flag
Browse files Browse the repository at this point in the history
  • Loading branch information
neuralaxy committed Apr 28, 2021
1 parent ce6864d commit 2fa3361
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions Software/NeuroStimDuino/NeuroStimDuino.cpp
Expand Up @@ -268,14 +268,35 @@ void changeI2Caddress_Callback(SerialCommands* sender)
{
sender->GetSerial()->println("ERROR! ADDR outside range ");
return;
}
i2c_error = I2Cwrite(ThreeBytesCommds, ADDR, -1, val);
if (i2c_error != 0){
sender->GetSerial()->print("I2C error = ");
sender->GetSerial()->println(i2c_error);
}else{
NSDuino_address = val; // Update I2C address of current slave that will be communicated with
}
val_str = sender->Next();
if (val_str == NULL)
{
sender->GetSerial()->println("ERROR! ADDR program flag 0/1 is missing ");
return;
}
int program_addr = atoi(val_str);
if (program_addr != 0 && program_addr != 1)
{
sender->GetSerial()->println("ERROR! ADDR program flag outside range ");
return;
}
if (program_addr == 1){
i2c_error = I2Cwrite(ThreeBytesCommds, ADDR, -1, val);
if (i2c_error != 0){
sender->GetSerial()->print("I2C error = ");
sender->GetSerial()->println(i2c_error);
}else{
NSDuino_address = val; // Update I2C address of current slave that will be communicated with
sender->GetSerial()->print("Current I2C slave address = ");
sender->GetSerial()->println(NSDuino_address, DEC);
}
}else{
//Only change I2C address of current slave device. Do not program the I2C address
NSDuino_address = val;
sender->GetSerial()->print("Current I2C slave address = ");
sender->GetSerial()->println(NSDuino_address, DEC);
}
}

void resetNeuroStimDuino_Callback(SerialCommands* sender)
Expand Down

0 comments on commit 2fa3361

Please sign in to comment.