Thundersoft
/
BH1790GLC_for_TTMxx
BH1790GLC
main.cpp@1:e9033991d204, 2019-03-21 (annotated)
- Committer:
- ThunderSoft
- Date:
- Thu Mar 21 08:52:45 2019 +0000
- Revision:
- 1:e9033991d204
Add BH1790GLC code for TT_Mxx.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ThunderSoft | 1:e9033991d204 | 1 | #include "mbed.h" |
ThunderSoft | 1:e9033991d204 | 2 | #include "bh1790glc.h" |
ThunderSoft | 1:e9033991d204 | 3 | |
ThunderSoft | 1:e9033991d204 | 4 | |
ThunderSoft | 1:e9033991d204 | 5 | #ifdef TEST_LCD |
ThunderSoft | 1:e9033991d204 | 6 | LCD tft(LCD_SPI_CS,LCD_SPI_DC, LCD_MOSI_PIN, LCD_MISO_PIN, LCD_SPI_CL_PIN,LCD_BL_PIN); |
ThunderSoft | 1:e9033991d204 | 7 | #else |
ThunderSoft | 1:e9033991d204 | 8 | #define LCD int |
ThunderSoft | 1:e9033991d204 | 9 | LCD tft; |
ThunderSoft | 1:e9033991d204 | 10 | #endif |
ThunderSoft | 1:e9033991d204 | 11 | |
ThunderSoft | 1:e9033991d204 | 12 | |
ThunderSoft | 1:e9033991d204 | 13 | #define DISPLAY_TMPM_STRING "Welcome to Thundersoft TT_M3HQ" |
ThunderSoft | 1:e9033991d204 | 14 | |
ThunderSoft | 1:e9033991d204 | 15 | /*macro for BH1790GLC*/ |
ThunderSoft | 1:e9033991d204 | 16 | #define DISPLAY_BH1790GLC_STRING_ID "BH1790GLC ID:" |
ThunderSoft | 1:e9033991d204 | 17 | #define DISPLAY_BH1790GLC_STRING_ID_HIGH 16 |
ThunderSoft | 1:e9033991d204 | 18 | #define DISPLAY_BH1790GLC_VALUE_STRING "BH1790GLC value:" |
ThunderSoft | 1:e9033991d204 | 19 | #define DISPLAY_BH1790GLC_VALUE_STRING_HIGH 32 |
ThunderSoft | 1:e9033991d204 | 20 | #define DISPLAY_BH1790GLC_VALUE_HIGH 48 |
ThunderSoft | 1:e9033991d204 | 21 | |
ThunderSoft | 1:e9033991d204 | 22 | |
ThunderSoft | 1:e9033991d204 | 23 | static void displayForBH1790GLC(LCD &lcd,BH1790GLC &bh1790glc) |
ThunderSoft | 1:e9033991d204 | 24 | { |
ThunderSoft | 1:e9033991d204 | 25 | #ifdef TEST_LCD |
ThunderSoft | 1:e9033991d204 | 26 | lcd.drawString(0,0,DISPLAY_TMPM_STRING,RED); |
ThunderSoft | 1:e9033991d204 | 27 | displayId(lcd,DISPLAY_BH1790GLC_STRING_ID,sizeof(DISPLAY_BH1790GLC_STRING_ID),DISPLAY_BH1790GLC_STRING_ID_HIGH,bh1790glc.getDeviceID()); |
ThunderSoft | 1:e9033991d204 | 28 | lcd.drawString(0,DISPLAY_BH1790GLC_VALUE_STRING_HIGH,DISPLAY_BH1790GLC_VALUE_STRING,RED); |
ThunderSoft | 1:e9033991d204 | 29 | #endif |
ThunderSoft | 1:e9033991d204 | 30 | } |
ThunderSoft | 1:e9033991d204 | 31 | |
ThunderSoft | 1:e9033991d204 | 32 | static void handleLCDForBH1790GLC(LCD &lcd,BH1790GLC &bh1790glc) |
ThunderSoft | 1:e9033991d204 | 33 | { |
ThunderSoft | 1:e9033991d204 | 34 | char temp_buffer[50]; |
ThunderSoft | 1:e9033991d204 | 35 | uint16_t data[2]; |
ThunderSoft | 1:e9033991d204 | 36 | while(1) |
ThunderSoft | 1:e9033991d204 | 37 | { |
ThunderSoft | 1:e9033991d204 | 38 | memset(temp_buffer,0,sizeof(temp_buffer)); |
ThunderSoft | 1:e9033991d204 | 39 | #ifdef TEST_LCD |
ThunderSoft | 1:e9033991d204 | 40 | bh1790glc.getresults(data); |
ThunderSoft | 1:e9033991d204 | 41 | #endif |
ThunderSoft | 1:e9033991d204 | 42 | sprintf(temp_buffer,"%d,%d",data[0],data[1]); |
ThunderSoft | 1:e9033991d204 | 43 | printf("BH1790GLC data = %d,%d\r\n",data[0],data[1]); |
ThunderSoft | 1:e9033991d204 | 44 | #ifdef TEST_LCD |
ThunderSoft | 1:e9033991d204 | 45 | lcd.drawString(0,DISPLAY_BH1790GLC_VALUE_HIGH,temp_buffer,RED); |
ThunderSoft | 1:e9033991d204 | 46 | #endif |
ThunderSoft | 1:e9033991d204 | 47 | wait_ms(1000); |
ThunderSoft | 1:e9033991d204 | 48 | #ifdef TEST_LCD |
ThunderSoft | 1:e9033991d204 | 49 | lcd.clearScreenArea(0,DISPLAY_BH1790GLC_VALUE_HIGH,WHITE); |
ThunderSoft | 1:e9033991d204 | 50 | #endif |
ThunderSoft | 1:e9033991d204 | 51 | } |
ThunderSoft | 1:e9033991d204 | 52 | } |
ThunderSoft | 1:e9033991d204 | 53 | |
ThunderSoft | 1:e9033991d204 | 54 | |
ThunderSoft | 1:e9033991d204 | 55 | |
ThunderSoft | 1:e9033991d204 | 56 | |
ThunderSoft | 1:e9033991d204 | 57 | int main() |
ThunderSoft | 1:e9033991d204 | 58 | { |
ThunderSoft | 1:e9033991d204 | 59 | uint16_t data[2]; |
ThunderSoft | 1:e9033991d204 | 60 | I2C i2c(I2C_SDA, I2C_SCL); |
ThunderSoft | 1:e9033991d204 | 61 | RegisterWriter i2c_rw(i2c); |
ThunderSoft | 1:e9033991d204 | 62 | BH1790GLC bh1790glc(i2c_rw); |
ThunderSoft | 1:e9033991d204 | 63 | printf("%s\r\n",DISPLAY_TMPM_STRING); |
ThunderSoft | 1:e9033991d204 | 64 | printf("BH1790GLC Decide Id = 0x%x \r\n",bh1790glc.getDeviceID()); |
ThunderSoft | 1:e9033991d204 | 65 | bh1790glc.set_default_on(); |
ThunderSoft | 1:e9033991d204 | 66 | #ifdef TEST_LCD |
ThunderSoft | 1:e9033991d204 | 67 | tft.init(); |
ThunderSoft | 1:e9033991d204 | 68 | #endif |
ThunderSoft | 1:e9033991d204 | 69 | displayForBH1790GLC(tft,bh1790glc); |
ThunderSoft | 1:e9033991d204 | 70 | handleLCDForBH1790GLC(tft,bh1790glc); |
ThunderSoft | 1:e9033991d204 | 71 | while(1) |
ThunderSoft | 1:e9033991d204 | 72 | { |
ThunderSoft | 1:e9033991d204 | 73 | } |
ThunderSoft | 1:e9033991d204 | 74 | } |