Thundersoft
/
VL6180XA1_for_TT_Mxx
Creating a project about VL6180XA1 for TT_Mxx
main.cpp@3:7a97a01bad5e, 2019-04-26 (annotated)
- Committer:
- ThunderSoft
- Date:
- Fri Apr 26 09:34:53 2019 +0000
- Revision:
- 3:7a97a01bad5e
- Parent:
- 0:293917667c17
"update the mbed-os code to support TT_M4G9"
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ThunderSoft | 0:293917667c17 | 1 | #include "mbed.h" |
ThunderSoft | 0:293917667c17 | 2 | #include "VL6180X.h" |
ThunderSoft | 0:293917667c17 | 3 | #include "STMPE1600.h" |
ThunderSoft | 0:293917667c17 | 4 | #include "Display.h" |
ThunderSoft | 0:293917667c17 | 5 | #include "Switch.h" |
ThunderSoft | 0:293917667c17 | 6 | |
ThunderSoft | 0:293917667c17 | 7 | |
ThunderSoft | 0:293917667c17 | 8 | |
ThunderSoft | 0:293917667c17 | 9 | |
ThunderSoft | 0:293917667c17 | 10 | |
ThunderSoft | 0:293917667c17 | 11 | |
ThunderSoft | 0:293917667c17 | 12 | #ifdef TEST_LCD |
ThunderSoft | 0:293917667c17 | 13 | LCD tft(LCD_SPI_CS,LCD_SPI_DC, LCD_MOSI_PIN, LCD_MISO_PIN, LCD_SPI_CL_PIN,LCD_BL_PIN); |
ThunderSoft | 0:293917667c17 | 14 | #else |
ThunderSoft | 0:293917667c17 | 15 | #define LCD int |
ThunderSoft | 0:293917667c17 | 16 | LCD tft; |
ThunderSoft | 0:293917667c17 | 17 | #endif |
ThunderSoft | 0:293917667c17 | 18 | |
ThunderSoft | 0:293917667c17 | 19 | |
ThunderSoft | 0:293917667c17 | 20 | #if __TT_M3HQ__ |
ThunderSoft | 0:293917667c17 | 21 | #define DISPLAY_TMPM_STRING "Welcome to Thundersoft TT_M3HQ" |
ThunderSoft | 0:293917667c17 | 22 | #endif |
ThunderSoft | 0:293917667c17 | 23 | |
ThunderSoft | 0:293917667c17 | 24 | |
ThunderSoft | 0:293917667c17 | 25 | #if __TT_M4G9__ |
ThunderSoft | 0:293917667c17 | 26 | #define DISPLAY_TMPM_STRING "Welcome to Thundersoft TT_M4G9" |
ThunderSoft | 0:293917667c17 | 27 | #endif |
ThunderSoft | 0:293917667c17 | 28 | |
ThunderSoft | 0:293917667c17 | 29 | |
ThunderSoft | 0:293917667c17 | 30 | |
ThunderSoft | 0:293917667c17 | 31 | |
ThunderSoft | 0:293917667c17 | 32 | #define DISPLAY_VL6180_ID_STRING "VL6180 ID:" |
ThunderSoft | 0:293917667c17 | 33 | #define DISPLAY_VL6180_ID_HIGH (16 * 1) |
ThunderSoft | 0:293917667c17 | 34 | #define DISPLAY_STEMPE_STRING "STMPE ID:" |
ThunderSoft | 0:293917667c17 | 35 | #define DISPLAY_STEMPE_ID_HIGH (DISPLAY_VL6180_ID_HIGH * 2) |
ThunderSoft | 0:293917667c17 | 36 | #define DISPLAY_VL6180_RANGE_VALUE_STRING "VL6180X RANG:" |
ThunderSoft | 0:293917667c17 | 37 | #define DISPLAY_VL6180_RANGE_STRING_HIGH (DISPLAY_VL6180_ID_HIGH * 3) |
ThunderSoft | 0:293917667c17 | 38 | #define DISPLAY_VL6180_RANGE_VALUE_HIGH (DISPLAY_VL6180_ID_HIGH * 4) |
ThunderSoft | 0:293917667c17 | 39 | #define DISPLAY_VL6180_ALS_VALUE_STRING "VL6180X ALS:" |
ThunderSoft | 0:293917667c17 | 40 | #define DISPLAY_VL6180_ALS_STRING_HIGH (DISPLAY_VL6180_ID_HIGH * 5) |
ThunderSoft | 0:293917667c17 | 41 | #define DISPLAY_VL6180_ALS_VALUE_HIGH (DISPLAY_VL6180_ID_HIGH * 6) |
ThunderSoft | 0:293917667c17 | 42 | |
ThunderSoft | 0:293917667c17 | 43 | |
ThunderSoft | 0:293917667c17 | 44 | |
ThunderSoft | 0:293917667c17 | 45 | |
ThunderSoft | 0:293917667c17 | 46 | static void displayForVL6180X(LCD &lcd,VL6180X &vl6180x,STMPE1600 &stmpe1600) |
ThunderSoft | 0:293917667c17 | 47 | { |
ThunderSoft | 0:293917667c17 | 48 | #ifdef TEST_LCD |
ThunderSoft | 0:293917667c17 | 49 | char temp_buffer[5]; |
ThunderSoft | 0:293917667c17 | 50 | temp_buffer[4] = '\0'; |
ThunderSoft | 0:293917667c17 | 51 | lcd.drawString(0,0,DISPLAY_TMPM_STRING,RED); |
ThunderSoft | 0:293917667c17 | 52 | |
ThunderSoft | 0:293917667c17 | 53 | lcd.drawString(0,DISPLAY_VL6180_ID_HIGH,DISPLAY_VL6180_ID_STRING,RED); |
ThunderSoft | 0:293917667c17 | 54 | translateBinaryToBCD(temp_buffer,vl6180x.readID()); |
ThunderSoft | 0:293917667c17 | 55 | lcd.drawString((sizeof(DISPLAY_VL6180_ID_STRING) - 1) * FONT_CHAR_WIDTH,DISPLAY_VL6180_ID_HIGH,(const char *)temp_buffer,BLACK); |
ThunderSoft | 0:293917667c17 | 56 | |
ThunderSoft | 0:293917667c17 | 57 | displayId(lcd,DISPLAY_STEMPE_STRING,sizeof(DISPLAY_STEMPE_STRING),DISPLAY_STEMPE_ID_HIGH,stmpe1600.readID()); |
ThunderSoft | 0:293917667c17 | 58 | |
ThunderSoft | 0:293917667c17 | 59 | /*Set 6180XA1 for LCD string*/ |
ThunderSoft | 0:293917667c17 | 60 | lcd.drawString(0,DISPLAY_VL6180_RANGE_STRING_HIGH,DISPLAY_VL6180_RANGE_VALUE_STRING,RED); |
ThunderSoft | 0:293917667c17 | 61 | lcd.drawString(0,DISPLAY_VL6180_ALS_STRING_HIGH,DISPLAY_VL6180_ALS_VALUE_STRING,RED); |
ThunderSoft | 0:293917667c17 | 62 | #endif |
ThunderSoft | 0:293917667c17 | 63 | } |
ThunderSoft | 0:293917667c17 | 64 | |
ThunderSoft | 0:293917667c17 | 65 | static void handleLCDForVL6180X(LCD &lcd,VL6180X &vl6180x) |
ThunderSoft | 0:293917667c17 | 66 | { |
ThunderSoft | 0:293917667c17 | 67 | char temp_buffer[50]; |
ThunderSoft | 0:293917667c17 | 68 | while(1) |
ThunderSoft | 0:293917667c17 | 69 | { |
ThunderSoft | 0:293917667c17 | 70 | /*data for range */ |
ThunderSoft | 0:293917667c17 | 71 | memset(temp_buffer,0,sizeof(temp_buffer)); |
ThunderSoft | 0:293917667c17 | 72 | sprintf(temp_buffer,"%d",vl6180x.readRangeSingle()); |
ThunderSoft | 0:293917667c17 | 73 | #ifdef TEST_LCD |
ThunderSoft | 0:293917667c17 | 74 | lcd.drawString(0,DISPLAY_VL6180_RANGE_VALUE_HIGH,temp_buffer,RED); |
ThunderSoft | 0:293917667c17 | 75 | #endif |
ThunderSoft | 0:293917667c17 | 76 | printf("Range = %d \r\n",vl6180x.readRangeSingle()); |
ThunderSoft | 0:293917667c17 | 77 | /*data for als*/ |
ThunderSoft | 0:293917667c17 | 78 | memset(temp_buffer,0,sizeof(temp_buffer)); |
ThunderSoft | 0:293917667c17 | 79 | sprintf(temp_buffer,"%d",vl6180x.readAmbientSingle()); |
ThunderSoft | 0:293917667c17 | 80 | #ifdef TEST_LCD |
ThunderSoft | 0:293917667c17 | 81 | lcd.drawString(0,DISPLAY_VL6180_ALS_VALUE_HIGH,temp_buffer,RED); |
ThunderSoft | 0:293917667c17 | 82 | #endif |
ThunderSoft | 0:293917667c17 | 83 | printf("ALS = %d \r\n",vl6180x.readAmbientSingle()); |
ThunderSoft | 0:293917667c17 | 84 | wait_ms(1000); |
ThunderSoft | 0:293917667c17 | 85 | #ifdef TEST_LCD |
ThunderSoft | 0:293917667c17 | 86 | lcd.clearScreenArea(0,DISPLAY_VL6180_RANGE_VALUE_HIGH,WHITE); |
ThunderSoft | 0:293917667c17 | 87 | lcd.clearScreenArea(0,DISPLAY_VL6180_ALS_VALUE_HIGH,WHITE); |
ThunderSoft | 0:293917667c17 | 88 | #endif |
ThunderSoft | 0:293917667c17 | 89 | } |
ThunderSoft | 0:293917667c17 | 90 | } |
ThunderSoft | 0:293917667c17 | 91 | |
ThunderSoft | 0:293917667c17 | 92 | |
ThunderSoft | 0:293917667c17 | 93 | int main() |
ThunderSoft | 0:293917667c17 | 94 | { |
ThunderSoft | 0:293917667c17 | 95 | printf("%s\r\n",DISPLAY_TMPM_STRING); |
ThunderSoft | 0:293917667c17 | 96 | I2C *i2c =new I2C(D14,D15); |
ThunderSoft | 0:293917667c17 | 97 | VL6180X *vl6180x = new VL6180X(i2c); |
ThunderSoft | 0:293917667c17 | 98 | STMPE1600 *stmpe1600 = new STMPE1600(i2c); |
ThunderSoft | 0:293917667c17 | 99 | Display display(*stmpe1600); |
ThunderSoft | 0:293917667c17 | 100 | Switch _switch(*stmpe1600); |
ThunderSoft | 0:293917667c17 | 101 | //MeasureData_t measure_data; |
ThunderSoft | 0:293917667c17 | 102 | vl6180x->init(); |
ThunderSoft | 0:293917667c17 | 103 | vl6180x->configureDefault(); |
ThunderSoft | 0:293917667c17 | 104 | //vl6180x->startAmbientContinuous(); |
ThunderSoft | 0:293917667c17 | 105 | printf("Vl6180X ID = 0x%x \r\n",vl6180x->readID()); |
ThunderSoft | 0:293917667c17 | 106 | printf("STMPE1600 ID = 0x%x \r\n",stmpe1600->readID()); |
ThunderSoft | 0:293917667c17 | 107 | #ifdef TEST_LCD |
ThunderSoft | 0:293917667c17 | 108 | tft.init(); |
ThunderSoft | 0:293917667c17 | 109 | #endif |
ThunderSoft | 0:293917667c17 | 110 | displayForVL6180X(tft,*vl6180x,*stmpe1600); |
ThunderSoft | 0:293917667c17 | 111 | handleLCDForVL6180X(tft,*vl6180x); |
ThunderSoft | 0:293917667c17 | 112 | while(1) |
ThunderSoft | 0:293917667c17 | 113 | { |
ThunderSoft | 0:293917667c17 | 114 | } |
ThunderSoft | 0:293917667c17 | 115 | } |