
USED IMAGE2GLCD
Dependencies: BLE_API SharpLCD_LucidaFont mbed nRF51822
Fork of Renard_YO by
main.cpp@1:f0635f12df8c, 2014-07-04 (annotated)
- Committer:
- erigow01
- Date:
- Fri Jul 04 13:39:06 2014 +0000
- Revision:
- 1:f0635f12df8c
- Parent:
- 0:9bea6067730f
- Child:
- 2:e6ff3466221e
UI with icons...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
erigow01 | 0:9bea6067730f | 1 | #include "mbed.h" |
erigow01 | 0:9bea6067730f | 2 | #include "DebouncedInterrupt.h" |
erigow01 | 0:9bea6067730f | 3 | #include "EaEpaper.h" |
erigow01 | 0:9bea6067730f | 4 | #include "Arial28x28.h" |
erigow01 | 0:9bea6067730f | 5 | #include "Arial12x12.h" |
erigow01 | 1:f0635f12df8c | 6 | #include "icon.h" |
erigow01 | 0:9bea6067730f | 7 | |
erigow01 | 0:9bea6067730f | 8 | //I/O Initialisation |
erigow01 | 0:9bea6067730f | 9 | DigitalOut myled(LED1); |
erigow01 | 0:9bea6067730f | 10 | DigitalOut motor(P0_23); |
erigow01 | 0:9bea6067730f | 11 | #define BUTTON_INTERRUPT_DEBOUNCE_TIME_MS 150 |
erigow01 | 0:9bea6067730f | 12 | DebouncedInterrupt buttonOne (P0_16); |
erigow01 | 0:9bea6067730f | 13 | DebouncedInterrupt buttonTwo (P0_17); |
erigow01 | 0:9bea6067730f | 14 | |
erigow01 | 0:9bea6067730f | 15 | //Epaper Init |
erigow01 | 0:9bea6067730f | 16 | EaEpaper epaper(P0_0, //PWR_CONTROL |
erigow01 | 0:9bea6067730f | 17 | P0_1, //BORDER CONTROL |
erigow01 | 0:9bea6067730f | 18 | P0_2, //DISCHARGE |
erigow01 | 0:9bea6067730f | 19 | P0_3, //RESET |
erigow01 | 0:9bea6067730f | 20 | P0_4, //BUSY |
erigow01 | 0:9bea6067730f | 21 | P0_5, //SSEL |
erigow01 | 0:9bea6067730f | 22 | P0_6, //PWM |
erigow01 | 0:9bea6067730f | 23 | P0_12,P0_13,P0_15, //MOSI,MISO,SCLK |
erigow01 | 0:9bea6067730f | 24 | P0_22,P0_20);//SDA, SDL |
erigow01 | 0:9bea6067730f | 25 | |
erigow01 | 0:9bea6067730f | 26 | //Notification Data struct |
erigow01 | 0:9bea6067730f | 27 | #define NOTIFICATION_TEXT_MAX_LENGTH 20 |
erigow01 | 1:f0635f12df8c | 28 | #define NOTIFICATION_TYPE_ALARM 0x01 |
erigow01 | 1:f0635f12df8c | 29 | #define NOTIFICATION_TYPE_CALL 0x02 |
erigow01 | 1:f0635f12df8c | 30 | #define NOTIFICATION_TYPE_SMS 0x03 |
erigow01 | 1:f0635f12df8c | 31 | #define NOTIFICATION_TYPE_EMAIL 0x04 |
erigow01 | 1:f0635f12df8c | 32 | #define NOTIFICATION_TYPE_EVENT 0x05 |
erigow01 | 0:9bea6067730f | 33 | #define NOTIFICATION_STATE_DELETED 0x00 |
erigow01 | 0:9bea6067730f | 34 | #define NOTIFICATION_STATE_UNREAD 0x01 |
erigow01 | 0:9bea6067730f | 35 | #define NOTIFICATION_STATE_READ 0x02 |
erigow01 | 0:9bea6067730f | 36 | struct Notification{ |
erigow01 | 0:9bea6067730f | 37 | uint8_t type; |
erigow01 | 0:9bea6067730f | 38 | uint8_t state; |
erigow01 | 0:9bea6067730f | 39 | char primary_text[NOTIFICATION_TEXT_MAX_LENGTH]; |
erigow01 | 0:9bea6067730f | 40 | char secondary_text[NOTIFICATION_TEXT_MAX_LENGTH]; |
erigow01 | 0:9bea6067730f | 41 | }; |
erigow01 | 0:9bea6067730f | 42 | |
erigow01 | 0:9bea6067730f | 43 | //notification storage |
erigow01 | 0:9bea6067730f | 44 | #define MAX_NOTIFICATIONS 20 |
erigow01 | 0:9bea6067730f | 45 | Notification notifications[MAX_NOTIFICATIONS]; |
erigow01 | 0:9bea6067730f | 46 | uint8_t notification_count = 0; |
erigow01 | 0:9bea6067730f | 47 | int visible_notification_index = -1; |
erigow01 | 0:9bea6067730f | 48 | |
erigow01 | 0:9bea6067730f | 49 | //States |
erigow01 | 0:9bea6067730f | 50 | uint8_t needs_display_update = 0; |
erigow01 | 0:9bea6067730f | 51 | uint8_t has_unread = 0; |
erigow01 | 0:9bea6067730f | 52 | |
erigow01 | 0:9bea6067730f | 53 | //For LED |
erigow01 | 0:9bea6067730f | 54 | #define LED_BLINK_TIME_MS 500 |
erigow01 | 0:9bea6067730f | 55 | uint8_t led_on = 0; |
erigow01 | 0:9bea6067730f | 56 | Timer led_timer; |
erigow01 | 0:9bea6067730f | 57 | |
erigow01 | 0:9bea6067730f | 58 | //For Buzzer |
erigow01 | 0:9bea6067730f | 59 | #define BUZZ_TIME_MS 200 |
erigow01 | 0:9bea6067730f | 60 | #define MAX_BUZZ_COUNT 3 |
erigow01 | 0:9bea6067730f | 61 | uint8_t buzz_count = MAX_BUZZ_COUNT; |
erigow01 | 0:9bea6067730f | 62 | Timer buzz_timer; |
erigow01 | 0:9bea6067730f | 63 | |
erigow01 | 0:9bea6067730f | 64 | void setType(Notification* note, uint8_t type) { |
erigow01 | 0:9bea6067730f | 65 | note->type = type; |
erigow01 | 0:9bea6067730f | 66 | } |
erigow01 | 0:9bea6067730f | 67 | |
erigow01 | 0:9bea6067730f | 68 | uint8_t isCall(Notification note) { |
erigow01 | 0:9bea6067730f | 69 | return note.type == NOTIFICATION_TYPE_CALL; |
erigow01 | 0:9bea6067730f | 70 | } |
erigow01 | 0:9bea6067730f | 71 | |
erigow01 | 0:9bea6067730f | 72 | uint8_t isSMS(Notification note) { |
erigow01 | 0:9bea6067730f | 73 | return note.type == NOTIFICATION_TYPE_SMS; |
erigow01 | 0:9bea6067730f | 74 | } |
erigow01 | 0:9bea6067730f | 75 | |
erigow01 | 0:9bea6067730f | 76 | uint8_t isEmail(Notification note) { |
erigow01 | 0:9bea6067730f | 77 | return note.type == NOTIFICATION_TYPE_EMAIL; |
erigow01 | 0:9bea6067730f | 78 | } |
erigow01 | 0:9bea6067730f | 79 | |
erigow01 | 0:9bea6067730f | 80 | uint8_t isEvent(Notification note) { |
erigow01 | 0:9bea6067730f | 81 | return note.type == NOTIFICATION_TYPE_EVENT; |
erigow01 | 0:9bea6067730f | 82 | } |
erigow01 | 0:9bea6067730f | 83 | |
erigow01 | 0:9bea6067730f | 84 | void setState(Notification* note, uint8_t state) { |
erigow01 | 0:9bea6067730f | 85 | note->state = state; |
erigow01 | 0:9bea6067730f | 86 | } |
erigow01 | 0:9bea6067730f | 87 | |
erigow01 | 0:9bea6067730f | 88 | uint8_t isDeleted(Notification note) { |
erigow01 | 0:9bea6067730f | 89 | return note.state == NOTIFICATION_STATE_DELETED; |
erigow01 | 0:9bea6067730f | 90 | } |
erigow01 | 0:9bea6067730f | 91 | |
erigow01 | 0:9bea6067730f | 92 | uint8_t isUnread(Notification note) { |
erigow01 | 0:9bea6067730f | 93 | return note.state == NOTIFICATION_STATE_UNREAD; |
erigow01 | 0:9bea6067730f | 94 | } |
erigow01 | 0:9bea6067730f | 95 | |
erigow01 | 0:9bea6067730f | 96 | uint8_t isRead(Notification note) { |
erigow01 | 0:9bea6067730f | 97 | return note.state == NOTIFICATION_STATE_READ; |
erigow01 | 0:9bea6067730f | 98 | } |
erigow01 | 0:9bea6067730f | 99 | |
erigow01 | 1:f0635f12df8c | 100 | //Layout Coordinates |
erigow01 | 1:f0635f12df8c | 101 | #define TYPE_ICON_X 5 |
erigow01 | 1:f0635f12df8c | 102 | #define TYPE_ICON_Y 10 |
erigow01 | 1:f0635f12df8c | 103 | #define UNREAD_ICON_X 96 |
erigow01 | 1:f0635f12df8c | 104 | #define UNREAD_ICON_Y 14 |
erigow01 | 1:f0635f12df8c | 105 | #define PRIMARY_TEXT_X 5 |
erigow01 | 1:f0635f12df8c | 106 | #define PRIMARY_TEXT_Y 64 |
erigow01 | 1:f0635f12df8c | 107 | #define SECONDARY_TEXT_X 5 |
erigow01 | 1:f0635f12df8c | 108 | #define SECONDARY_TEXT_Y 82 |
erigow01 | 0:9bea6067730f | 109 | //Update Display to show current notification... |
erigow01 | 0:9bea6067730f | 110 | void doDisplayUpdate() { |
erigow01 | 0:9bea6067730f | 111 | epaper.cls(); |
erigow01 | 0:9bea6067730f | 112 | if(visible_notification_index >= 0) { |
erigow01 | 1:f0635f12df8c | 113 | //Write current notification... |
erigow01 | 1:f0635f12df8c | 114 | //Draw type icon... |
erigow01 | 1:f0635f12df8c | 115 | switch(notifications[visible_notification_index].type) { |
erigow01 | 1:f0635f12df8c | 116 | case NOTIFICATION_TYPE_ALARM: |
erigow01 | 1:f0635f12df8c | 117 | epaper.print_bm(bitmAlarm, TYPE_ICON_X, TYPE_ICON_Y); |
erigow01 | 1:f0635f12df8c | 118 | break; |
erigow01 | 1:f0635f12df8c | 119 | |
erigow01 | 1:f0635f12df8c | 120 | case NOTIFICATION_TYPE_CALL: |
erigow01 | 1:f0635f12df8c | 121 | epaper.print_bm(bitmCall, TYPE_ICON_X, TYPE_ICON_Y); |
erigow01 | 1:f0635f12df8c | 122 | break; |
erigow01 | 1:f0635f12df8c | 123 | |
erigow01 | 1:f0635f12df8c | 124 | case NOTIFICATION_TYPE_SMS: |
erigow01 | 1:f0635f12df8c | 125 | epaper.print_bm(bitmSMS, TYPE_ICON_X, TYPE_ICON_Y); |
erigow01 | 1:f0635f12df8c | 126 | break; |
erigow01 | 1:f0635f12df8c | 127 | |
erigow01 | 1:f0635f12df8c | 128 | case NOTIFICATION_TYPE_EMAIL: |
erigow01 | 1:f0635f12df8c | 129 | epaper.print_bm(bitmEmail, TYPE_ICON_X, TYPE_ICON_Y); |
erigow01 | 1:f0635f12df8c | 130 | break; |
erigow01 | 1:f0635f12df8c | 131 | |
erigow01 | 1:f0635f12df8c | 132 | case NOTIFICATION_TYPE_EVENT: |
erigow01 | 1:f0635f12df8c | 133 | epaper.print_bm(bitmCalendar, TYPE_ICON_X, TYPE_ICON_Y); |
erigow01 | 1:f0635f12df8c | 134 | break; |
erigow01 | 1:f0635f12df8c | 135 | } |
erigow01 | 1:f0635f12df8c | 136 | |
erigow01 | 1:f0635f12df8c | 137 | //Unread notification |
erigow01 | 1:f0635f12df8c | 138 | if(isUnread(notifications[visible_notification_index])){ |
erigow01 | 1:f0635f12df8c | 139 | epaper.print_bm(bitmUnread, UNREAD_ICON_X, UNREAD_ICON_Y); |
erigow01 | 1:f0635f12df8c | 140 | } |
erigow01 | 1:f0635f12df8c | 141 | //Text fields... |
erigow01 | 0:9bea6067730f | 142 | epaper.set_font((unsigned char*)Arial12x12); |
erigow01 | 1:f0635f12df8c | 143 | epaper.locate(PRIMARY_TEXT_X,PRIMARY_TEXT_Y); |
erigow01 | 0:9bea6067730f | 144 | epaper.printf(notifications[visible_notification_index].primary_text); |
erigow01 | 1:f0635f12df8c | 145 | epaper.locate(SECONDARY_TEXT_X,SECONDARY_TEXT_Y); |
erigow01 | 0:9bea6067730f | 146 | epaper.printf(notifications[visible_notification_index].secondary_text); |
erigow01 | 0:9bea6067730f | 147 | } else { |
erigow01 | 0:9bea6067730f | 148 | //no notifications... |
erigow01 | 0:9bea6067730f | 149 | //Write current notification... |
erigow01 | 0:9bea6067730f | 150 | epaper.set_font((unsigned char*)Arial12x12); |
erigow01 | 1:f0635f12df8c | 151 | epaper.locate(PRIMARY_TEXT_X,PRIMARY_TEXT_Y); |
erigow01 | 0:9bea6067730f | 152 | epaper.printf("No Notifications"); |
erigow01 | 0:9bea6067730f | 153 | } |
erigow01 | 0:9bea6067730f | 154 | epaper.write_disp(); |
erigow01 | 0:9bea6067730f | 155 | needs_display_update = 0; |
erigow01 | 0:9bea6067730f | 156 | } |
erigow01 | 0:9bea6067730f | 157 | |
erigow01 | 0:9bea6067730f | 158 | //Request a display update.. |
erigow01 | 0:9bea6067730f | 159 | void requestDisplayUpdate() { |
erigow01 | 0:9bea6067730f | 160 | needs_display_update = 1; |
erigow01 | 0:9bea6067730f | 161 | } |
erigow01 | 0:9bea6067730f | 162 | |
erigow01 | 0:9bea6067730f | 163 | //Starts buzz pattern... |
erigow01 | 0:9bea6067730f | 164 | void startBuzz() { |
erigow01 | 0:9bea6067730f | 165 | //Buzz |
erigow01 | 0:9bea6067730f | 166 | buzz_count = 0; |
erigow01 | 0:9bea6067730f | 167 | buzz_timer.reset(); |
erigow01 | 0:9bea6067730f | 168 | buzz_timer.start(); |
erigow01 | 0:9bea6067730f | 169 | } |
erigow01 | 0:9bea6067730f | 170 | |
erigow01 | 0:9bea6067730f | 171 | |
erigow01 | 0:9bea6067730f | 172 | //Add Notification... |
erigow01 | 0:9bea6067730f | 173 | int addNotification(Notification note) { |
erigow01 | 0:9bea6067730f | 174 | //Find insertion point... |
erigow01 | 0:9bea6067730f | 175 | uint8_t index = 0; |
erigow01 | 0:9bea6067730f | 176 | for(index = 0; index < MAX_NOTIFICATIONS; index++) { |
erigow01 | 0:9bea6067730f | 177 | if(isDeleted(notifications[index])) { |
erigow01 | 0:9bea6067730f | 178 | //Here... |
erigow01 | 0:9bea6067730f | 179 | break; |
erigow01 | 0:9bea6067730f | 180 | } |
erigow01 | 0:9bea6067730f | 181 | } |
erigow01 | 0:9bea6067730f | 182 | //If here, didn't find insertion point... wrap to beginning. |
erigow01 | 0:9bea6067730f | 183 | if(index >= MAX_NOTIFICATIONS) index = 0; |
erigow01 | 0:9bea6067730f | 184 | notifications[index] = note; |
erigow01 | 0:9bea6067730f | 185 | //Set buzzer |
erigow01 | 0:9bea6067730f | 186 | startBuzz(); |
erigow01 | 0:9bea6067730f | 187 | //Set unread |
erigow01 | 0:9bea6067730f | 188 | if(isUnread(note)) has_unread = 1; |
erigow01 | 0:9bea6067730f | 189 | return index; |
erigow01 | 0:9bea6067730f | 190 | } |
erigow01 | 0:9bea6067730f | 191 | |
erigow01 | 0:9bea6067730f | 192 | void deleteNotification(int index) { |
erigow01 | 0:9bea6067730f | 193 | setState(¬ifications[index], NOTIFICATION_STATE_DELETED); |
erigow01 | 0:9bea6067730f | 194 | //Shift array elements left... |
erigow01 | 0:9bea6067730f | 195 | int i = 0; |
erigow01 | 0:9bea6067730f | 196 | for (i = index + 1; i < MAX_NOTIFICATIONS; i++) { |
erigow01 | 0:9bea6067730f | 197 | notifications[i - 1] = notifications[i]; |
erigow01 | 0:9bea6067730f | 198 | } |
erigow01 | 0:9bea6067730f | 199 | } |
erigow01 | 0:9bea6067730f | 200 | |
erigow01 | 0:9bea6067730f | 201 | void checkUnread(){ |
erigow01 | 0:9bea6067730f | 202 | uint8_t i = 0; |
erigow01 | 0:9bea6067730f | 203 | led_timer.stop(); |
erigow01 | 0:9bea6067730f | 204 | has_unread = 0; |
erigow01 | 0:9bea6067730f | 205 | for(i = 0; i < MAX_NOTIFICATIONS; i++) { |
erigow01 | 0:9bea6067730f | 206 | if(isUnread(notifications[i])) { |
erigow01 | 0:9bea6067730f | 207 | has_unread = 1; |
erigow01 | 0:9bea6067730f | 208 | led_timer.reset(); |
erigow01 | 0:9bea6067730f | 209 | led_timer.start(); |
erigow01 | 0:9bea6067730f | 210 | break; |
erigow01 | 0:9bea6067730f | 211 | } |
erigow01 | 0:9bea6067730f | 212 | } |
erigow01 | 0:9bea6067730f | 213 | } |
erigow01 | 0:9bea6067730f | 214 | |
erigow01 | 0:9bea6067730f | 215 | //Button One Handler |
erigow01 | 0:9bea6067730f | 216 | void buttonOnePressed(){ |
erigow01 | 0:9bea6067730f | 217 | if(visible_notification_index >= 0) { |
erigow01 | 0:9bea6067730f | 218 | //Increment index, wrap to beginning if last. |
erigow01 | 0:9bea6067730f | 219 | visible_notification_index++; |
erigow01 | 0:9bea6067730f | 220 | if(visible_notification_index >= MAX_NOTIFICATIONS || isDeleted(notifications[visible_notification_index])) { |
erigow01 | 0:9bea6067730f | 221 | visible_notification_index = 0; |
erigow01 | 0:9bea6067730f | 222 | if(isDeleted(notifications[visible_notification_index])) { |
erigow01 | 0:9bea6067730f | 223 | //Still deleted... none... |
erigow01 | 0:9bea6067730f | 224 | visible_notification_index = -1; |
erigow01 | 0:9bea6067730f | 225 | } |
erigow01 | 0:9bea6067730f | 226 | } |
erigow01 | 0:9bea6067730f | 227 | //Trigger display update... |
erigow01 | 0:9bea6067730f | 228 | requestDisplayUpdate(); |
erigow01 | 0:9bea6067730f | 229 | } |
erigow01 | 0:9bea6067730f | 230 | } |
erigow01 | 0:9bea6067730f | 231 | |
erigow01 | 0:9bea6067730f | 232 | //Button Two handler |
erigow01 | 0:9bea6067730f | 233 | void buttonTwoPressed(){ |
erigow01 | 0:9bea6067730f | 234 | if(visible_notification_index >= 0) { |
erigow01 | 0:9bea6067730f | 235 | if(!isDeleted(notifications[visible_notification_index])) { |
erigow01 | 0:9bea6067730f | 236 | //Exists. |
erigow01 | 0:9bea6067730f | 237 | if(isUnread(notifications[visible_notification_index])) { |
erigow01 | 0:9bea6067730f | 238 | //Toggle to 'read' |
erigow01 | 0:9bea6067730f | 239 | setState(¬ifications[visible_notification_index], NOTIFICATION_STATE_READ); |
erigow01 | 0:9bea6067730f | 240 | checkUnread(); |
erigow01 | 0:9bea6067730f | 241 | } else if (isRead(notifications[visible_notification_index])) { |
erigow01 | 0:9bea6067730f | 242 | //Already 'read'... delete, this also shifts remaining notifications down... |
erigow01 | 0:9bea6067730f | 243 | deleteNotification(visible_notification_index); |
erigow01 | 0:9bea6067730f | 244 | //If current is deleted... |
erigow01 | 0:9bea6067730f | 245 | if(isDeleted(notifications[visible_notification_index])) { |
erigow01 | 0:9bea6067730f | 246 | //We're at end, so wrap... |
erigow01 | 0:9bea6067730f | 247 | visible_notification_index = 0; |
erigow01 | 0:9bea6067730f | 248 | if(isDeleted(notifications[visible_notification_index])) { |
erigow01 | 0:9bea6067730f | 249 | //Still deleted... so there are none... |
erigow01 | 0:9bea6067730f | 250 | visible_notification_index = -1; |
erigow01 | 0:9bea6067730f | 251 | } |
erigow01 | 0:9bea6067730f | 252 | } |
erigow01 | 0:9bea6067730f | 253 | //Otherwise, we've got one, so we should be ok... |
erigow01 | 0:9bea6067730f | 254 | } |
erigow01 | 0:9bea6067730f | 255 | |
erigow01 | 0:9bea6067730f | 256 | //Trigger display update... |
erigow01 | 0:9bea6067730f | 257 | requestDisplayUpdate(); |
erigow01 | 0:9bea6067730f | 258 | } |
erigow01 | 0:9bea6067730f | 259 | } |
erigow01 | 0:9bea6067730f | 260 | } |
erigow01 | 0:9bea6067730f | 261 | |
erigow01 | 0:9bea6067730f | 262 | //Initialise notification data... |
erigow01 | 0:9bea6067730f | 263 | void initNotificationData() { |
erigow01 | 0:9bea6067730f | 264 | //For debug purposes... |
erigow01 | 1:f0635f12df8c | 265 | |
erigow01 | 1:f0635f12df8c | 266 | notifications[0].type = NOTIFICATION_TYPE_ALARM; |
erigow01 | 0:9bea6067730f | 267 | notifications[0].state = NOTIFICATION_STATE_UNREAD; |
erigow01 | 1:f0635f12df8c | 268 | strcpy(notifications[0].primary_text,"Wake Up"); |
erigow01 | 1:f0635f12df8c | 269 | strcpy(notifications[0].secondary_text, "07:00"); |
erigow01 | 1:f0635f12df8c | 270 | |
erigow01 | 1:f0635f12df8c | 271 | notifications[1].type = NOTIFICATION_TYPE_CALL; |
erigow01 | 1:f0635f12df8c | 272 | notifications[1].state = NOTIFICATION_STATE_UNREAD; |
erigow01 | 1:f0635f12df8c | 273 | strcpy(notifications[1].primary_text,"Eric Gowland"); |
erigow01 | 1:f0635f12df8c | 274 | strcpy(notifications[1].secondary_text, "07770909177"); |
erigow01 | 0:9bea6067730f | 275 | |
erigow01 | 1:f0635f12df8c | 276 | notifications[2].type = NOTIFICATION_TYPE_SMS; |
erigow01 | 1:f0635f12df8c | 277 | notifications[2].state = NOTIFICATION_STATE_UNREAD; |
erigow01 | 1:f0635f12df8c | 278 | strcpy(notifications[2].primary_text,"Hi, txt me..."); |
erigow01 | 1:f0635f12df8c | 279 | strcpy(notifications[2].secondary_text, "07770909177"); |
erigow01 | 1:f0635f12df8c | 280 | |
erigow01 | 1:f0635f12df8c | 281 | notifications[3].type = NOTIFICATION_TYPE_EMAIL; |
erigow01 | 1:f0635f12df8c | 282 | notifications[3].state = NOTIFICATION_STATE_UNREAD; |
erigow01 | 1:f0635f12df8c | 283 | strcpy(notifications[3].primary_text, "Dear Sir I have $US"); |
erigow01 | 1:f0635f12df8c | 284 | strcpy(notifications[3].secondary_text, "not@scam.net"); |
erigow01 | 1:f0635f12df8c | 285 | |
erigow01 | 1:f0635f12df8c | 286 | notifications[4].type = NOTIFICATION_TYPE_EVENT; |
erigow01 | 1:f0635f12df8c | 287 | notifications[4].state = NOTIFICATION_STATE_UNREAD; |
erigow01 | 1:f0635f12df8c | 288 | strcpy(notifications[4].primary_text,"Review Meeting"); |
erigow01 | 1:f0635f12df8c | 289 | strcpy(notifications[4].secondary_text, "10:00 - 10:30"); |
erigow01 | 0:9bea6067730f | 290 | |
erigow01 | 0:9bea6067730f | 291 | //Set location, etc. |
erigow01 | 0:9bea6067730f | 292 | visible_notification_index = 0; |
erigow01 | 0:9bea6067730f | 293 | checkUnread(); |
erigow01 | 0:9bea6067730f | 294 | requestDisplayUpdate(); |
erigow01 | 0:9bea6067730f | 295 | startBuzz(); |
erigow01 | 0:9bea6067730f | 296 | } |
erigow01 | 0:9bea6067730f | 297 | |
erigow01 | 0:9bea6067730f | 298 | //Main Program Function |
erigow01 | 0:9bea6067730f | 299 | int main() { |
erigow01 | 0:9bea6067730f | 300 | //Init Data |
erigow01 | 0:9bea6067730f | 301 | initNotificationData(); |
erigow01 | 0:9bea6067730f | 302 | //Attach interrupt handlers... |
erigow01 | 0:9bea6067730f | 303 | buttonOne.attach(buttonOnePressed, IRQ_RISE, BUTTON_INTERRUPT_DEBOUNCE_TIME_MS); |
erigow01 | 0:9bea6067730f | 304 | buttonTwo.attach(buttonTwoPressed, IRQ_RISE, BUTTON_INTERRUPT_DEBOUNCE_TIME_MS); |
erigow01 | 0:9bea6067730f | 305 | //Request display update... |
erigow01 | 0:9bea6067730f | 306 | requestDisplayUpdate(); |
erigow01 | 0:9bea6067730f | 307 | while(1) { |
erigow01 | 0:9bea6067730f | 308 | if(needs_display_update){ |
erigow01 | 0:9bea6067730f | 309 | doDisplayUpdate(); |
erigow01 | 0:9bea6067730f | 310 | } else { |
erigow01 | 0:9bea6067730f | 311 | //If state hasn't changed, just action timers... |
erigow01 | 0:9bea6067730f | 312 | //Unread LED |
erigow01 | 0:9bea6067730f | 313 | if(has_unread) { |
erigow01 | 0:9bea6067730f | 314 | //LED flashing... |
erigow01 | 0:9bea6067730f | 315 | if(led_timer.read_ms() > LED_BLINK_TIME_MS) { |
erigow01 | 0:9bea6067730f | 316 | myled = !myled; |
erigow01 | 0:9bea6067730f | 317 | led_timer.reset(); |
erigow01 | 0:9bea6067730f | 318 | } |
erigow01 | 0:9bea6067730f | 319 | } else { |
erigow01 | 0:9bea6067730f | 320 | myled = 0; |
erigow01 | 0:9bea6067730f | 321 | led_timer.stop(); |
erigow01 | 0:9bea6067730f | 322 | } |
erigow01 | 0:9bea6067730f | 323 | |
erigow01 | 0:9bea6067730f | 324 | //Buzz |
erigow01 | 0:9bea6067730f | 325 | if(buzz_count < MAX_BUZZ_COUNT) { |
erigow01 | 0:9bea6067730f | 326 | //Buzzing... |
erigow01 | 0:9bea6067730f | 327 | if(buzz_timer.read_ms() > BUZZ_TIME_MS) { |
erigow01 | 0:9bea6067730f | 328 | motor = !motor; |
erigow01 | 0:9bea6067730f | 329 | if(!motor) buzz_count++; |
erigow01 | 0:9bea6067730f | 330 | buzz_timer.reset(); |
erigow01 | 0:9bea6067730f | 331 | } |
erigow01 | 0:9bea6067730f | 332 | } else { |
erigow01 | 0:9bea6067730f | 333 | motor = 0; |
erigow01 | 0:9bea6067730f | 334 | buzz_timer.stop(); |
erigow01 | 0:9bea6067730f | 335 | } |
erigow01 | 0:9bea6067730f | 336 | } |
erigow01 | 0:9bea6067730f | 337 | } |
erigow01 | 0:9bea6067730f | 338 | } |