teste de publish

Dependencies:   LinkedList

Fork of DS1820 by Erik -

Committer:
brunofgc
Date:
Thu Jun 07 16:19:27 2018 +0000
Revision:
14:01fb493e5d2f
Parent:
11:1a3c3002b50c
Corrigido os delays para osDelay (a fim de liberar para outras threads)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Michael_ 2:ee820a991b95 1 /* mbed DS1820 Library, for the Dallas (Maxim) 1-Wire Digital Thermometer
Michael_ 2:ee820a991b95 2 * Copyright (c) 2010, Michael Hagberg Michael@RedBoxCode.com
Michael_ 2:ee820a991b95 3 *
Michael_ 2:ee820a991b95 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
Michael_ 2:ee820a991b95 5 * of this software and associated documentation files (the "Software"), to deal
Michael_ 2:ee820a991b95 6 * in the Software without restriction, including without limitation the rights
Michael_ 2:ee820a991b95 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Michael_ 2:ee820a991b95 8 * copies of the Software, and to permit persons to whom the Software is
Michael_ 2:ee820a991b95 9 * furnished to do so, subject to the following conditions:
Michael_ 2:ee820a991b95 10 *
Michael_ 2:ee820a991b95 11 * The above copyright notice and this permission notice shall be included in
Michael_ 2:ee820a991b95 12 * all copies or substantial portions of the Software.
Michael_ 2:ee820a991b95 13 *
Michael_ 2:ee820a991b95 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Michael_ 2:ee820a991b95 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Michael_ 2:ee820a991b95 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Michael_ 2:ee820a991b95 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Michael_ 2:ee820a991b95 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Michael_ 2:ee820a991b95 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Michael_ 2:ee820a991b95 20 * THE SOFTWARE.
Michael_ 2:ee820a991b95 21 */
Michael_ 2:ee820a991b95 22
Michael_ 2:ee820a991b95 23 #ifndef MBED_DS1820_H
Michael_ 2:ee820a991b95 24 #define MBED_DS1820_H
Michael_ 2:ee820a991b95 25
Michael_ 2:ee820a991b95 26 #include "mbed.h"
Sissors 5:2cd4928e8147 27 #include "LinkedList.h"
brunofgc 14:01fb493e5d2f 28 #include "cmsis_os.h" //Nucleo do Real Time Operational System
Michael_ 2:ee820a991b95 29
Sissors 5:2cd4928e8147 30 #define FAMILY_CODE _ROM[0]
Sissors 5:2cd4928e8147 31 #define FAMILY_CODE_DS1820 0x10
Sissors 5:2cd4928e8147 32 #define FAMILY_CODE_DS18B20 0x28
Sissors 5:2cd4928e8147 33 #define FAMILY_CODE_DS1822 0x22
Michael_ 2:ee820a991b95 34
Michael_ 2:ee820a991b95 35 /** DS1820 Dallas 1-Wire Temperature Probe
Michael_ 2:ee820a991b95 36 *
Michael_ 2:ee820a991b95 37 * Example:
Michael_ 2:ee820a991b95 38 * @code
Michael_ 2:ee820a991b95 39 * #include "mbed.h"
Michael_ 2:ee820a991b95 40 * #include "DS1820.h"
Michael_ 2:ee820a991b95 41 *
Sissors 5:2cd4928e8147 42 * DS1820 probe(DATA_PIN);
Sissors 5:2cd4928e8147 43 *
Michael_ 2:ee820a991b95 44 * int main() {
Sissors 5:2cd4928e8147 45 * while(1) {
Sissors 5:2cd4928e8147 46 * probe.convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready
Sissors 5:2cd4928e8147 47 * printf("It is %3.1foC\r\n", probe.temperature());
Sissors 5:2cd4928e8147 48 * wait(1);
Michael_ 2:ee820a991b95 49 * }
Michael_ 2:ee820a991b95 50 * }
Michael_ 2:ee820a991b95 51 * @endcode
Michael_ 2:ee820a991b95 52 */
Michael_ 2:ee820a991b95 53 class DS1820 {
Michael_ 2:ee820a991b95 54 public:
Michael_ 2:ee820a991b95 55 enum devices{
Michael_ 2:ee820a991b95 56 this_device, // command applies to only this device
Michael_ 2:ee820a991b95 57 all_devices }; // command applies to all devices
Sissors 7:58b61681818f 58
Sissors 7:58b61681818f 59 enum {
Sissors 7:58b61681818f 60 invalid_conversion = -1000
Sissors 7:58b61681818f 61 };
Michael_ 2:ee820a991b95 62
Michael_ 2:ee820a991b95 63 /** Create a probe object connected to the specified pins
Sissors 5:2cd4928e8147 64 *
Sissors 5:2cd4928e8147 65 * The probe might either by regular powered or parasite powered. If it is parasite
Sissors 5:2cd4928e8147 66 * powered and power_pin is set, that pin will be used to switch an external mosfet connecting
Sissors 5:2cd4928e8147 67 * data to Vdd. If it is parasite powered and the pin is not set, the regular data pin
Sissors 5:2cd4928e8147 68 * is used to supply extra power when required. This will be sufficient as long as the
Sissors 5:2cd4928e8147 69 * number of probes is limitted.
Michael_ 2:ee820a991b95 70 *
Michael_ 2:ee820a991b95 71 * @param data_pin DigitalInOut pin for the data bus
Sissors 5:2cd4928e8147 72 * @param power_pin DigitalOut (optional) pin to control the power MOSFET
Sissors 5:2cd4928e8147 73 * @param power_polarity bool (optional) which sets active state (0 for active low (default), 1 for active high)
Michael_ 2:ee820a991b95 74 */
Sissors 5:2cd4928e8147 75 DS1820(PinName data_pin, PinName power_pin = NC, bool power_polarity = 0); // Constructor with parasite power pin
Sissors 5:2cd4928e8147 76 ~DS1820();
Michael_ 2:ee820a991b95 77
Sissors 5:2cd4928e8147 78 /** Function to see if there are DS1820 devices left on a pin which do not have a corresponding DS1820 object
Sissors 5:2cd4928e8147 79 *
Sissors 5:2cd4928e8147 80 * @return - true if there are one or more unassigned devices, otherwise false
Michael_ 2:ee820a991b95 81 */
Sissors 5:2cd4928e8147 82 static bool unassignedProbe(PinName pin);
Michael_ 2:ee820a991b95 83
Michael_ 2:ee820a991b95 84 /** This routine will initiate the temperature conversion within
Sissors 5:2cd4928e8147 85 * one or all DS1820 probes.
Michael_ 2:ee820a991b95 86 *
pairmand 3:8f2b7f4940b5 87 * @param wait if true or parisitic power is used, waits up to 750 ms for
pairmand 3:8f2b7f4940b5 88 * conversion otherwise returns immediatly.
pairmand 3:8f2b7f4940b5 89 * @param device allows the function to apply to a specific device or
Michael_ 2:ee820a991b95 90 * to all devices on the 1-Wire bus.
pairmand 3:8f2b7f4940b5 91 * @returns milliseconds untill conversion will complete.
Michael_ 2:ee820a991b95 92 */
Sissors 6:abfdd851218a 93 int convertTemperature(bool wait, devices device=all_devices);
Michael_ 2:ee820a991b95 94
pairmand 3:8f2b7f4940b5 95 /** This function will return the probe temperature. Approximately 10ms per
pairmand 3:8f2b7f4940b5 96 * probe to read its RAM, do CRC check and convert temperature on the LPC1768.
Michael_ 2:ee820a991b95 97 *
Michael_ 2:ee820a991b95 98 * @param scale, may be either 'c' or 'f'
Sissors 7:58b61681818f 99 * @returns temperature for that scale, or DS1820::invalid_conversion (-1000) if CRC error detected.
Michael_ 2:ee820a991b95 100 */
Michael_ 2:ee820a991b95 101 float temperature(char scale='c');
Michael_ 2:ee820a991b95 102
pairmand 3:8f2b7f4940b5 103 /** This function sets the temperature resolution for the DS18B20
pairmand 3:8f2b7f4940b5 104 * in the configuration register.
pairmand 3:8f2b7f4940b5 105 *
pairmand 3:8f2b7f4940b5 106 * @param a number between 9 and 12 to specify resolution
pairmand 3:8f2b7f4940b5 107 * @returns true if successful
pairmand 3:8f2b7f4940b5 108 */
Sissors 5:2cd4928e8147 109 bool setResolution(unsigned int resolution);
Michael_ 2:ee820a991b95 110
Michael_ 2:ee820a991b95 111 private:
Michael_ 2:ee820a991b95 112 bool _parasite_power;
Sissors 5:2cd4928e8147 113 bool _power_mosfet;
Sissors 5:2cd4928e8147 114 bool _power_polarity;
Sissors 5:2cd4928e8147 115
Sissors 11:1a3c3002b50c 116 static char CRC_byte(char _CRC, char byte );
Sissors 5:2cd4928e8147 117 static bool onewire_reset(DigitalInOut *pin);
Michael_ 2:ee820a991b95 118 void match_ROM();
Michael_ 2:ee820a991b95 119 void skip_ROM();
Sissors 5:2cd4928e8147 120 static bool search_ROM_routine(DigitalInOut *pin, char command, char *ROM_address);
Sissors 5:2cd4928e8147 121 static void onewire_bit_out (DigitalInOut *pin, bool bit_data);
Michael_ 2:ee820a991b95 122 void onewire_byte_out(char data);
Sissors 5:2cd4928e8147 123 static bool onewire_bit_in(DigitalInOut *pin);
Michael_ 2:ee820a991b95 124 char onewire_byte_in();
Sissors 5:2cd4928e8147 125 static bool ROM_checksum_error(char *_ROM_address);
Sissors 5:2cd4928e8147 126 bool RAM_checksum_error();
Sissors 5:2cd4928e8147 127 void read_RAM();
Sissors 5:2cd4928e8147 128 static bool unassignedProbe(DigitalInOut *pin, char *ROM_address);
Sissors 5:2cd4928e8147 129 void write_scratchpad(int data);
Sissors 5:2cd4928e8147 130 bool read_power_supply(devices device=this_device);
Michael_ 2:ee820a991b95 131
Michael_ 2:ee820a991b95 132 DigitalInOut _datapin;
Michael_ 2:ee820a991b95 133 DigitalOut _parasitepin;
Sissors 5:2cd4928e8147 134
Sissors 5:2cd4928e8147 135 char _ROM[8];
Sissors 5:2cd4928e8147 136 char RAM[9];
Sissors 5:2cd4928e8147 137
Sissors 5:2cd4928e8147 138 static LinkedList<node> probes;
Michael_ 2:ee820a991b95 139 };
Michael_ 2:ee820a991b95 140
Michael_ 2:ee820a991b95 141
Michael_ 2:ee820a991b95 142 #endif