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