Added a GPIO to power on/off for external I2C sensor(s) (with LEDs)

Dependencies:   UniGraphic mbed vt100

18-Jun-2018 外部センサの電源オン・オフ機能は下位互換の為に無効になっていました。 この版で再度有効にしました。

Committer:
Rhyme
Date:
Fri Apr 13 04:19:23 2018 +0000
Revision:
0:846e2321c637
power to color sensor on/off test OK. Currently the function is disabled.

Who changed what in which revision?

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