Extended MaximInterface
Dependents: mbed_DS28EC20_GPIO
Diff: Devices/DS2431.cpp
- Revision:
- 7:471901a04573
- Parent:
- 6:a8c83a2e6fa4
--- a/Devices/DS2431.cpp Wed Jan 23 13:11:04 2019 -0600 +++ b/Devices/DS2431.cpp Mon Mar 04 08:10:00 2019 -0600 @@ -55,59 +55,59 @@ error_code DS2431::readMemory(Address beginAddress, span<uint_least8_t> data) const { - error_code owmResult = selectRom(*master); - if (owmResult) { - return owmResult; + error_code result = selectRom(*master); + if (result) { + return result; } const uint_least8_t sendBlock[] = {0xF0, beginAddress, 0x00}; - owmResult = master->writeBlock(sendBlock); - if (owmResult) { - return owmResult; + result = master->writeBlock(sendBlock); + if (result) { + return result; } - owmResult = master->readBlock(data); - return owmResult; + result = master->readBlock(data); + return result; } error_code DS2431::writeScratchpad(Address targetAddress, Scratchpad::const_span data) { - error_code owmResult = selectRom(*master); - if (owmResult) { - return owmResult; + error_code result = selectRom(*master); + if (result) { + return result; } uint_least8_t block[3 + Scratchpad::size] = {0x0F, targetAddress, 0x00}; std::copy(data.begin(), data.end(), block + 3); - owmResult = master->writeBlock(block); - if (owmResult) { - return owmResult; + result = master->writeBlock(block); + if (result) { + return result; } const uint_fast16_t calculatedCrc = calculateCrc16(block) ^ 0xFFFFU; - owmResult = master->readBlock(make_span(block, 2)); - if (owmResult) { - return owmResult; + result = master->readBlock(make_span(block, 2)); + if (result) { + return result; } if (calculatedCrc != ((static_cast<uint_fast16_t>(block[1]) << 8) | block[0])) { - owmResult = make_error_code(CrcError); + result = make_error_code(CrcError); } - return owmResult; + return result; } error_code DS2431::readScratchpad(Scratchpad::span data, uint_least8_t & esByte) { typedef array<uint_least8_t, 6 + Scratchpad::size> Block; - error_code owmResult = selectRom(*master); - if (owmResult) { - return owmResult; + error_code result = selectRom(*master); + if (result) { + return result; } Block block = {0xAA}; - owmResult = master->writeByte(block.front()); - if (owmResult) { - return owmResult; + result = master->writeByte(block.front()); + if (result) { + return result; } - owmResult = master->readBlock(make_span(block.data() + 1, block.size() - 1)); - if (owmResult) { - return owmResult; + result = master->readBlock(make_span(block).subspan(1)); + if (result) { + return result; } Block::const_iterator blockIt = block.end(); uint_fast16_t receivedCrc = static_cast<uint_fast16_t>(*(--blockIt)) << 8; @@ -120,38 +120,38 @@ std::copy(blockIt, blockItEnd, data.begin()); esByte = *(--blockIt); } else { - owmResult = make_error_code(CrcError); + result = make_error_code(CrcError); } - return owmResult; + return result; } error_code DS2431::copyScratchpad(Address targetAddress, uint_least8_t esByte) { - error_code owmResult = selectRom(*master); - if (owmResult) { - return owmResult; + error_code result = selectRom(*master); + if (result) { + return result; } uint_least8_t block[] = {0x55, targetAddress, 0x00}; - owmResult = master->writeBlock(block); - if (owmResult) { - return owmResult; + result = master->writeBlock(block); + if (result) { + return result; } - owmResult = master->writeByteSetLevel(esByte, OneWireMaster::StrongLevel); - if (owmResult) { - return owmResult; + result = master->writeByteSetLevel(esByte, OneWireMaster::StrongLevel); + if (result) { + return result; } sleep->invoke(10); - owmResult = master->setLevel(OneWireMaster::NormalLevel); - if (owmResult) { - return owmResult; + result = master->setLevel(OneWireMaster::NormalLevel); + if (result) { + return result; } - owmResult = master->readByte(block[0]); - if (owmResult) { - return owmResult; + result = master->readByte(block[0]); + if (result) { + return result; } if (block[0] != 0xAA) { - owmResult = make_error_code(OperationFailure); + result = make_error_code(OperationFailure); } - return owmResult; + return result; } const error_category & DS2431::errorCategory() { @@ -165,11 +165,9 @@ return "CRC Error"; case OperationFailure: - return "Operation Failure"; - - default: - return defaultErrorMessage(condition); + return "Operation Failure"; } + return defaultErrorMessage(condition); } } instance; return instance;