OneWire Library lets you access 1-wire devices made by Maxim/Dallas, such as temperature sensors
Dependents: OneWireTest mbed_blinky Affich_Lum_Moist Projetv0 ... more
#include "mbed.h" #include "OneWire.h" OneWire owBus(p21); int main() { char _id[16]; DeviceAddresses* devAddresses = owBus.getFoundDevAddresses(); uint8_t foundNum = owBus.getFoundDevNum(); printf("OneWire: found %d devices\r\n", foundNum); while(1) { OneWireDeviceTemperature::startConversationForAll(&owBus, OWTEMP_11_BIT); for (uint8_t i = 0; i < foundNum; i++) { OneWireDevice* owDevice = OneWireDeviceFactory::init(&owBus, (*devAddresses)[i]); if (owDevice->getFamily() != ONEWIRE_DS18B20_FAMILY) // currently only DS18B20 supports continue; owDevice->generateId(_id); printf("OneWire: device #%s = %.4f*C\r\n", _id, (float) owDevice->sendGetCommand(GET_TEMPERATURE)); delete owDevice; } wait(5); } }
Diff: OneWire.h
- Revision:
- 2:07da4deb7135
- Parent:
- 0:b9cd1d4dcc1f
--- a/OneWire.h Mon Dec 17 13:34:57 2012 +0000 +++ b/OneWire.h Tue Dec 18 11:40:28 2012 +0000 @@ -50,35 +50,6 @@ void findDevAddresses(void); }; -class OneWireDevice { -public: - OneWireDevice(OneWire* ow, DeviceAddress devAddr); - //~OneWireDevice(); - void generateId(char* id); - uint8_t getFamily(); - - virtual void sendSetCommand(OneWireDeviceCmd cmd, uint8_t data) {}; - virtual float sendGetCommand(OneWireDeviceCmd cmd) { - return 0; - }; +#include "OneWireDevice.h" -protected: - OneWire* owBus; - DeviceAddress address; -}; - -class OneWireDeviceTemperature : public OneWireDevice { -public: - OneWireDeviceTemperature(OneWire* ow, DeviceAddress address) : OneWireDevice(ow, address) {}; - //static setResolutionForAll - static void startConversationForAll(OneWire* owBus, uint8_t resolution); -}; - - -class OneWireDeviceFactory { -public: - static OneWireDevice* init(OneWire* owBus, DeviceAddress address); -}; - -#include "devices/ds18b20.h" #endif \ No newline at end of file