Color sensor reset at the end of calibration added. sensor id auto assignment was changed to be a fixed value assignment to avoid sensor id shift when some sensor is absent.
Dependencies: UniGraphic mbed vt100
sensors/LM75B.h@1:8818b793d147, 2018-02-23 (annotated)
- Committer:
- Rhyme
- Date:
- Fri Feb 23 07:51:55 2018 +0000
- Revision:
- 1:8818b793d147
- Parent:
- 0:ce97f6d34336
Wrong behavior when one of color sensor is missing has been fixed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:ce97f6d34336 | 1 | #ifndef _LM75B_H_ |
Rhyme | 0:ce97f6d34336 | 2 | #define _LM75B_H_ |
Rhyme | 0:ce97f6d34336 | 3 | |
Rhyme | 0:ce97f6d34336 | 4 | #include "mbed.h" |
Rhyme | 0:ce97f6d34336 | 5 | |
Rhyme | 0:ce97f6d34336 | 6 | /** |
Rhyme | 0:ce97f6d34336 | 7 | * NXP LM75B Digital temperature sensor and thermal watchdog |
Rhyme | 0:ce97f6d34336 | 8 | * |
Rhyme | 0:ce97f6d34336 | 9 | * @code |
Rhyme | 0:ce97f6d34336 | 10 | #include "mbed.h" |
Rhyme | 0:ce97f6d34336 | 11 | #include "LM75B.h" |
Rhyme | 0:ce97f6d34336 | 12 | #define LM75B_I2C_ADDRESS (0x48) |
Rhyme | 0:ce97f6d34336 | 13 | |
Rhyme | 0:ce97f6d34336 | 14 | #if defined (TARGET_KL25Z) |
Rhyme | 0:ce97f6d34336 | 15 | #define PIN_SCL PTE1 |
Rhyme | 0:ce97f6d34336 | 16 | #define PIN_SDA PTE0 |
Rhyme | 0:ce97f6d34336 | 17 | #elif defined (TARGET_KL46Z) |
Rhyme | 0:ce97f6d34336 | 18 | #define PIN_SCL PTE1 |
Rhyme | 0:ce97f6d34336 | 19 | #define PIN_SDA PTE0 |
Rhyme | 0:ce97f6d34336 | 20 | #elif defined (TARGET_K64F) |
Rhyme | 0:ce97f6d34336 | 21 | #define PIN_SCL PTE24 |
Rhyme | 0:ce97f6d34336 | 22 | #define PIN_SDA PTE25 |
Rhyme | 0:ce97f6d34336 | 23 | #elif defined (TARGET_K22F) |
Rhyme | 0:ce97f6d34336 | 24 | #define PIN_SCL PTE1 |
Rhyme | 0:ce97f6d34336 | 25 | #define PIN_SDA PTE0 |
Rhyme | 0:ce97f6d34336 | 26 | #elif defined (TARGET_KL05Z) |
Rhyme | 0:ce97f6d34336 | 27 | #define PIN_SCL PTB3 |
Rhyme | 0:ce97f6d34336 | 28 | #define PIN_SDA PTB4 |
Rhyme | 0:ce97f6d34336 | 29 | #elif defined (TARGET_NUCLEO_F411RE) |
Rhyme | 0:ce97f6d34336 | 30 | #define PIN_SCL PB_8 |
Rhyme | 0:ce97f6d34336 | 31 | #define PIN_SDA PB_9 |
Rhyme | 0:ce97f6d34336 | 32 | #else |
Rhyme | 0:ce97f6d34336 | 33 | #error TARGET NOT DEFINED |
Rhyme | 0:ce97f6d34336 | 34 | #endif |
Rhyme | 0:ce97f6d34336 | 35 | |
Rhyme | 0:ce97f6d34336 | 36 | int main() { |
Rhyme | 0:ce97f6d34336 | 37 | int8_t itemp = 0 ; |
Rhyme | 0:ce97f6d34336 | 38 | float ftemp = 0.0 ; |
Rhyme | 0:ce97f6d34336 | 39 | LM75B lm75b(PIN_SDA, PIN_SCL, LM75B_I2C_ADDRESS) ; |
Rhyme | 0:ce97f6d34336 | 40 | |
Rhyme | 0:ce97f6d34336 | 41 | while(1) { |
Rhyme | 0:ce97f6d34336 | 42 | itemp = lm75b.temp() ; |
Rhyme | 0:ce97f6d34336 | 43 | lm75b.getTemp(&ftemp) ; |
Rhyme | 0:ce97f6d34336 | 44 | printf("Temp = %d C degree, %.3f C degree\n", itemp, ftemp) ; |
Rhyme | 0:ce97f6d34336 | 45 | wait(1) ; |
Rhyme | 0:ce97f6d34336 | 46 | } |
Rhyme | 0:ce97f6d34336 | 47 | } |
Rhyme | 0:ce97f6d34336 | 48 | * @endcode |
Rhyme | 0:ce97f6d34336 | 49 | */ |
Rhyme | 0:ce97f6d34336 | 50 | class LM75B |
Rhyme | 0:ce97f6d34336 | 51 | { |
Rhyme | 0:ce97f6d34336 | 52 | public: |
Rhyme | 0:ce97f6d34336 | 53 | /** |
Rhyme | 0:ce97f6d34336 | 54 | * LM75B constructor |
Rhyme | 0:ce97f6d34336 | 55 | * |
Rhyme | 0:ce97f6d34336 | 56 | * @param i2c pointer to the I2C object |
Rhyme | 0:ce97f6d34336 | 57 | * @param addr addr of the I2C peripheral |
Rhyme | 0:ce97f6d34336 | 58 | */ |
Rhyme | 0:ce97f6d34336 | 59 | LM75B(I2C *i2c, int addr); |
Rhyme | 0:ce97f6d34336 | 60 | |
Rhyme | 0:ce97f6d34336 | 61 | /** |
Rhyme | 0:ce97f6d34336 | 62 | * LM75B destructor |
Rhyme | 0:ce97f6d34336 | 63 | */ |
Rhyme | 0:ce97f6d34336 | 64 | ~LM75B(); |
Rhyme | 0:ce97f6d34336 | 65 | |
Rhyme | 0:ce97f6d34336 | 66 | /** |
Rhyme | 0:ce97f6d34336 | 67 | * get temperature as one byte (signed) |
Rhyme | 0:ce97f6d34336 | 68 | * @param *temp int8_t returns integer part of the temperature |
Rhyme | 0:ce97f6d34336 | 69 | * @return 0: success not-0: failure |
Rhyme | 0:ce97f6d34336 | 70 | */ |
Rhyme | 0:ce97f6d34336 | 71 | int temp(int8_t *temp) ; |
Rhyme | 0:ce97f6d34336 | 72 | |
Rhyme | 0:ce97f6d34336 | 73 | /** |
Rhyme | 0:ce97f6d34336 | 74 | * get temperature as 11 bit (float) |
Rhyme | 0:ce97f6d34336 | 75 | * @param *temp float returns the temperature as float |
Rhyme | 0:ce97f6d34336 | 76 | * @return 0: success not-0: failure |
Rhyme | 0:ce97f6d34336 | 77 | */ |
Rhyme | 0:ce97f6d34336 | 78 | int getTemp(float *temp) ; |
Rhyme | 0:ce97f6d34336 | 79 | |
Rhyme | 0:ce97f6d34336 | 80 | /** |
Rhyme | 0:ce97f6d34336 | 81 | * get configuration register |
Rhyme | 0:ce97f6d34336 | 82 | * @param ptr_byte uint8_t pointer value for the register |
Rhyme | 0:ce97f6d34336 | 83 | * @param *config_data uint8_t value of the config register |
Rhyme | 0:ce97f6d34336 | 84 | * @return 0: success non-0: failure |
Rhyme | 0:ce97f6d34336 | 85 | */ |
Rhyme | 0:ce97f6d34336 | 86 | int getConfig(uint8_t ptr_byte, uint8_t *config_data) ; |
Rhyme | 0:ce97f6d34336 | 87 | |
Rhyme | 0:ce97f6d34336 | 88 | /** |
Rhyme | 0:ce97f6d34336 | 89 | * set configuration register |
Rhyme | 0:ce97f6d34336 | 90 | * @param ptr_byte uint8_t pointer value for the register |
Rhyme | 0:ce97f6d34336 | 91 | * @param config_data uint8_t value to set in the config register |
Rhyme | 0:ce97f6d34336 | 92 | * @return 0: success non-0: failure |
Rhyme | 0:ce97f6d34336 | 93 | */ |
Rhyme | 0:ce97f6d34336 | 94 | int setConfig(uint8_t ptr_byte, uint8_t config_data) ; |
Rhyme | 0:ce97f6d34336 | 95 | |
Rhyme | 0:ce97f6d34336 | 96 | private: |
Rhyme | 0:ce97f6d34336 | 97 | I2C *p_i2c; |
Rhyme | 0:ce97f6d34336 | 98 | int m_addr; |
Rhyme | 0:ce97f6d34336 | 99 | int readRegs(int addr, uint8_t * data, int len); |
Rhyme | 0:ce97f6d34336 | 100 | int writeRegs(uint8_t * data, int len); |
Rhyme | 0:ce97f6d34336 | 101 | |
Rhyme | 0:ce97f6d34336 | 102 | }; |
Rhyme | 0:ce97f6d34336 | 103 | |
Rhyme | 0:ce97f6d34336 | 104 | #endif |