Charles Lindsay / Mbed OS MASTER

Dependencies:   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 "OLED_types.h"
00005 #include "OpenSans_Font.h"
00006 #include "string.h"
00007 #include "images.h"
00008 
00009 #define LED_ON      0
00010 #define LED_OFF     1
00011 
00012 void ReadCommand();
00013 void homescreen();
00014 
00015 void StartHaptic(void);
00016 void StopHaptic(void const *n);
00017 DigitalOut haptic(PTB9);
00018 RtosTimer hapticTimer(StopHaptic, osTimerOnce);
00019 
00020 Serial pc(USBTX, USBRX, 115200);
00021 //Serial BT(PTC17, PTC16, 115200);
00022 KW40Z kw40z_device(PTE24, PTE25);
00023 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15);
00024 
00025 BusIn MusicCommand(PTA10, PTB13, PTD2);
00026 InterruptIn que(PTD3);
00027 
00028 DigitalOut listeningLED(LED1, 1);
00029 
00030 DigitalOut volumeup(PTA4);
00031 DigitalOut nextsong(PTB7);
00032 DigitalOut pause_play(PTB6);
00033 DigitalOut lastsong(PTC17);
00034 DigitalOut volumedown(PTD8);
00035 
00036 char text[20];
00037 
00038 int y;
00039 
00040 void ReadCommand()
00041 {
00042     while(1)
00043     {
00044         listeningLED = 0;
00045         wait(.5);
00046         y = MusicCommand.read();
00047     
00048         if (y == 0)//volume up
00049         {
00050             volumeup.write(0);
00051             wait(0.1);
00052             volumeup.write(1);
00053             wait(0.1);
00054             volumeup.write(0);
00055             wait(0.1);
00056             volumeup.write(1);
00057             wait(0.1);
00058             volumeup.write(0);
00059             wait(0.1);
00060             volumeup.write(1);
00061             listeningLED = 1;
00062             break;
00063         }
00064         if (y == 1)//next song
00065         {
00066             nextsong.write(0);
00067             wait(0.1);
00068             nextsong.write(1);
00069             listeningLED = 1;
00070             break;
00071         }
00072         if (y == 2)//pause
00073         {
00074             pause_play.write(0);
00075             wait(0.1);
00076             pause_play.write(1);
00077             listeningLED = 1;
00078             break;
00079         }
00080         if (y == 3)//play
00081         {
00082             pause_play.write(0);
00083             wait(0.1);
00084             pause_play.write(1);
00085             listeningLED = 1;
00086             break;
00087         }
00088         if (y == 4)//restart
00089         {
00090             lastsong.write(0);
00091             wait(0.1);
00092             lastsong.write(1);
00093             listeningLED = 1;
00094             break;
00095         }
00096         if (y == 5)//volume down
00097         {
00098             volumedown.write(0);
00099             wait(0.1);
00100             volumedown.write(1);
00101             wait(0.1);
00102             volumedown.write(0);
00103             wait(0.1);
00104             volumedown.write(1);
00105             wait(0.1);
00106             volumedown.write(0);
00107             wait(0.1);
00108             volumedown.write(1);
00109             listeningLED = 1;
00110             break;
00111         }
00112         if (y == 6)//last song
00113         {
00114             lastsong.write(0);
00115             wait(0.1);
00116             lastsong.write(1);
00117             wait(0.1);
00118             lastsong.write(0);
00119             wait(0.1);
00120             lastsong.write(1);
00121             listeningLED = 1;
00122             break;
00123         }
00124     }
00125 }
00126 
00127 void homescreen()
00128 {
00129     oled.DimScreenON();
00130     const uint8_t *image1;
00131     image1  = NXP_whole_bmp;
00132     oled.FillScreen(COLOR_WHITE);
00133     oled.DrawImage(image1,0,0);        
00134     oled_text_properties_t textProperties = {0};
00135     oled.GetTextProperties(&textProperties); 
00136     textProperties.fontColor   = COLOR_WHITE;
00137     textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
00138     oled.SetTextProperties(&textProperties);
00139     strcpy((char *) text,"Welcome to");
00140     oled.Label((uint8_t *)text,15,30);
00141     strcpy((char *) text,"HexiHub");
00142     oled.Label((uint8_t *)text,20,45);   
00143     strcpy((char *) text,"Prev.");
00144     oled.Label((uint8_t *)text,0,0);    
00145     strcpy((char *) text,"Pause");
00146     oled.Label((uint8_t *)text,0,80);   
00147     strcpy((char *) text,"Play");
00148     oled.Label((uint8_t *)text,74,80);    
00149     strcpy((char *) text,"Next");
00150     oled.Label((uint8_t *)text,72,0);
00151 }
00152 
00153 void ButtonUp(void)
00154 {
00155     StartHaptic();
00156     nextsong.write(0);
00157     wait(0.1);
00158     nextsong.write(1);
00159 }
00160 
00161 void ButtonDown(void)
00162 {
00163     StartHaptic();
00164     lastsong.write(0);
00165     wait(0.1);
00166     lastsong.write(1);
00167 }
00168 
00169 void ButtonRight(void)
00170 {
00171     StartHaptic();
00172  
00173     pause_play.write(0);
00174             wait(0.1);
00175             pause_play.write(1);
00176     
00177 }
00178 
00179 void ButtonLeft(void)
00180 {
00181     StartHaptic();
00182     volumeup.write(0);
00183     wait(0.1);
00184     volumeup.write(1);
00185 }
00186 
00187 int main()
00188 {  
00189     homescreen();
00190 
00191     que.rise(&ReadCommand);
00192     que.fall(&ReadCommand);
00193     
00194     kw40z_device.attach_buttonUp(&ButtonUp);
00195     kw40z_device.attach_buttonDown(&ButtonDown);
00196     kw40z_device.attach_buttonLeft(&ButtonLeft);
00197     kw40z_device.attach_buttonRight(&ButtonRight);
00198     
00199    // while(1) 
00200     //{
00201       //  pc.putc(BT.getc());
00202    // }    
00203 }
00204 
00205 void StartHaptic(void)
00206 {
00207     hapticTimer.start(50);
00208     haptic = 1;
00209 }
00210 
00211 void StopHaptic(void const *n) {
00212     haptic = 0;
00213     hapticTimer.stop();
00214 }
00215 
00216 
00217 //SCREEN CHANGES
00218 
00219 /*
00220 oled.DimScreenON();
00221 const uint8_t *image1;
00222 image1  = NXP_whole_bmp;
00223 oled.FillScreen(COLOR_WHITE);
00224 oled.DrawImage(image1,0,0);        
00225 oled_text_properties_t textProperties = {0};
00226 oled.GetTextProperties(&textProperties); 
00227 textProperties.fontColor   = COLOR_WHITE;
00228 textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
00229 oled.SetTextProperties(&textProperties);
00230 strcpy((char *) text,"NEXT");
00231 oled.Label((uint8_t *)text,15,30);
00232 */
00233