Demo program for MAXREFDES132. Searches 1-Wire® bus and prints ROM IDs of devices found. If the DS1920 is found presents user with menu for interfacing with the DS1920 temperature iButton
Dependencies: OneWire Terminal mbed
Diff: main.cpp
- Revision:
- 10:a43e5b99d61f
- Parent:
- 8:7af592c694b2
- Child:
- 11:11a01dc7a2c9
--- a/main.cpp Fri Dec 02 19:35:29 2016 +0000 +++ b/main.cpp Mon Jul 10 17:39:49 2017 +0000 @@ -45,7 +45,11 @@ { Terminal term(USBTX, USBRX); char user_entry = 'y'; - + char cmnd_entry = ' '; + RomId myROM; + array<uint8_t, 8> myArray; + bool DS1920active = false; + I2C i2cBus(D14, D15); i2cBus.frequency(400000); DS2484 owm(i2cBus); @@ -68,35 +72,71 @@ { result = owm.OWReset(); if(result == OneWireMaster::Success) - { - term.printf("\nOWReset success, starting search\n"); + { + term.printf("\nOWReset successn"); + cmnd_entry = term.get_char("\nEnter 'a' to perform a Search ROM command\nEnter 'b' to find a specific device: ", 'a', 'b'); + term.cls(); + term.home(); + + switch(cmnd_entry) + { + case 'a': - result = OWFirst(owm, searchState); - if(result == OneWireMaster::Success) - { - do - { - //print current devices rom id - print_rom_id(term, searchState.romId); - + result = OWFirst(owm, searchState); + if(result == OneWireMaster::Success) + { + do + { + //print current devices rom id + print_rom_id(term, searchState.romId); - //This could be a switch statement based on familyCodes - //if your app has more than one device on the bus - if(searchState.romId.familyCode() == 0x10) + //This could be a switch statement based on familyCodes + //if your app has more than one device on the bus + if(searchState.romId.familyCode() == 0x10) + { + DS1920active = true; + //DS1920Menu(term, searchState.romId, selector); + } + + //find the next device if any + result = OWNext(owm, searchState); + } + while(result == OneWireMaster::Success); + if (DS1920active == true){ + DS1920Menu(term, searchState.romId, selector); + } + DS1920active = false; + } + else { - DS1920Menu(term, searchState.romId, selector); + term.printf("\nSearch failed\n"); + term.printf("\nError code = %d\n", result); } - - //find the next device if any - result = OWNext(owm, searchState); + break; + + case 'b': + term.printf("\nPlease enter the ROMID you would like to search for starting with the MSB\n"); + + for (int i = 7; i > -1; i--){ + term.printf("\nEnter the %d byte: ",i); + term.scanf("%x", &myArray[i]); + myROM[i] = myArray[i]; + term.printf("%#x", myROM[i]); + } + + //print_rom_id(term, myROM); + + result = OWVerify(owm, myROM); + if(result == OneWireMaster::Success) + { + term.printf("\n\nYAY!"); + } + else + { + term.printf("\n\nBOO!\n"); + } + break; } - while(result == OneWireMaster::Success); - } - else - { - term.printf("\nSearch failed\n"); - term.printf("\nError code = %d\n", result); - } } else { @@ -126,6 +166,8 @@ void print_rom_id(Terminal & term, const RomId & romId) { //print the rom number + //term.printf("\n"); + //term.printf("%x ", romId.familyCode()); term.printf("\n"); int8_t idx = (RomId::byteLen - 1); do