Simple demo for exercising the board
Dependencies: MAX11300 MAX4822 OneWire Terminal ds3231 mbed
Diff: main.cpp
- Revision:
- 5:2fe6dd435618
- Parent:
- 4:2a25a4e00541
- Child:
- 6:18a831a757b5
--- a/main.cpp Sun Jul 31 22:00:57 2016 +0000 +++ b/main.cpp Wed Aug 03 23:00:23 2016 +0000 @@ -47,6 +47,7 @@ void calibrate_420_io(Terminal & term, MAX11300 & pixi, float & slope_out, float & offset_out, float & slope_in, float & offset_in); +void DS1920Menu(Terminal & term, const RomId & romId, MultidropRomIterator & selector); int main(void) { @@ -203,6 +204,8 @@ avo_volts = term.get_float("Please enter a voltage from 0.0 to 10.0 volts: ", -0.1, 10.1); analog_val = static_cast<uint16_t>((avo_volts/10.0) * 4095); + term.printf("DAC Code = %d\n", analog_val); + pixi_result = pixi.single_ended_dac_write(static_cast<MAX11300::MAX11300_Ports>(analog_out_ch), analog_val); if(pixi_result != MAX11300::Success) { @@ -318,6 +321,7 @@ void search_ow_bus(Terminal & term, DS2484 & owm) { OneWireMaster::CmdResult result = owm.OWReset(); + MultidropRomIterator selector(owm); SearchState search_state; if(result == OneWireMaster::Success) @@ -332,6 +336,11 @@ //print current devices rom id print_rom_id(term, search_state.romId); + if(search_state.romId.familyCode() == 0x10) + { + DS1920Menu(term, search_state.romId, selector); + } + //find the next device if any result = OWNext(owm, search_state); } @@ -468,3 +477,132 @@ wait(1.0); } +//********************************************************************* +void DS1920Menu(Terminal & term, const RomId & romId, MultidropRomIterator & selector) +{ + char userEntry = '0'; + uint8_t th, tl, idx; + uint8_t scratchPadBuff[8]; + float temperature; + + DS1920 tempIbutton(selector); + DS1920::CmdResult result = DS1920::OpFailure; + tempIbutton.setRomId(romId); + + while(userEntry != '7') + { + term.printf("\nDS1920 Menu Options\n"); + term.printf("\n%t1. Write ScratchPad"); + term.printf("\n%t2. Read Scratchpad"); + term.printf("\n%t3. Copy Scratchpad"); + term.printf("\n%t4. Convert Temperature"); + term.printf("\n%t5. Recall EEPROM"); + term.printf("\n%t6. Clear Screen"); + term.printf("\n%t7. Quit"); + + userEntry = term.get_char("\nPlease select an option above: ", '1', '7'); + + switch(userEntry) + { + case '1': + th = term.get_int32("\nPlease enter upper temperature threshold, integer values only: ", 0, 100); + tl = term.get_int32("\nPlease enter lower temperature threshold, integer values only: ", -55, 0); + + result = tempIbutton.writeScratchPad(th, tl); + if(result == DS1920::Success) + { + term.printf("\nWrite Scratchpad Success\n"); + } + else + { + term.printf("\nWrite Scratchpad Fail\n"); + } + + break; + + case '2': + + result = tempIbutton.readScratchPad(scratchPadBuff); + if(result == DS1920::Success) + { + term.printf("\nRead Scratchpad Success\n"); + term.printf("\nScratchpad = "); + for(idx = 0; idx < 8; idx++) + { + if(scratchPadBuff[idx] < 16) + { + term.printf("0x0%x ", scratchPadBuff[idx]); + } + else + { + term.printf("0x%2x ", scratchPadBuff[idx]); + } + } + term.printf("\n"); + + } + else + { + term.printf("\nRead Scratchpad Fail\n"); + } + + break; + + case '3': + + result = tempIbutton.copyScratchPad(); + if(result == DS1920::Success) + { + term.printf("\nCopy Scratchpad Success\n"); + } + else + { + term.printf("\nCopy Scratchpad Fail\n"); + } + + break; + + case '4': + + result = tempIbutton.convertTemperature(temperature); + if(result == DS1920::Success) + { + term.printf("\nConvert Temperature Success\n"); + term.printf("\nTemperature = %.1f", temperature); + } + else + { + term.printf("\nConvert Temperature Fail\n"); + } + + break; + + case '5': + + result = tempIbutton.recallEEPROM(); + if(result == DS1920::Success) + { + term.printf("\nRecall EEPROM Success\n"); + } + else + { + term.printf("\nRecall EEPROM Fail\n"); + } + + break; + + case '6': + term.cls(); + term.home(); + break; + + case '7': + term.printf("\nLeaving DS1920 Menu Options\n"); + break; + + default: + mbed_die(); + break; + } + } +}