Creating a project for TT_Mxx

Committer:
ThunderSoft
Date:
Fri Apr 26 09:48:41 2019 +0000
Revision:
2:2186c624272f
Parent:
1:40799c64129e
"Update the mbed-os code to support TT_M4G9"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ThunderSoft 0:1159c687a20f 1 #include "mbed.h"
ThunderSoft 0:1159c687a20f 2 #include "HTU21D.h"
ThunderSoft 0:1159c687a20f 3
ThunderSoft 0:1159c687a20f 4
ThunderSoft 0:1159c687a20f 5
ThunderSoft 0:1159c687a20f 6
ThunderSoft 0:1159c687a20f 7
ThunderSoft 0:1159c687a20f 8 #if __TT_M3HQ__
ThunderSoft 0:1159c687a20f 9 #define DISPLAY_TMPM_STRING "Welcome to Thundersoft TT_M3HQ"
ThunderSoft 0:1159c687a20f 10 #endif
ThunderSoft 0:1159c687a20f 11
ThunderSoft 0:1159c687a20f 12
ThunderSoft 0:1159c687a20f 13 #if __TT_M4G9__
ThunderSoft 0:1159c687a20f 14 #define DISPLAY_TMPM_STRING "Welcome to Thundersoft TT_M4G9"
ThunderSoft 0:1159c687a20f 15 #endif
ThunderSoft 0:1159c687a20f 16
ThunderSoft 0:1159c687a20f 17
ThunderSoft 0:1159c687a20f 18 #ifdef TEST_LCD
ThunderSoft 0:1159c687a20f 19 LCD tft(LCD_SPI_CS,LCD_SPI_DC, LCD_MOSI_PIN, LCD_MISO_PIN, LCD_SPI_CL_PIN,LCD_BL_PIN);
ThunderSoft 0:1159c687a20f 20 #else
ThunderSoft 0:1159c687a20f 21 #define LCD int
ThunderSoft 0:1159c687a20f 22 LCD tft;
ThunderSoft 0:1159c687a20f 23 #endif
ThunderSoft 0:1159c687a20f 24
ThunderSoft 0:1159c687a20f 25
ThunderSoft 0:1159c687a20f 26
ThunderSoft 0:1159c687a20f 27
ThunderSoft 0:1159c687a20f 28
ThunderSoft 0:1159c687a20f 29 /*macros for HTU21D*/
ThunderSoft 0:1159c687a20f 30 #define DISPLAY_HTU21D_STRING "HTU21D Sensor:"
ThunderSoft 0:1159c687a20f 31 #define DISPLAY_HTU21D_STRING_HIGH 16
ThunderSoft 0:1159c687a20f 32 #define DISPLAY_HTU21D_TEM_VALUE_STRING "Temperature value:"
ThunderSoft 0:1159c687a20f 33 #define DISPLAY_HTU21D_TEM_VALUE_STRING_HIGH 32
ThunderSoft 0:1159c687a20f 34 #define DISPLAY_HTU21D_TEM_VALUE_HIGH 48
ThunderSoft 0:1159c687a20f 35 #define DISPLAY_HTU21D_HUM_VALUE_STRING "Humidity value:"
ThunderSoft 0:1159c687a20f 36 #define DISPLAY_HTU21D_HUM_VALUE_STRING_HIGH 64
ThunderSoft 0:1159c687a20f 37 #define DISPLAY_HTU21D_HUM_VALUE_HIGH 80
ThunderSoft 0:1159c687a20f 38
ThunderSoft 0:1159c687a20f 39
ThunderSoft 0:1159c687a20f 40
ThunderSoft 0:1159c687a20f 41 static void displayForHTU21D(LCD &lcd,HTU21D &htu)
ThunderSoft 0:1159c687a20f 42 {
ThunderSoft 0:1159c687a20f 43 #ifdef TEST_LCD
ThunderSoft 0:1159c687a20f 44 lcd.drawString(0,0,DISPLAY_TMPM_STRING,RED);
ThunderSoft 0:1159c687a20f 45 lcd.drawString(0,DISPLAY_HTU21D_STRING_HIGH,DISPLAY_HTU21D_STRING,RED);
ThunderSoft 0:1159c687a20f 46 lcd.drawString(0,DISPLAY_HTU21D_TEM_VALUE_STRING_HIGH,DISPLAY_HTU21D_TEM_VALUE_STRING,RED);
ThunderSoft 0:1159c687a20f 47 lcd.drawString(0,DISPLAY_HTU21D_HUM_VALUE_STRING_HIGH,DISPLAY_HTU21D_HUM_VALUE_STRING,RED);
ThunderSoft 0:1159c687a20f 48 #endif
ThunderSoft 0:1159c687a20f 49 }
ThunderSoft 0:1159c687a20f 50
ThunderSoft 0:1159c687a20f 51 static void handleLCDForHTU21D(LCD &lcd,HTU21D &htu)
ThunderSoft 0:1159c687a20f 52 {
ThunderSoft 0:1159c687a20f 53 char temp_buffer[50];
ThunderSoft 0:1159c687a20f 54 int temperature,humidity;
ThunderSoft 0:1159c687a20f 55 while(1)
ThunderSoft 0:1159c687a20f 56 {
ThunderSoft 0:1159c687a20f 57 temperature = htu.sample_ctemp();
ThunderSoft 0:1159c687a20f 58 humidity = htu.sample_humid();
ThunderSoft 0:1159c687a20f 59 memset(temp_buffer,0,sizeof(temp_buffer));
ThunderSoft 0:1159c687a20f 60 sprintf(temp_buffer,"%d",temperature);
ThunderSoft 0:1159c687a20f 61 printf("HTU21D temperature = %d \r\n",temperature);
ThunderSoft 0:1159c687a20f 62 #ifdef TEST_LCD
ThunderSoft 0:1159c687a20f 63 lcd.drawString(0,DISPLAY_HTU21D_TEM_VALUE_HIGH,temp_buffer,RED);
ThunderSoft 0:1159c687a20f 64 #endif
ThunderSoft 0:1159c687a20f 65 memset(temp_buffer,0,sizeof(temp_buffer));
ThunderSoft 0:1159c687a20f 66 sprintf(temp_buffer,"%d",humidity);
ThunderSoft 0:1159c687a20f 67 printf("HTU21D humidity = %d \r\n",humidity);
ThunderSoft 0:1159c687a20f 68 #ifdef TEST_LCD
ThunderSoft 0:1159c687a20f 69 lcd.drawString(0,DISPLAY_HTU21D_HUM_VALUE_HIGH,temp_buffer,RED);
ThunderSoft 0:1159c687a20f 70 #endif
ThunderSoft 0:1159c687a20f 71 wait_ms(1000);
ThunderSoft 0:1159c687a20f 72 #ifdef TEST_LCD
ThunderSoft 0:1159c687a20f 73 lcd.clearScreenArea(0,DISPLAY_HTU21D_TEM_VALUE_HIGH,WHITE);
ThunderSoft 0:1159c687a20f 74 lcd.clearScreenArea(0,DISPLAY_HTU21D_HUM_VALUE_HIGH,WHITE);
ThunderSoft 0:1159c687a20f 75 #endif
ThunderSoft 0:1159c687a20f 76 }
ThunderSoft 0:1159c687a20f 77 }
ThunderSoft 0:1159c687a20f 78
ThunderSoft 0:1159c687a20f 79 int main()
ThunderSoft 0:1159c687a20f 80 {
ThunderSoft 1:40799c64129e 81 HTU21D htu;
ThunderSoft 1:40799c64129e 82 printf("%s\r\n",DISPLAY_TMPM_STRING);
ThunderSoft 1:40799c64129e 83 #ifdef TEST_LCD
ThunderSoft 1:40799c64129e 84 tft.init();
ThunderSoft 1:40799c64129e 85 #endif
ThunderSoft 1:40799c64129e 86 displayForHTU21D(tft,htu);
ThunderSoft 1:40799c64129e 87 handleLCDForHTU21D(tft,htu);
ThunderSoft 1:40799c64129e 88 while(1)
ThunderSoft 1:40799c64129e 89 {
ThunderSoft 1:40799c64129e 90 }
ThunderSoft 0:1159c687a20f 91 }