A simple reminder program that can store up to 5 reminders, and has the ability to navigate between different pages through different functions.
Dependencies: Hexi_KW40Z Hexi_OLED_SSD1351 PWM_Tone_Library
6Other_Functions.h@0:63db1c7ee975, 2017-04-19 (annotated)
- Committer:
- fusop
- Date:
- Wed Apr 19 14:57:15 2017 +0000
- Revision:
- 0:63db1c7ee975
Final Version of the Reminder Program;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fusop | 0:63db1c7ee975 | 1 | |
fusop | 0:63db1c7ee975 | 2 | //------------------------------------------------------------------------------ |
fusop | 0:63db1c7ee975 | 3 | // SUPPLEMENTARY FUNCTION DEFINITIONS |
fusop | 0:63db1c7ee975 | 4 | //------------------------------------------------------------------------------ |
fusop | 0:63db1c7ee975 | 5 | |
fusop | 0:63db1c7ee975 | 6 | int CharInput (int y, int rNum) |
fusop | 0:63db1c7ee975 | 7 | { |
fusop | 0:63db1c7ee975 | 8 | //Planned events: |
fusop | 0:63db1c7ee975 | 9 | //1. Wake Up |
fusop | 0:63db1c7ee975 | 10 | //2. Close Oven |
fusop | 0:63db1c7ee975 | 11 | //3. Do laundry |
fusop | 0:63db1c7ee975 | 12 | //4. OP Garage |
fusop | 0:63db1c7ee975 | 13 | //5. Meeting |
fusop | 0:63db1c7ee975 | 14 | //6. Call Mom |
fusop | 0:63db1c7ee975 | 15 | |
fusop | 0:63db1c7ee975 | 16 | int txtPt = 0; //Short for Text Pointer |
fusop | 0:63db1c7ee975 | 17 | int f = 1; //Annoying temp variable for while loop control |
fusop | 0:63db1c7ee975 | 18 | |
fusop | 0:63db1c7ee975 | 19 | //Setup the first text to appear |
fusop | 0:63db1c7ee975 | 20 | oled.Label((uint8_t *) remTxt[txtPt], 0, y); |
fusop | 0:63db1c7ee975 | 21 | |
fusop | 0:63db1c7ee975 | 22 | //Clear button memories |
fusop | 0:63db1c7ee975 | 23 | butmem = 0; |
fusop | 0:63db1c7ee975 | 24 | |
fusop | 0:63db1c7ee975 | 25 | //In the condition, alternatively, (butmem != BUT_LEFT & butmem != BUT_RIGHT) |
fusop | 0:63db1c7ee975 | 26 | //Basically, as long as left and right is not pressed, keep looping. |
fusop | 0:63db1c7ee975 | 27 | while (f == 1) |
fusop | 0:63db1c7ee975 | 28 | { |
fusop | 0:63db1c7ee975 | 29 | if (butflg == 1) |
fusop | 0:63db1c7ee975 | 30 | { |
fusop | 0:63db1c7ee975 | 31 | if (butmem == BUT_UP && txtPt != 5) txtPt++; |
fusop | 0:63db1c7ee975 | 32 | else if (butmem == BUT_DOWN && txtPt != 0) txtPt--; |
fusop | 0:63db1c7ee975 | 33 | |
fusop | 0:63db1c7ee975 | 34 | //To exit this loop |
fusop | 0:63db1c7ee975 | 35 | if (butmem == BUT_LEFT || butmem == BUT_RIGHT) f = 0; |
fusop | 0:63db1c7ee975 | 36 | |
fusop | 0:63db1c7ee975 | 37 | //The screen will only be updated for every keypress |
fusop | 0:63db1c7ee975 | 38 | oled.DrawBox(0, y, 96, 96-y, COLOR_BLACK); |
fusop | 0:63db1c7ee975 | 39 | oled.Label((uint8_t *) remTxt[txtPt], 0, y); |
fusop | 0:63db1c7ee975 | 40 | butflg = 0; |
fusop | 0:63db1c7ee975 | 41 | } |
fusop | 0:63db1c7ee975 | 42 | } |
fusop | 0:63db1c7ee975 | 43 | |
fusop | 0:63db1c7ee975 | 44 | //After an input has been decided |
fusop | 0:63db1c7ee975 | 45 | if (butmem == BUT_RIGHT) //Acknowledge input and add to database |
fusop | 0:63db1c7ee975 | 46 | { |
fusop | 0:63db1c7ee975 | 47 | strcpy(remData[rNum].rText, remTxt[txtPt]); |
fusop | 0:63db1c7ee975 | 48 | return 1; |
fusop | 0:63db1c7ee975 | 49 | } |
fusop | 0:63db1c7ee975 | 50 | else return 0; //Cancel input and go back to home screen |
fusop | 0:63db1c7ee975 | 51 | |
fusop | 0:63db1c7ee975 | 52 | } |
fusop | 0:63db1c7ee975 | 53 | |
fusop | 0:63db1c7ee975 | 54 | void DelayProg (int del) |
fusop | 0:63db1c7ee975 | 55 | { |
fusop | 0:63db1c7ee975 | 56 | //A very sloppy delay program used in parallel with interrupt. |
fusop | 0:63db1c7ee975 | 57 | //Using interrupt might be a little messy, so it's better to have delay |
fusop | 0:63db1c7ee975 | 58 | //inside its own world. |
fusop | 0:63db1c7ee975 | 59 | |
fusop | 0:63db1c7ee975 | 60 | double delayCount = del*100000; |
fusop | 0:63db1c7ee975 | 61 | while (delayCount != 0) delayCount--; |
fusop | 0:63db1c7ee975 | 62 | } |
fusop | 0:63db1c7ee975 | 63 | |
fusop | 0:63db1c7ee975 | 64 | void TextInit (void) |
fusop | 0:63db1c7ee975 | 65 | { |
fusop | 0:63db1c7ee975 | 66 | strcpy(remTxt[0], "WakeUp"); |
fusop | 0:63db1c7ee975 | 67 | strcpy(remTxt[1], "CloseOven"); |
fusop | 0:63db1c7ee975 | 68 | strcpy(remTxt[2], "DoLaundry"); |
fusop | 0:63db1c7ee975 | 69 | strcpy(remTxt[3], "OpenGarage"); |
fusop | 0:63db1c7ee975 | 70 | strcpy(remTxt[4], "Meeting"); |
fusop | 0:63db1c7ee975 | 71 | strcpy(remTxt[5], "CallMom"); |
fusop | 0:63db1c7ee975 | 72 | } |
fusop | 0:63db1c7ee975 | 73 | |
fusop | 0:63db1c7ee975 | 74 | /* OLD CHARINPUT FUNCTION BECAUSE I DON'T WANT TO WASTE TIME ON SINGLE ALPHANUMERIC INPUT |
fusop | 0:63db1c7ee975 | 75 | void CharInput (int y, int rNum) |
fusop | 0:63db1c7ee975 | 76 | { |
fusop | 0:63db1c7ee975 | 77 | //Assumptions for this function: |
fusop | 0:63db1c7ee975 | 78 | //Text input always begins at the left |
fusop | 0:63db1c7ee975 | 79 | //y variable is vertical position of the text |
fusop | 0:63db1c7ee975 | 80 | //This function exits when exit character(ASCII 64 or @)is detected |
fusop | 0:63db1c7ee975 | 81 | //ASCII is used for this operation |
fusop | 0:63db1c7ee975 | 82 | |
fusop | 0:63db1c7ee975 | 83 | char textIn = 65; //A variable to control character input |
fusop | 0:63db1c7ee975 | 84 | int textPoint = 0; //Index position of string |
fusop | 0:63db1c7ee975 | 85 | char prevChar = '0'; //Stuff |
fusop | 0:63db1c7ee975 | 86 | |
fusop | 0:63db1c7ee975 | 87 | while (prevChar != '@') |
fusop | 0:63db1c7ee975 | 88 | { |
fusop | 0:63db1c7ee975 | 89 | if (butflg == 1) |
fusop | 0:63db1c7ee975 | 90 | { |
fusop | 0:63db1c7ee975 | 91 | //Character change navigation |
fusop | 0:63db1c7ee975 | 92 | if (butmem == BUT_UP && textIn != 95) textIn++; |
fusop | 0:63db1c7ee975 | 93 | else if (butmem == BUT_DOWN && textIn != 64) textIn--; |
fusop | 0:63db1c7ee975 | 94 | |
fusop | 0:63db1c7ee975 | 95 | //Position change navigation |
fusop | 0:63db1c7ee975 | 96 | else if (butmem == BUT_RIGHT && textPoint != 19) |
fusop | 0:63db1c7ee975 | 97 | { |
fusop | 0:63db1c7ee975 | 98 | prevChar = textIn; |
fusop | 0:63db1c7ee975 | 99 | textPoint++; |
fusop | 0:63db1c7ee975 | 100 | textIn = 65; |
fusop | 0:63db1c7ee975 | 101 | } |
fusop | 0:63db1c7ee975 | 102 | else if (butmem == BUT_LEFT && textPoint != 0) |
fusop | 0:63db1c7ee975 | 103 | { |
fusop | 0:63db1c7ee975 | 104 | prevChar = textIn; |
fusop | 0:63db1c7ee975 | 105 | textPoint--; |
fusop | 0:63db1c7ee975 | 106 | textIn = 65; |
fusop | 0:63db1c7ee975 | 107 | } |
fusop | 0:63db1c7ee975 | 108 | butmem = 0; |
fusop | 0:63db1c7ee975 | 109 | butflg = 0; |
fusop | 0:63db1c7ee975 | 110 | } |
fusop | 0:63db1c7ee975 | 111 | |
fusop | 0:63db1c7ee975 | 112 | remData[rNum].rText[textPoint] = textIn; |
fusop | 0:63db1c7ee975 | 113 | oled.Label((uint8_t *) remData[rNum].rText, 0, y); |
fusop | 0:63db1c7ee975 | 114 | } |
fusop | 0:63db1c7ee975 | 115 | |
fusop | 0:63db1c7ee975 | 116 | }*/ |