Extended MaximInterface
Dependents: mbed_DS28EC20_GPIO
Diff: Devices/DS1920.cpp
- Revision:
- 6:a8c83a2e6fa4
- Parent:
- 0:f77ad7f72d04
--- a/Devices/DS1920.cpp Fri Jan 19 10:25:02 2018 -0600 +++ b/Devices/DS1920.cpp Wed Jan 23 13:11:04 2019 -0600 @@ -36,35 +36,25 @@ namespace MaximInterface { -enum DS1920_CMDS { - WRITE_SCRATCHPAD = 0x4E, - READ_SCRATCHPAD = 0xBE, - COPY_SCRATCHPAD = 0x48, - CONV_TEMPERATURE = 0x44, - RECALL = 0xB8 -}; - -error_code DS1920::writeScratchpad(uint_least8_t th, uint_least8_t tl) { +error_code DS1920::writeScratchpad(uint_least8_t th, uint_least8_t tl) { error_code result = selectRom(*master); if (!result) { - const uint_least8_t sendBlock[] = {WRITE_SCRATCHPAD, th, tl}; - result = - master->writeBlock(sendBlock, sizeof(sendBlock) / sizeof(sendBlock[0])); + const uint_least8_t sendBlock[] = {0x4E, th, tl}; + result = master->writeBlock(sendBlock); } return result; } -error_code DS1920::readScratchpad(Scratchpad & scratchpad) { +error_code DS1920::readScratchpad(Scratchpad::span scratchpad) { error_code result = selectRom(*master); if (!result) { - result = master->writeByte(READ_SCRATCHPAD); + result = master->writeByte(0xBE); if (!result) { - result = master->readBlock(scratchpad.data(), scratchpad.size()); + result = master->readBlock(scratchpad); if (!result) { uint_least8_t receivedCrc; result = master->readByte(receivedCrc); - if (!result && (receivedCrc != - calculateCrc8(scratchpad.data(), scratchpad.size()))) { + if (!result && (receivedCrc != calculateCrc8(scratchpad))) { result = make_error_code(CrcError); } } @@ -73,36 +63,34 @@ return result; } -error_code DS1920::copyScratchpad() { +error_code DS1920::copyScratchpad() { error_code result = selectRom(*master); if (!result) { - result = - master->writeByteSetLevel(COPY_SCRATCHPAD, OneWireMaster::StrongLevel); + result = master->writeByteSetLevel(0x48, OneWireMaster::StrongLevel); if (!result) { - (*sleep)(10); + sleep->invoke(10); result = master->setLevel(OneWireMaster::NormalLevel); } } return result; } -error_code DS1920::convertTemperature() { +error_code DS1920::convertTemperature() { error_code result = selectRom(*master); if (!result) { - result = - master->writeByteSetLevel(CONV_TEMPERATURE, OneWireMaster::StrongLevel); + result = master->writeByteSetLevel(0x44, OneWireMaster::StrongLevel); if (!result) { - (*sleep)(750); + sleep->invoke(750); result = master->setLevel(OneWireMaster::NormalLevel); } } return result; } -error_code DS1920::recallEeprom() { +error_code DS1920::recallEeprom() { error_code result = selectRom(*master); if (!result) { - result = master->writeByte(RECALL); + result = master->writeByte(0xB8); } return result; } @@ -133,7 +121,7 @@ if (result) { return result; } - DS1920::Scratchpad scratchpad; + DS1920::Scratchpad::array scratchpad; result = ds1920.readScratchpad(scratchpad); if (result) { return result;