PARK JAICHANG / Mbed OS Hexi_Click_HDC1000

Dependencies:   HDC1000 Hexi_KW40Z Hexi_OLED_SSD1351

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Hexi_KW40Z.h"
00003 #include "Hexi_OLED_SSD1351.h"
00004 #include "HDC1000.h"
00005 #include "string.h"
00006 
00007 #define LED_ON      0
00008 #define LED_OFF     1
00009 
00010 void StartHaptic(void);
00011 void StopHaptic(void const *n);
00012 
00013 DigitalOut  led1(LED1);
00014 
00015 DigitalOut  redLed(PTC8);
00016 DigitalOut  greenLed(PTD0);
00017 DigitalOut  blueLed(PTC9);
00018 DigitalOut  haptic(PTB9);
00019 
00020 HDC1000     hdc(PTD9,PTD8);
00021 Serial      pc(USBTX, USBRX);
00022 SSD1351     oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15);  /* (MOSI,SCLK,POWER,CS,RST,DC) */
00023 KW40Z       kw40z_device(PTE24, PTE25);                 /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */ 
00024 
00025 /* Define timer for haptic feedback */
00026 RtosTimer hapticTimer(StopHaptic, osTimerOnce);
00027 
00028 void ButtonRight(void)
00029 {
00030     StartHaptic();
00031     
00032     redLed      = LED_OFF;
00033     greenLed    = LED_OFF;
00034     blueLed     = LED_ON;
00035 }
00036 
00037 void ButtonLeft(void)
00038 {
00039 //   char t_tmp[10] = {};
00040 //    float tmp = 0.0f;
00041 //    
00042 //    tmp = hdc.conv_c_to_f();
00043 //    
00044 //    
00045 //    /* Get OLED Class Default Text Properties */
00046 //    oled_text_properties_t textProperties = {0};
00047 //    oled.GetTextProperties(&textProperties);    
00048 //
00049 //    /* Turn on the backlight of the OLED Display */
00050 //    oled.DimScreenON();
00051 //    
00052 //    /* Fills the screen with solid black */         
00053 //    oled.FillScreen(COLOR_BLACK);
00054 //    
00055 //    textProperties.fontColor = COLOR_WHITE;
00056 //    oled.SetTextProperties(&textProperties);  
00057 //    
00058 //    sprintf(t_tmp,"%4.1fC",tmp);
00059 //    //sprintf(t_humi,"%4.1f%%",humi);
00060 //    oled.TextBox((uint8_t *)t_tmp,40,30,46,15); //Increase textbox for more digits
00061 //    //oled.TextBox((uint8_t *)t_humi,40,45,46,15); //Increase textbox for more digits
00062 
00063     StartHaptic();
00064     redLed      = LED_ON;
00065     greenLed    = LED_ON;
00066     blueLed     = LED_OFF;
00067 }
00068 
00069 void StartHaptic(void)
00070 {
00071     hapticTimer.start(50);
00072     haptic = 1;
00073 }
00074 
00075 void StopHaptic(void const *n) {
00076     haptic = 0;
00077     hapticTimer.stop();
00078 }
00079 
00080 
00081 // main() runs in its own thread in the OS
00082 int main() {
00083     
00084     char text[20] = {0};  /* Text Buffer */ 
00085     
00086     char t_temp[10] = {0};
00087     char t_humi[10] = {0};
00088     
00089     float temp = 0.0f, humi = 0.0f;
00090     
00091     
00092     /* Get OLED Class Default Text Properties */
00093     oled_text_properties_t textProperties = {0};
00094     oled.GetTextProperties(&textProperties);    
00095 
00096     /* Turn on the backlight of the OLED Display */
00097     oled.DimScreenON();
00098     
00099     /* Fills the screen with solid black */         
00100     oled.FillScreen(COLOR_BLACK);
00101     
00102      /* Change font color to blue */ 
00103     textProperties.fontColor   = COLOR_BLUE;
00104     textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
00105     oled.SetTextProperties(&textProperties);
00106     
00107     /* Display Text at (x=0,y=0) */
00108     strcpy((char *) text,"HDC1000");
00109     oled.TextBox((uint8_t *)text,0,0,96,15); //Increase textbox for more digits
00110     
00111     textProperties.fontColor = COLOR_WHITE;
00112     oled.SetTextProperties(&textProperties);  
00113     
00114     /* Display Text at (x=7,y=30) */
00115     strcpy((char *) text,"TEMP :");
00116     oled.Label((uint8_t *)text,7,30);  
00117     
00118     /* Display Text at (x=7,y=45) */
00119     strcpy((char *) text,"HUMI :");
00120     oled.Label((uint8_t *)text,7,45);  
00121     
00122     /* Display Text at (x=7,y=0) */
00123     strcpy((char *) text,"F");
00124     oled.Label((uint8_t *)text,15,81);  
00125     
00126     strcpy((char *) text,"C");
00127     oled.Label((uint8_t *)text,75,81);  
00128     
00129     
00130     kw40z_device.attach_buttonLeft(&ButtonLeft);
00131     kw40z_device.attach_buttonRight(&ButtonRight);
00132     
00133     
00134     while (true) {
00135         
00136         hdc.get();    // Triger conversion
00137         pc.printf("Temp: %+4.1fC, Humid: %4.1f%%\r\n", hdc.temperature(), hdc.humidity());
00138         temp = hdc.temperature();
00139         humi = hdc.humidity();
00140         sprintf(t_temp,"%4.1fC",temp);
00141         sprintf(t_humi,"%4.1f%%",humi);
00142         oled.TextBox((uint8_t *)t_temp,40,30,46,15); //Increase textbox for more digits
00143         oled.TextBox((uint8_t *)t_humi,40,45,46,15); //Increase textbox for more digits
00144         wait(1.0);
00145         led1 = !led1;
00146     
00147     }
00148 }
00149