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