|
|
@ -473,7 +473,7 @@ void I2CPositionEncoder::calibrate_steps_mm(const uint8_t iter) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void I2CPositionEncoder::reset() {
|
|
|
|
void I2CPositionEncoder::reset() {
|
|
|
|
Wire.beginTransmission(i2cAddress);
|
|
|
|
Wire.beginTransmission(I2C_ADDRESS(i2cAddress));
|
|
|
|
Wire.write(I2CPE_RESET_COUNT);
|
|
|
|
Wire.write(I2CPE_RESET_COUNT);
|
|
|
|
Wire.endTransmission();
|
|
|
|
Wire.endTransmission();
|
|
|
|
|
|
|
|
|
|
|
@ -703,7 +703,7 @@ void I2CPositionEncodersMgr::report_position(const int8_t idx, const bool units,
|
|
|
|
|
|
|
|
|
|
|
|
void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const uint8_t newaddr) {
|
|
|
|
void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const uint8_t newaddr) {
|
|
|
|
// First check 'new' address is not in use
|
|
|
|
// First check 'new' address is not in use
|
|
|
|
Wire.beginTransmission(newaddr);
|
|
|
|
Wire.beginTransmission(I2C_ADDRESS(newaddr));
|
|
|
|
if (!Wire.endTransmission()) {
|
|
|
|
if (!Wire.endTransmission()) {
|
|
|
|
SERIAL_ECHOPAIR("?There is already a device with that address on the I2C bus! (", newaddr);
|
|
|
|
SERIAL_ECHOPAIR("?There is already a device with that address on the I2C bus! (", newaddr);
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
@ -711,7 +711,7 @@ void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Now check that we can find the module on the oldaddr address
|
|
|
|
// Now check that we can find the module on the oldaddr address
|
|
|
|
Wire.beginTransmission(oldaddr);
|
|
|
|
Wire.beginTransmission(I2C_ADDRESS(oldaddr));
|
|
|
|
if (Wire.endTransmission()) {
|
|
|
|
if (Wire.endTransmission()) {
|
|
|
|
SERIAL_ECHOPAIR("?No module detected at this address! (", oldaddr);
|
|
|
|
SERIAL_ECHOPAIR("?No module detected at this address! (", oldaddr);
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
@ -722,7 +722,7 @@ void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const
|
|
|
|
SERIAL_ECHOLNPAIR(", changing address to ", newaddr);
|
|
|
|
SERIAL_ECHOLNPAIR(", changing address to ", newaddr);
|
|
|
|
|
|
|
|
|
|
|
|
// Change the modules address
|
|
|
|
// Change the modules address
|
|
|
|
Wire.beginTransmission(oldaddr);
|
|
|
|
Wire.beginTransmission(I2C_ADDRESS(oldaddr));
|
|
|
|
Wire.write(I2CPE_SET_ADDR);
|
|
|
|
Wire.write(I2CPE_SET_ADDR);
|
|
|
|
Wire.write(newaddr);
|
|
|
|
Wire.write(newaddr);
|
|
|
|
Wire.endTransmission();
|
|
|
|
Wire.endTransmission();
|
|
|
@ -733,7 +733,7 @@ void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const
|
|
|
|
safe_delay(I2CPE_REBOOT_TIME);
|
|
|
|
safe_delay(I2CPE_REBOOT_TIME);
|
|
|
|
|
|
|
|
|
|
|
|
// Look for the module at the new address.
|
|
|
|
// Look for the module at the new address.
|
|
|
|
Wire.beginTransmission(newaddr);
|
|
|
|
Wire.beginTransmission(I2C_ADDRESS(newaddr));
|
|
|
|
if (Wire.endTransmission()) {
|
|
|
|
if (Wire.endTransmission()) {
|
|
|
|
SERIAL_ECHOLNPGM("Address change failed! Check encoder module.");
|
|
|
|
SERIAL_ECHOLNPGM("Address change failed! Check encoder module.");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -753,7 +753,7 @@ void I2CPositionEncodersMgr::change_module_address(const uint8_t oldaddr, const
|
|
|
|
|
|
|
|
|
|
|
|
void I2CPositionEncodersMgr::report_module_firmware(const uint8_t address) {
|
|
|
|
void I2CPositionEncodersMgr::report_module_firmware(const uint8_t address) {
|
|
|
|
// First check there is a module
|
|
|
|
// First check there is a module
|
|
|
|
Wire.beginTransmission(address);
|
|
|
|
Wire.beginTransmission(I2C_ADDRESS(address));
|
|
|
|
if (Wire.endTransmission()) {
|
|
|
|
if (Wire.endTransmission()) {
|
|
|
|
SERIAL_ECHOPAIR("?No module detected at this address! (", address);
|
|
|
|
SERIAL_ECHOPAIR("?No module detected at this address! (", address);
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
@ -763,7 +763,7 @@ void I2CPositionEncodersMgr::report_module_firmware(const uint8_t address) {
|
|
|
|
SERIAL_ECHOPAIR("Requesting version info from module at address ", address);
|
|
|
|
SERIAL_ECHOPAIR("Requesting version info from module at address ", address);
|
|
|
|
SERIAL_ECHOLNPGM(":");
|
|
|
|
SERIAL_ECHOLNPGM(":");
|
|
|
|
|
|
|
|
|
|
|
|
Wire.beginTransmission(address);
|
|
|
|
Wire.beginTransmission(I2C_ADDRESS(address));
|
|
|
|
Wire.write(I2CPE_SET_REPORT_MODE);
|
|
|
|
Wire.write(I2CPE_SET_REPORT_MODE);
|
|
|
|
Wire.write(I2CPE_REPORT_VERSION);
|
|
|
|
Wire.write(I2CPE_REPORT_VERSION);
|
|
|
|
Wire.endTransmission();
|
|
|
|
Wire.endTransmission();
|
|
|
@ -777,7 +777,7 @@ void I2CPositionEncodersMgr::report_module_firmware(const uint8_t address) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set module back to normal (distance) mode
|
|
|
|
// Set module back to normal (distance) mode
|
|
|
|
Wire.beginTransmission(address);
|
|
|
|
Wire.beginTransmission(I2C_ADDRESS(address));
|
|
|
|
Wire.write(I2CPE_SET_REPORT_MODE);
|
|
|
|
Wire.write(I2CPE_SET_REPORT_MODE);
|
|
|
|
Wire.write(I2CPE_REPORT_DISTANCE);
|
|
|
|
Wire.write(I2CPE_REPORT_DISTANCE);
|
|
|
|
Wire.endTransmission();
|
|
|
|
Wire.endTransmission();
|
|
|
|