Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Hexi_OLED_SSD1351
main.cpp
00001 #include "mbed.h" 00002 #include "Hexi_KW40Z.h" 00003 #include "Hexi_OLED_SSD1351.h" 00004 #include "OLED_types.h" 00005 #include "OpenSans_Font.h" 00006 #include "string.h" 00007 #include <stdio.h> 00008 #include <stdlib.h> 00009 #include <string.h> 00010 00011 00012 #define LED_ON 0 00013 #define LED_OFF 1 00014 #define MPL3115A2_I2C_ADDRESS (0x60<<1) 00015 00016 void StartHaptic(void); 00017 void StopHaptic(void const *n); 00018 00019 00020 00021 DigitalOut redLed(LED1,1); 00022 DigitalOut greenLed(LED2,1); 00023 DigitalOut WHITELed(LED3,1); 00024 DigitalOut haptic(PTB9); 00025 DigitalOut sensorPowerEn(PTB12); 00026 DigitalOut powerEN (PTB12); 00027 DigitalOut led1(LED_GREEN); // RGB LED 00028 Serial pc(USBTX,USBRX); // Serial interface 00029 00030 char text[20]; // Text Buffer for dynamic value displayed 00031 char text1[20]; // Text Buffer for dynamic value displayed 00032 char text2[20]; // Text Buffer for dynamic value displayed 00033 char text3[20]; // Text Buffer for dynamic value displayed 00034 char text4[20]; // Text Buffer for dynamic value displayed 00035 00036 /* Define timer for haptic feedback */ 00037 RtosTimer hapticTimer(StopHaptic, osTimerOnce); 00038 00039 /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */ 00040 KW40Z kw40z_device(PTE24, PTE25); 00041 00042 /* Instantiate the SSD1351 OLED Driver */ 00043 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); /* (MOSI,SCLK,POWER,CS,RST,DC) */ 00044 //void page_1(void); 00045 00046 00047 00048 00049 /****************************Call Back Functions*******************************/ 00050 00051 00052 void ButtonRight(void) 00053 { 00054 StartHaptic(); 00055 pc.printf("opoooooooo"); 00056 00057 } 00058 00059 void ButtonLeft(void) 00060 { 00061 StartHaptic(); 00062 00063 } 00064 00065 void ButtonDown(void) 00066 { 00067 00068 StartHaptic(); 00069 pc.printf("down"); 00070 00071 } 00072 00073 void ButtonUp(void) 00074 { 00075 StartHaptic(); 00076 pc.printf("up once"); 00077 00078 } 00079 00080 void ButtonSlide(void) 00081 { 00082 StartHaptic(); 00083 } 00084 void PassKey(void) 00085 { 00086 StartHaptic(); 00087 strcpy((char *) text,"PAIR CODE"); 00088 oled.TextBox((uint8_t *)text,0,25,95,18); 00089 00090 /* Display Bond Pass Key in a 95px by 18px textbox at x=0,y=40 */ 00091 sprintf(text,"%d", kw40z_device.GetPassKey()); 00092 oled.TextBox((uint8_t *)text,0,40,95,18); 00093 } 00094 00095 /***********************End of Call Back Functions*****************************/ 00096 00097 00098 00099 00100 00101 /********************************Main******************************************/ 00102 00103 00104 int pages[5]; 00105 00106 int row_count = 0; 00107 00108 void pag_1(){ 00109 00110 00111 pc.printf("page1\n"); 00112 } 00113 void pag_2(){ 00114 00115 00116 pc.printf("page2\n"); 00117 } 00118 00119 void pag_3(){ 00120 00121 00122 pc.printf("page3\n"); 00123 } 00124 00125 void pag_4(){ 00126 00127 00128 pc.printf("page4\n"); 00129 } 00130 void pag_5(){ 00131 00132 00133 pc.printf("page5\n"); 00134 } 00135 void switch_page (int count) 00136 { 00137 //This function checks 00138 //the int value of the count to determine what page to load to the screen 00139 switch (count) { 00140 //checks and calls appropriate function 00141 case 0: 00142 // pull first page function 00143 pag_1(); 00144 break; 00145 00146 case 1: 00147 // pull 2nd page function 00148 pag_2(); 00149 break; 00150 00151 case 2: 00152 // pull 3rd page function 00153 pag_3(); 00154 break; 00155 00156 case 3: 00157 // pull 4th page function 00158 pag_4(); 00159 break; 00160 00161 00162 case 4: 00163 // pull 5th page function 00164 pag_5(); 00165 break; 00166 00167 default: 00168 // Do nothing 00169 break; 00170 00171 } 00172 00173 } 00174 00175 void ButtonTouch() 00176 { 00177 StartHaptic(); 00178 00179 // typedef int(*pageFunction)(); 00180 // pageFunction page_1 = pag_1; 00181 00182 00183 switch_page(row_count); 00184 if (row_count > 4) row_count = 4; 00185 00186 row_count++; 00187 } 00188 00189 00190 void ButtonTouch2() 00191 { 00192 StartHaptic(); 00193 00194 // typedef int(*pageFunction)(); 00195 // pageFunction page_1 = pag_1; 00196 00197 00198 00199 if (row_count > 4) row_count = 4; 00200 row_count--; 00201 switch_page(row_count); 00202 } 00203 00204 int main() 00205 { 00206 00207 00208 00209 //kw40z_device.ToggleAdvertisementMode(); 00210 /* Register callbacks to application functions */ 00211 kw40z_device.attach_buttonLeft(&ButtonLeft); 00212 kw40z_device.attach_buttonRight(&ButtonRight); 00213 kw40z_device.attach_passkey(&PassKey); 00214 kw40z_device.attach_buttonDown(&ButtonDown); 00215 kw40z_device.attach_buttonUp(&ButtonUp); 00216 kw40z_device.PageIndex(&ButtonTouch); 00217 kw40z_device.PageIndex2(&ButtonTouch2); 00218 00219 00220 /* Turn on the backlight of the OLED Display */ 00221 oled.DimScreenON(); 00222 /* Fills the screen with solid black */ 00223 oled.FillScreen(COLOR_BLACK); 00224 /* Get OLED Class Default Text Properties */ 00225 oled_text_properties_t textProperties = {0}; 00226 oled.GetTextProperties(&textProperties); 00227 oled.FillScreen(COLOR_BLACK); 00228 00229 while (true) { 00230 00231 Thread::wait(0.1); 00232 WHITELed = !kw40z_device.GetAdvertisementMode(); /*Indicate BLE Advertisment Mode*/ 00233 Thread::wait(50); 00234 } 00235 } 00236 00237 /******************************End of Main*************************************/ 00238 00239 00240 void StartHaptic(void) 00241 { 00242 hapticTimer.start(50); 00243 haptic = 1; 00244 } 00245 00246 void StopHaptic(void const *n) 00247 { 00248 haptic = 0; 00249 hapticTimer.stop(); 00250 } 00251 00252 00253
Generated on Tue Jul 12 2022 18:19:43 by
1.7.2