HexiHub code
Dependencies: Hexi_KW40Z Hexi_OLED_SSD1351
main.cpp@0:efcad8f28b0f, 2018-02-16 (annotated)
- Committer:
- cwl35
- Date:
- Fri Feb 16 22:14:24 2018 +0000
- Revision:
- 0:efcad8f28b0f
Master HexiHub code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cwl35 | 0:efcad8f28b0f | 1 | #include "mbed.h" |
cwl35 | 0:efcad8f28b0f | 2 | #include "Hexi_KW40Z.h" |
cwl35 | 0:efcad8f28b0f | 3 | #include "Hexi_OLED_SSD1351.h" |
cwl35 | 0:efcad8f28b0f | 4 | #include "OLED_types.h" |
cwl35 | 0:efcad8f28b0f | 5 | #include "OpenSans_Font.h" |
cwl35 | 0:efcad8f28b0f | 6 | #include "string.h" |
cwl35 | 0:efcad8f28b0f | 7 | #include "images.h" |
cwl35 | 0:efcad8f28b0f | 8 | |
cwl35 | 0:efcad8f28b0f | 9 | #define LED_ON 0 |
cwl35 | 0:efcad8f28b0f | 10 | #define LED_OFF 1 |
cwl35 | 0:efcad8f28b0f | 11 | |
cwl35 | 0:efcad8f28b0f | 12 | void ReadCommand(); |
cwl35 | 0:efcad8f28b0f | 13 | void homescreen(); |
cwl35 | 0:efcad8f28b0f | 14 | |
cwl35 | 0:efcad8f28b0f | 15 | void StartHaptic(void); |
cwl35 | 0:efcad8f28b0f | 16 | void StopHaptic(void const *n); |
cwl35 | 0:efcad8f28b0f | 17 | DigitalOut haptic(PTB9); |
cwl35 | 0:efcad8f28b0f | 18 | RtosTimer hapticTimer(StopHaptic, osTimerOnce); |
cwl35 | 0:efcad8f28b0f | 19 | |
cwl35 | 0:efcad8f28b0f | 20 | Serial pc(USBTX, USBRX, 115200); |
cwl35 | 0:efcad8f28b0f | 21 | //Serial BT(PTC17, PTC16, 115200); |
cwl35 | 0:efcad8f28b0f | 22 | KW40Z kw40z_device(PTE24, PTE25); |
cwl35 | 0:efcad8f28b0f | 23 | SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); |
cwl35 | 0:efcad8f28b0f | 24 | |
cwl35 | 0:efcad8f28b0f | 25 | BusIn MusicCommand(PTA10, PTB13, PTD2); |
cwl35 | 0:efcad8f28b0f | 26 | InterruptIn que(PTD3); |
cwl35 | 0:efcad8f28b0f | 27 | |
cwl35 | 0:efcad8f28b0f | 28 | DigitalOut listeningLED(LED1, 1); |
cwl35 | 0:efcad8f28b0f | 29 | |
cwl35 | 0:efcad8f28b0f | 30 | DigitalOut volumeup(PTA4); |
cwl35 | 0:efcad8f28b0f | 31 | DigitalOut nextsong(PTB7); |
cwl35 | 0:efcad8f28b0f | 32 | DigitalOut pause_play(PTB6); |
cwl35 | 0:efcad8f28b0f | 33 | DigitalOut lastsong(PTC17); |
cwl35 | 0:efcad8f28b0f | 34 | DigitalOut volumedown(PTD8); |
cwl35 | 0:efcad8f28b0f | 35 | |
cwl35 | 0:efcad8f28b0f | 36 | char text[20]; |
cwl35 | 0:efcad8f28b0f | 37 | |
cwl35 | 0:efcad8f28b0f | 38 | int y; |
cwl35 | 0:efcad8f28b0f | 39 | |
cwl35 | 0:efcad8f28b0f | 40 | void ReadCommand() |
cwl35 | 0:efcad8f28b0f | 41 | { |
cwl35 | 0:efcad8f28b0f | 42 | while(1) |
cwl35 | 0:efcad8f28b0f | 43 | { |
cwl35 | 0:efcad8f28b0f | 44 | listeningLED = 0; |
cwl35 | 0:efcad8f28b0f | 45 | wait(.5); |
cwl35 | 0:efcad8f28b0f | 46 | y = MusicCommand.read(); |
cwl35 | 0:efcad8f28b0f | 47 | |
cwl35 | 0:efcad8f28b0f | 48 | if (y == 0)//volume up |
cwl35 | 0:efcad8f28b0f | 49 | { |
cwl35 | 0:efcad8f28b0f | 50 | volumeup.write(0); |
cwl35 | 0:efcad8f28b0f | 51 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 52 | volumeup.write(1); |
cwl35 | 0:efcad8f28b0f | 53 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 54 | volumeup.write(0); |
cwl35 | 0:efcad8f28b0f | 55 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 56 | volumeup.write(1); |
cwl35 | 0:efcad8f28b0f | 57 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 58 | volumeup.write(0); |
cwl35 | 0:efcad8f28b0f | 59 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 60 | volumeup.write(1); |
cwl35 | 0:efcad8f28b0f | 61 | listeningLED = 1; |
cwl35 | 0:efcad8f28b0f | 62 | break; |
cwl35 | 0:efcad8f28b0f | 63 | } |
cwl35 | 0:efcad8f28b0f | 64 | if (y == 1)//next song |
cwl35 | 0:efcad8f28b0f | 65 | { |
cwl35 | 0:efcad8f28b0f | 66 | nextsong.write(0); |
cwl35 | 0:efcad8f28b0f | 67 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 68 | nextsong.write(1); |
cwl35 | 0:efcad8f28b0f | 69 | listeningLED = 1; |
cwl35 | 0:efcad8f28b0f | 70 | break; |
cwl35 | 0:efcad8f28b0f | 71 | } |
cwl35 | 0:efcad8f28b0f | 72 | if (y == 2)//pause |
cwl35 | 0:efcad8f28b0f | 73 | { |
cwl35 | 0:efcad8f28b0f | 74 | pause_play.write(0); |
cwl35 | 0:efcad8f28b0f | 75 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 76 | pause_play.write(1); |
cwl35 | 0:efcad8f28b0f | 77 | listeningLED = 1; |
cwl35 | 0:efcad8f28b0f | 78 | break; |
cwl35 | 0:efcad8f28b0f | 79 | } |
cwl35 | 0:efcad8f28b0f | 80 | if (y == 3)//play |
cwl35 | 0:efcad8f28b0f | 81 | { |
cwl35 | 0:efcad8f28b0f | 82 | pause_play.write(0); |
cwl35 | 0:efcad8f28b0f | 83 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 84 | pause_play.write(1); |
cwl35 | 0:efcad8f28b0f | 85 | listeningLED = 1; |
cwl35 | 0:efcad8f28b0f | 86 | break; |
cwl35 | 0:efcad8f28b0f | 87 | } |
cwl35 | 0:efcad8f28b0f | 88 | if (y == 4)//restart |
cwl35 | 0:efcad8f28b0f | 89 | { |
cwl35 | 0:efcad8f28b0f | 90 | lastsong.write(0); |
cwl35 | 0:efcad8f28b0f | 91 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 92 | lastsong.write(1); |
cwl35 | 0:efcad8f28b0f | 93 | listeningLED = 1; |
cwl35 | 0:efcad8f28b0f | 94 | break; |
cwl35 | 0:efcad8f28b0f | 95 | } |
cwl35 | 0:efcad8f28b0f | 96 | if (y == 5)//volume down |
cwl35 | 0:efcad8f28b0f | 97 | { |
cwl35 | 0:efcad8f28b0f | 98 | volumedown.write(0); |
cwl35 | 0:efcad8f28b0f | 99 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 100 | volumedown.write(1); |
cwl35 | 0:efcad8f28b0f | 101 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 102 | volumedown.write(0); |
cwl35 | 0:efcad8f28b0f | 103 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 104 | volumedown.write(1); |
cwl35 | 0:efcad8f28b0f | 105 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 106 | volumedown.write(0); |
cwl35 | 0:efcad8f28b0f | 107 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 108 | volumedown.write(1); |
cwl35 | 0:efcad8f28b0f | 109 | listeningLED = 1; |
cwl35 | 0:efcad8f28b0f | 110 | break; |
cwl35 | 0:efcad8f28b0f | 111 | } |
cwl35 | 0:efcad8f28b0f | 112 | if (y == 6)//last song |
cwl35 | 0:efcad8f28b0f | 113 | { |
cwl35 | 0:efcad8f28b0f | 114 | lastsong.write(0); |
cwl35 | 0:efcad8f28b0f | 115 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 116 | lastsong.write(1); |
cwl35 | 0:efcad8f28b0f | 117 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 118 | lastsong.write(0); |
cwl35 | 0:efcad8f28b0f | 119 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 120 | lastsong.write(1); |
cwl35 | 0:efcad8f28b0f | 121 | listeningLED = 1; |
cwl35 | 0:efcad8f28b0f | 122 | break; |
cwl35 | 0:efcad8f28b0f | 123 | } |
cwl35 | 0:efcad8f28b0f | 124 | } |
cwl35 | 0:efcad8f28b0f | 125 | } |
cwl35 | 0:efcad8f28b0f | 126 | |
cwl35 | 0:efcad8f28b0f | 127 | void homescreen() |
cwl35 | 0:efcad8f28b0f | 128 | { |
cwl35 | 0:efcad8f28b0f | 129 | oled.DimScreenON(); |
cwl35 | 0:efcad8f28b0f | 130 | const uint8_t *image1; |
cwl35 | 0:efcad8f28b0f | 131 | image1 = NXP_whole_bmp; |
cwl35 | 0:efcad8f28b0f | 132 | oled.FillScreen(COLOR_WHITE); |
cwl35 | 0:efcad8f28b0f | 133 | oled.DrawImage(image1,0,0); |
cwl35 | 0:efcad8f28b0f | 134 | oled_text_properties_t textProperties = {0}; |
cwl35 | 0:efcad8f28b0f | 135 | oled.GetTextProperties(&textProperties); |
cwl35 | 0:efcad8f28b0f | 136 | textProperties.fontColor = COLOR_WHITE; |
cwl35 | 0:efcad8f28b0f | 137 | textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; |
cwl35 | 0:efcad8f28b0f | 138 | oled.SetTextProperties(&textProperties); |
cwl35 | 0:efcad8f28b0f | 139 | strcpy((char *) text,"Welcome to"); |
cwl35 | 0:efcad8f28b0f | 140 | oled.Label((uint8_t *)text,15,30); |
cwl35 | 0:efcad8f28b0f | 141 | strcpy((char *) text,"HexiHub"); |
cwl35 | 0:efcad8f28b0f | 142 | oled.Label((uint8_t *)text,20,45); |
cwl35 | 0:efcad8f28b0f | 143 | strcpy((char *) text,"Prev."); |
cwl35 | 0:efcad8f28b0f | 144 | oled.Label((uint8_t *)text,0,0); |
cwl35 | 0:efcad8f28b0f | 145 | strcpy((char *) text,"Pause"); |
cwl35 | 0:efcad8f28b0f | 146 | oled.Label((uint8_t *)text,0,80); |
cwl35 | 0:efcad8f28b0f | 147 | strcpy((char *) text,"Play"); |
cwl35 | 0:efcad8f28b0f | 148 | oled.Label((uint8_t *)text,74,80); |
cwl35 | 0:efcad8f28b0f | 149 | strcpy((char *) text,"Next"); |
cwl35 | 0:efcad8f28b0f | 150 | oled.Label((uint8_t *)text,72,0); |
cwl35 | 0:efcad8f28b0f | 151 | } |
cwl35 | 0:efcad8f28b0f | 152 | |
cwl35 | 0:efcad8f28b0f | 153 | void ButtonUp(void) |
cwl35 | 0:efcad8f28b0f | 154 | { |
cwl35 | 0:efcad8f28b0f | 155 | StartHaptic(); |
cwl35 | 0:efcad8f28b0f | 156 | nextsong.write(0); |
cwl35 | 0:efcad8f28b0f | 157 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 158 | nextsong.write(1); |
cwl35 | 0:efcad8f28b0f | 159 | } |
cwl35 | 0:efcad8f28b0f | 160 | |
cwl35 | 0:efcad8f28b0f | 161 | void ButtonDown(void) |
cwl35 | 0:efcad8f28b0f | 162 | { |
cwl35 | 0:efcad8f28b0f | 163 | StartHaptic(); |
cwl35 | 0:efcad8f28b0f | 164 | lastsong.write(0); |
cwl35 | 0:efcad8f28b0f | 165 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 166 | lastsong.write(1); |
cwl35 | 0:efcad8f28b0f | 167 | } |
cwl35 | 0:efcad8f28b0f | 168 | |
cwl35 | 0:efcad8f28b0f | 169 | void ButtonRight(void) |
cwl35 | 0:efcad8f28b0f | 170 | { |
cwl35 | 0:efcad8f28b0f | 171 | StartHaptic(); |
cwl35 | 0:efcad8f28b0f | 172 | |
cwl35 | 0:efcad8f28b0f | 173 | pause_play.write(0); |
cwl35 | 0:efcad8f28b0f | 174 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 175 | pause_play.write(1); |
cwl35 | 0:efcad8f28b0f | 176 | |
cwl35 | 0:efcad8f28b0f | 177 | } |
cwl35 | 0:efcad8f28b0f | 178 | |
cwl35 | 0:efcad8f28b0f | 179 | void ButtonLeft(void) |
cwl35 | 0:efcad8f28b0f | 180 | { |
cwl35 | 0:efcad8f28b0f | 181 | StartHaptic(); |
cwl35 | 0:efcad8f28b0f | 182 | volumeup.write(0); |
cwl35 | 0:efcad8f28b0f | 183 | wait(0.1); |
cwl35 | 0:efcad8f28b0f | 184 | volumeup.write(1); |
cwl35 | 0:efcad8f28b0f | 185 | } |
cwl35 | 0:efcad8f28b0f | 186 | |
cwl35 | 0:efcad8f28b0f | 187 | int main() |
cwl35 | 0:efcad8f28b0f | 188 | { |
cwl35 | 0:efcad8f28b0f | 189 | homescreen(); |
cwl35 | 0:efcad8f28b0f | 190 | |
cwl35 | 0:efcad8f28b0f | 191 | que.rise(&ReadCommand); |
cwl35 | 0:efcad8f28b0f | 192 | que.fall(&ReadCommand); |
cwl35 | 0:efcad8f28b0f | 193 | |
cwl35 | 0:efcad8f28b0f | 194 | kw40z_device.attach_buttonUp(&ButtonUp); |
cwl35 | 0:efcad8f28b0f | 195 | kw40z_device.attach_buttonDown(&ButtonDown); |
cwl35 | 0:efcad8f28b0f | 196 | kw40z_device.attach_buttonLeft(&ButtonLeft); |
cwl35 | 0:efcad8f28b0f | 197 | kw40z_device.attach_buttonRight(&ButtonRight); |
cwl35 | 0:efcad8f28b0f | 198 | |
cwl35 | 0:efcad8f28b0f | 199 | // while(1) |
cwl35 | 0:efcad8f28b0f | 200 | //{ |
cwl35 | 0:efcad8f28b0f | 201 | // pc.putc(BT.getc()); |
cwl35 | 0:efcad8f28b0f | 202 | // } |
cwl35 | 0:efcad8f28b0f | 203 | } |
cwl35 | 0:efcad8f28b0f | 204 | |
cwl35 | 0:efcad8f28b0f | 205 | void StartHaptic(void) |
cwl35 | 0:efcad8f28b0f | 206 | { |
cwl35 | 0:efcad8f28b0f | 207 | hapticTimer.start(50); |
cwl35 | 0:efcad8f28b0f | 208 | haptic = 1; |
cwl35 | 0:efcad8f28b0f | 209 | } |
cwl35 | 0:efcad8f28b0f | 210 | |
cwl35 | 0:efcad8f28b0f | 211 | void StopHaptic(void const *n) { |
cwl35 | 0:efcad8f28b0f | 212 | haptic = 0; |
cwl35 | 0:efcad8f28b0f | 213 | hapticTimer.stop(); |
cwl35 | 0:efcad8f28b0f | 214 | } |
cwl35 | 0:efcad8f28b0f | 215 | |
cwl35 | 0:efcad8f28b0f | 216 | |
cwl35 | 0:efcad8f28b0f | 217 | //SCREEN CHANGES |
cwl35 | 0:efcad8f28b0f | 218 | |
cwl35 | 0:efcad8f28b0f | 219 | /* |
cwl35 | 0:efcad8f28b0f | 220 | oled.DimScreenON(); |
cwl35 | 0:efcad8f28b0f | 221 | const uint8_t *image1; |
cwl35 | 0:efcad8f28b0f | 222 | image1 = NXP_whole_bmp; |
cwl35 | 0:efcad8f28b0f | 223 | oled.FillScreen(COLOR_WHITE); |
cwl35 | 0:efcad8f28b0f | 224 | oled.DrawImage(image1,0,0); |
cwl35 | 0:efcad8f28b0f | 225 | oled_text_properties_t textProperties = {0}; |
cwl35 | 0:efcad8f28b0f | 226 | oled.GetTextProperties(&textProperties); |
cwl35 | 0:efcad8f28b0f | 227 | textProperties.fontColor = COLOR_WHITE; |
cwl35 | 0:efcad8f28b0f | 228 | textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; |
cwl35 | 0:efcad8f28b0f | 229 | oled.SetTextProperties(&textProperties); |
cwl35 | 0:efcad8f28b0f | 230 | strcpy((char *) text,"NEXT"); |
cwl35 | 0:efcad8f28b0f | 231 | oled.Label((uint8_t *)text,15,30); |
cwl35 | 0:efcad8f28b0f | 232 | */ |
cwl35 | 0:efcad8f28b0f | 233 |