Browse Source

i2c: ...and show addresses in hex

pull/2516/head
Maxim Prokhorov 2 years ago
parent
commit
b080dd9ea6
2 changed files with 10 additions and 3 deletions
  1. +5
    -3
      code/espurna/i2c.cpp
  2. +5
    -0
      code/espurna/utils.h

+ 5
- 3
code/espurna/i2c.cpp View File

@ -126,11 +126,13 @@ void bootScan() {
addresses += F(", ");
}
addresses += String(address, 10);
addresses += F("0x");
addresses += hexEncode(address);
});
if (addresses.length()) {
DEBUG_MSG_P(PSTR("[I2C] Found addresses: %s\n"), addresses.c_str());
DEBUG_MSG_P(PSTR("[I2C] Found device(s): %s\n"), addresses.c_str());
} else {
DEBUG_MSG_P(PSTR("[I2C] No devices found\n"));
}
@ -494,7 +496,7 @@ bool i2cGetLock(unsigned char address) {
unsigned char mask = 1 << (address % 8);
if (!(i2c::internal::locked[index] & mask)) {
i2c::internal::locked[index] = i2c::internal::locked[index] | mask;
DEBUG_MSG_P(PSTR("[I2C] Address 0x%02X locked\n"), address);
DEBUG_MSG_P(PSTR("[I2C] 0x%02X locked\n"), address);
return true;
}
return false;


+ 5
- 0
code/espurna/utils.h View File

@ -62,6 +62,11 @@ inline String hexEncode(const uint8_t (&buffer)[Size]) {
return hexEncode(std::begin(buffer), std::end(buffer));
}
inline String hexEncode(uint8_t value) {
uint8_t buffer[1] { value };
return hexEncode(buffer);
}
uint8_t* hexDecode(const char* in_begin, const char* in_end, uint8_t* out_begin, uint8_t* out_end);
size_t hexDecode(const char* in, size_t in_size, uint8_t* out, size_t out_size);


Loading…
Cancel
Save