Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: N5110 SDFileSystem SRF02 TMP102 mbed
Fork of Ranger by
main.h@7:14cfb0df30e6, 2016-04-25 (annotated)
- Committer:
- el15pjt
- Date:
- Mon Apr 25 10:08:05 2016 +0000
- Revision:
- 7:14cfb0df30e6
- Child:
- 8:fe6ebe807b9d
BUZZER TO IMPLEMENT AND AVERAGE;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el15pjt | 7:14cfb0df30e6 | 1 | /** |
el15pjt | 7:14cfb0df30e6 | 2 | @file main.h |
el15pjt | 7:14cfb0df30e6 | 3 | @brief Header file containing functions prototypes, defines and global variables. |
el15pjt | 7:14cfb0df30e6 | 4 | @brief Ranger Project |
el15pjt | 7:14cfb0df30e6 | 5 | @brief Revision 1.0. |
el15pjt | 7:14cfb0df30e6 | 6 | @author Philip Thompson |
el15pjt | 7:14cfb0df30e6 | 7 | @date March 2016 |
el15pjt | 7:14cfb0df30e6 | 8 | @brief The following code has been writen for the University of Leeds ELEC264501 embedded system project and is intended to |
el15pjt | 7:14cfb0df30e6 | 9 | create a programe that can read a distance from an SRF02 sensor and then based aponn the reading disply the distance on the screen |
el15pjt | 7:14cfb0df30e6 | 10 | and increment the LEDs and buzzer according the provision of a temperature sensor is also provied as a secondary function when no |
el15pjt | 7:14cfb0df30e6 | 11 | object is detected with in range. |
el15pjt | 7:14cfb0df30e6 | 12 | */ |
el15pjt | 7:14cfb0df30e6 | 13 | |
el15pjt | 7:14cfb0df30e6 | 14 | #ifndef MAIN_H |
el15pjt | 7:14cfb0df30e6 | 15 | #define MAIN_H |
el15pjt | 7:14cfb0df30e6 | 16 | #include "mbed.h" |
el15pjt | 7:14cfb0df30e6 | 17 | #include "mbed.h" |
el15pjt | 7:14cfb0df30e6 | 18 | #include "SRF02.h" |
el15pjt | 7:14cfb0df30e6 | 19 | #include "N5110.h" |
el15pjt | 7:14cfb0df30e6 | 20 | #include "TMP102.h" |
el15pjt | 7:14cfb0df30e6 | 21 | #include "SDFileSystem.h" |
el15pjt | 7:14cfb0df30e6 | 22 | |
el15pjt | 7:14cfb0df30e6 | 23 | #define LOW 0 /// No output |
el15pjt | 7:14cfb0df30e6 | 24 | #define HIGH 1 /// High output |
el15pjt | 7:14cfb0df30e6 | 25 | #define METRIC 1 |
el15pjt | 7:14cfb0df30e6 | 26 | #define IMPERIAL 0 |
el15pjt | 7:14cfb0df30e6 | 27 | |
el15pjt | 7:14cfb0df30e6 | 28 | |
el15pjt | 7:14cfb0df30e6 | 29 | /** |
el15pjt | 7:14cfb0df30e6 | 30 | @namespace LEDs |
el15pjt | 7:14cfb0df30e6 | 31 | @brief Output for Alert LEDs |
el15pjt | 7:14cfb0df30e6 | 32 | */ |
el15pjt | 7:14cfb0df30e6 | 33 | /** Red LED connect to pin PTA1*/ |
el15pjt | 7:14cfb0df30e6 | 34 | DigitalOut rr_led (PTA1); |
el15pjt | 7:14cfb0df30e6 | 35 | /** amber LED connect to pin PTC2*/ |
el15pjt | 7:14cfb0df30e6 | 36 | DigitalOut a_led (PTC2); |
el15pjt | 7:14cfb0df30e6 | 37 | /** Green LED connect to pin PTB23*/ |
el15pjt | 7:14cfb0df30e6 | 38 | DigitalOut gg_led(PTB23); |
el15pjt | 7:14cfb0df30e6 | 39 | |
el15pjt | 7:14cfb0df30e6 | 40 | /** |
el15pjt | 7:14cfb0df30e6 | 41 | @namespace BOARDLEDs |
el15pjt | 7:14cfb0df30e6 | 42 | @brief On board LEDs |
el15pjt | 7:14cfb0df30e6 | 43 | */ |
el15pjt | 7:14cfb0df30e6 | 44 | DigitalOut r_led(LED_RED); |
el15pjt | 7:14cfb0df30e6 | 45 | DigitalOut g_led(LED_GREEN); |
el15pjt | 7:14cfb0df30e6 | 46 | DigitalOut b_led(LED_BLUE); |
el15pjt | 7:14cfb0df30e6 | 47 | |
el15pjt | 7:14cfb0df30e6 | 48 | /** |
el15pjt | 7:14cfb0df30e6 | 49 | @namespace Buzzer |
el15pjt | 7:14cfb0df30e6 | 50 | @brief PWM output for Buzzer |
el15pjt | 7:14cfb0df30e6 | 51 | */ |
el15pjt | 7:14cfb0df30e6 | 52 | PwmOut buzzer(PTA2); |
el15pjt | 7:14cfb0df30e6 | 53 | |
el15pjt | 7:14cfb0df30e6 | 54 | /** |
el15pjt | 7:14cfb0df30e6 | 55 | @namespace Buttons |
el15pjt | 7:14cfb0df30e6 | 56 | @brief Button triggered Interrupts |
el15pjt | 7:14cfb0df30e6 | 57 | */ |
el15pjt | 7:14cfb0df30e6 | 58 | InterruptIn sw1(PTB19); |
el15pjt | 7:14cfb0df30e6 | 59 | InterruptIn sw2(PTB18); |
el15pjt | 7:14cfb0df30e6 | 60 | |
el15pjt | 7:14cfb0df30e6 | 61 | /** |
el15pjt | 7:14cfb0df30e6 | 62 | @namespace Timers |
el15pjt | 7:14cfb0df30e6 | 63 | @brief Tickers and time outs |
el15pjt | 7:14cfb0df30e6 | 64 | */ |
el15pjt | 7:14cfb0df30e6 | 65 | Ticker ticker; |
el15pjt | 7:14cfb0df30e6 | 66 | Ticker ticker_srf02; |
el15pjt | 7:14cfb0df30e6 | 67 | Ticker ticker_tone; |
el15pjt | 7:14cfb0df30e6 | 68 | Ticker ticker_standby; |
el15pjt | 7:14cfb0df30e6 | 69 | Timeout buzzoff; |
el15pjt | 7:14cfb0df30e6 | 70 | |
el15pjt | 7:14cfb0df30e6 | 71 | // Create TMP102 object |
el15pjt | 7:14cfb0df30e6 | 72 | TMP102 tmp102(I2C_SDA,I2C_SCL); |
el15pjt | 7:14cfb0df30e6 | 73 | |
el15pjt | 7:14cfb0df30e6 | 74 | /** |
el15pjt | 7:14cfb0df30e6 | 75 | @namespace Ranger |
el15pjt | 7:14cfb0df30e6 | 76 | @brief Creat the Ranger object |
el15pjt | 7:14cfb0df30e6 | 77 | */ |
el15pjt | 7:14cfb0df30e6 | 78 | SRF02 srf02(I2C_SDA,I2C_SCL); |
el15pjt | 7:14cfb0df30e6 | 79 | |
el15pjt | 7:14cfb0df30e6 | 80 | /** |
el15pjt | 7:14cfb0df30e6 | 81 | @namespace LCD |
el15pjt | 7:14cfb0df30e6 | 82 | @brief Creats the LCD object |
el15pjt | 7:14cfb0df30e6 | 83 | */ |
el15pjt | 7:14cfb0df30e6 | 84 | N5110 lcd(PTE26,PTA0,PTC4,PTD0,PTD2,PTD1,PTC3); |
el15pjt | 7:14cfb0df30e6 | 85 | |
el15pjt | 7:14cfb0df30e6 | 86 | /// Connections to SD card holder on K64F (SPI interface) |
el15pjt | 7:14cfb0df30e6 | 87 | SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS |
el15pjt | 7:14cfb0df30e6 | 88 | |
el15pjt | 7:14cfb0df30e6 | 89 | /** |
el15pjt | 7:14cfb0df30e6 | 90 | @namespace TimerFlags |
el15pjt | 7:14cfb0df30e6 | 91 | @brief Flags for use with timed interupts |
el15pjt | 7:14cfb0df30e6 | 92 | */ |
el15pjt | 7:14cfb0df30e6 | 93 | volatile int g_timer_flag_led = 0, g_timer_flag_srf02 = 0, g_timer_flag_tone = 0; /** Flag rised by interupts*/ |
el15pjt | 7:14cfb0df30e6 | 94 | volatile int g_timer_flag_standby = 0; |
el15pjt | 7:14cfb0df30e6 | 95 | /** |
el15pjt | 7:14cfb0df30e6 | 96 | @namespace ButtonFlages |
el15pjt | 7:14cfb0df30e6 | 97 | @brief Flags for use with button interupts |
el15pjt | 7:14cfb0df30e6 | 98 | */ |
el15pjt | 7:14cfb0df30e6 | 99 | volatile int g_sw1_flag = 0, g_sw2_flag = 0; |
el15pjt | 7:14cfb0df30e6 | 100 | |
el15pjt | 7:14cfb0df30e6 | 101 | /** |
el15pjt | 7:14cfb0df30e6 | 102 | @namespace RangePresets |
el15pjt | 7:14cfb0df30e6 | 103 | @brief Preset range of the differant alert levels |
el15pjt | 7:14cfb0df30e6 | 104 | */ |
el15pjt | 7:14cfb0df30e6 | 105 | int r1 = 3,/*!< Upper limit of alert 1 */r2 = 20,/*!< Upper limit of alert 2 */r3 = 40,/*!< Upper limit of alert 3 */r4 = 60,/*!< Upper limit of alert 4 */r5 = 80,/*!< Upper limit of alert 5 */r6 = 100,/*!< Upper limit of alert 6 */r7 = 120; /*!< Upper limit of alert 7 */ |
el15pjt | 7:14cfb0df30e6 | 106 | |
el15pjt | 7:14cfb0df30e6 | 107 | FILE *fp; |
el15pjt | 7:14cfb0df30e6 | 108 | |
el15pjt | 7:14cfb0df30e6 | 109 | int myarray[9];/*!< array to hold last ten range readings */ |
el15pjt | 7:14cfb0df30e6 | 110 | int d =0; |
el15pjt | 7:14cfb0df30e6 | 111 | int t; |
el15pjt | 7:14cfb0df30e6 | 112 | int i; |
el15pjt | 7:14cfb0df30e6 | 113 | float avgdistance; |
el15pjt | 7:14cfb0df30e6 | 114 | int totaldistance; |
el15pjt | 7:14cfb0df30e6 | 115 | int subpage; /*!< veriable to hold the page being viewed with in the submenu */ |
el15pjt | 7:14cfb0df30e6 | 116 | int page;/*!< veriable to hold the page being viewed with in the menu */ |
el15pjt | 7:14cfb0df30e6 | 117 | int offset = 0;/*!< veriable to hold the offset and adjust the 0 Range point */ |
el15pjt | 7:14cfb0df30e6 | 118 | int alert;/*!< veriable to hold the current alert level */ |
el15pjt | 7:14cfb0df30e6 | 119 | int distance;/*!< veriable to hold the distance read from the srf02 sensor */ |
el15pjt | 7:14cfb0df30e6 | 120 | float bright = 1;/*!< veriable to hold the current LED backlight of the 5110 LCD */ |
el15pjt | 7:14cfb0df30e6 | 121 | char units = METRIC;/*!< veriable to hold the current unit type set to METRIC as default */ |
el15pjt | 7:14cfb0df30e6 | 122 | int length, length1, length2, length3, length4; |
el15pjt | 7:14cfb0df30e6 | 123 | char buffer[14], buffer1[14], buffer2[14], buffer3[14], buffer4[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14) |
el15pjt | 7:14cfb0df30e6 | 124 | float T; |
el15pjt | 7:14cfb0df30e6 | 125 | int standby =1; |
el15pjt | 7:14cfb0df30e6 | 126 | float c =1; /// convertion factor from Cm to inch |
el15pjt | 7:14cfb0df30e6 | 127 | |
el15pjt | 7:14cfb0df30e6 | 128 | |
el15pjt | 7:14cfb0df30e6 | 129 | struct Alertlevel { |
el15pjt | 7:14cfb0df30e6 | 130 | char srr_led; /// stead RED LED state |
el15pjt | 7:14cfb0df30e6 | 131 | char sa_led; /// stead AMBER LED state |
el15pjt | 7:14cfb0df30e6 | 132 | char sgg_led; /// stead GREEN LED state |
el15pjt | 7:14cfb0df30e6 | 133 | char frr_led;///FLASHING RED LED state |
el15pjt | 7:14cfb0df30e6 | 134 | char fa_led; ///FLASHING AMBER LED state |
el15pjt | 7:14cfb0df30e6 | 135 | char fgg_led; ///FLASHING GREEN LED state |
el15pjt | 7:14cfb0df30e6 | 136 | int toneon; |
el15pjt | 7:14cfb0df30e6 | 137 | int toneoff; |
el15pjt | 7:14cfb0df30e6 | 138 | }; /*!< Stucture to hold all outputs. Steady LEDs, Flashing LEDs, Tone on, Tonne off*/ |
el15pjt | 7:14cfb0df30e6 | 139 | typedef const struct Alertlevel STyp; |
el15pjt | 7:14cfb0df30e6 | 140 | |
el15pjt | 7:14cfb0df30e6 | 141 | STyp Alertlevel[8] = { |
el15pjt | 7:14cfb0df30e6 | 142 | {LOW,LOW,LOW,LOW,LOW,LOW,0,1}, // no output |
el15pjt | 7:14cfb0df30e6 | 143 | {LOW,LOW,LOW,LOW,LOW,HIGH,1,8}, //flash green |
el15pjt | 7:14cfb0df30e6 | 144 | {LOW,LOW,HIGH,LOW,LOW,LOW,2,7}, //steady green |
el15pjt | 7:14cfb0df30e6 | 145 | {LOW,LOW,HIGH,LOW,HIGH,LOW,4,5}, //flash amber |
el15pjt | 7:14cfb0df30e6 | 146 | {LOW,HIGH,HIGH,LOW,LOW,LOW,6,3}, //steady amber |
el15pjt | 7:14cfb0df30e6 | 147 | {LOW,HIGH,HIGH,HIGH,LOW,LOW,8,1}, //flash red |
el15pjt | 7:14cfb0df30e6 | 148 | {HIGH,HIGH,HIGH,LOW,LOW,LOW,9,0},// steady red |
el15pjt | 7:14cfb0df30e6 | 149 | {LOW,LOW,LOW,HIGH,HIGH,HIGH,9,0} // all flash |
el15pjt | 7:14cfb0df30e6 | 150 | };/*!< Array contaning structures for diffent outputs */ |
el15pjt | 7:14cfb0df30e6 | 151 | |
el15pjt | 7:14cfb0df30e6 | 152 | |
el15pjt | 7:14cfb0df30e6 | 153 | void lcdoutput(); |
el15pjt | 7:14cfb0df30e6 | 154 | void timer_isr_led(); |
el15pjt | 7:14cfb0df30e6 | 155 | void timer_isr_srf02(); |
el15pjt | 7:14cfb0df30e6 | 156 | void timer_isr_tone(); |
el15pjt | 7:14cfb0df30e6 | 157 | void timer_isr_standby(); |
el15pjt | 7:14cfb0df30e6 | 158 | /** Called to increment to brightness by 0.2 each time when at 1 resets back to 0.0 |
el15pjt | 7:14cfb0df30e6 | 159 | @param bright 0.0-1 |
el15pjt | 7:14cfb0df30e6 | 160 | @returns lcd.setbrightness |
el15pjt | 7:14cfb0df30e6 | 161 | @code |
el15pjt | 7:14cfb0df30e6 | 162 | if (bright == 1.0) { |
el15pjt | 7:14cfb0df30e6 | 163 | bright = 0; |
el15pjt | 7:14cfb0df30e6 | 164 | } else { |
el15pjt | 7:14cfb0df30e6 | 165 | bright += 0.2; |
el15pjt | 7:14cfb0df30e6 | 166 | } |
el15pjt | 7:14cfb0df30e6 | 167 | lcd.setBrightness(bright); |
el15pjt | 7:14cfb0df30e6 | 168 | @endcode |
el15pjt | 7:14cfb0df30e6 | 169 | */ |
el15pjt | 7:14cfb0df30e6 | 170 | void backlight(); |
el15pjt | 7:14cfb0df30e6 | 171 | void init_K64F(); |
el15pjt | 7:14cfb0df30e6 | 172 | void sw2_isr(); |
el15pjt | 7:14cfb0df30e6 | 173 | void sw1_isr(); |
el15pjt | 7:14cfb0df30e6 | 174 | void setup(); |
el15pjt | 7:14cfb0df30e6 | 175 | |
el15pjt | 7:14cfb0df30e6 | 176 | /** A fuction used to determin the alert level given a range with the use of IF statments |
el15pjt | 7:14cfb0df30e6 | 177 | @param distance The distance read from sensor |
el15pjt | 7:14cfb0df30e6 | 178 | @param alert The level that distance falls with in 0 -7 |
el15pjt | 7:14cfb0df30e6 | 179 | @returns alert |
el15pjt | 7:14cfb0df30e6 | 180 | @code |
el15pjt | 7:14cfb0df30e6 | 181 | if (distance >= r6 && distance < r7) { // r6 150 and r7 200 |
el15pjt | 7:14cfb0df30e6 | 182 | alert = 1; /// alert 1 distance between preset 150Cm to 200Cm |
el15pjt | 7:14cfb0df30e6 | 183 | } else if (distance >= r5 && distance < r6) { |
el15pjt | 7:14cfb0df30e6 | 184 | alert = 2; /// alert 2 when between preset 90Cm to 150Cm |
el15pjt | 7:14cfb0df30e6 | 185 | } else if (distance >= r4 && distance < r5) { |
el15pjt | 7:14cfb0df30e6 | 186 | alert = 3; /// alert 3 when distance between 60Cm to 90Cm |
el15pjt | 7:14cfb0df30e6 | 187 | } else if (distance >= r3 && distance < r4) { |
el15pjt | 7:14cfb0df30e6 | 188 | alert = 4; /// alert 4 when distance between 40Cm and 60Cm |
el15pjt | 7:14cfb0df30e6 | 189 | } else if ( distance > r2 && distance < r3) { |
el15pjt | 7:14cfb0df30e6 | 190 | alert = 5; ///alert 5 when distance between 20Cm and 40m |
el15pjt | 7:14cfb0df30e6 | 191 | } else if (distance > r1 && distance <= r2) { //r1 3 and r2 20 |
el15pjt | 7:14cfb0df30e6 | 192 | alert = 6; ///alert 6 when distance between 1 and 20 |
el15pjt | 7:14cfb0df30e6 | 193 | } else if (distance <=r1) { |
el15pjt | 7:14cfb0df30e6 | 194 | alert = 7; ///alert 7 when distance below 1Cm |
el15pjt | 7:14cfb0df30e6 | 195 | } else { |
el15pjt | 7:14cfb0df30e6 | 196 | alert = 0; /// alert 0 all else |
el15pjt | 7:14cfb0df30e6 | 197 | } |
el15pjt | 7:14cfb0df30e6 | 198 | } |
el15pjt | 7:14cfb0df30e6 | 199 | @endcode |
el15pjt | 7:14cfb0df30e6 | 200 | */ |
el15pjt | 7:14cfb0df30e6 | 201 | void setalert(); |
el15pjt | 7:14cfb0df30e6 | 202 | /** If statments to determine the output of each LED by inspecting the struct in the relevent element of the alertlevel array |
el15pjt | 7:14cfb0df30e6 | 203 | |
el15pjt | 7:14cfb0df30e6 | 204 | @code |
el15pjt | 7:14cfb0df30e6 | 205 | if (alert ==7) { |
el15pjt | 7:14cfb0df30e6 | 206 | if (g_timer_flag_led) { |
el15pjt | 7:14cfb0df30e6 | 207 | g_timer_flag_led = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 208 | rr_led = !rr_led; |
el15pjt | 7:14cfb0df30e6 | 209 | gg_led = !gg_led; |
el15pjt | 7:14cfb0df30e6 | 210 | a_led = !a_led; |
el15pjt | 7:14cfb0df30e6 | 211 | } |
el15pjt | 7:14cfb0df30e6 | 212 | } else if(Alertlevel[alert].fa_led == HIGH) { |
el15pjt | 7:14cfb0df30e6 | 213 | if (g_timer_flag_led) { |
el15pjt | 7:14cfb0df30e6 | 214 | g_timer_flag_led = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 215 | a_led = !a_led; |
el15pjt | 7:14cfb0df30e6 | 216 | } |
el15pjt | 7:14cfb0df30e6 | 217 | } else if (Alertlevel[alert].frr_led == HIGH) { |
el15pjt | 7:14cfb0df30e6 | 218 | if (g_timer_flag_led) { |
el15pjt | 7:14cfb0df30e6 | 219 | g_timer_flag_led = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 220 | rr_led = !rr_led; |
el15pjt | 7:14cfb0df30e6 | 221 | } |
el15pjt | 7:14cfb0df30e6 | 222 | } else if(Alertlevel[alert].fgg_led == HIGH) { |
el15pjt | 7:14cfb0df30e6 | 223 | if (g_timer_flag_led) { |
el15pjt | 7:14cfb0df30e6 | 224 | g_timer_flag_led = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 225 | gg_led = !gg_led; |
el15pjt | 7:14cfb0df30e6 | 226 | } |
el15pjt | 7:14cfb0df30e6 | 227 | } else { |
el15pjt | 7:14cfb0df30e6 | 228 | rr_led = Alertlevel[alert].srr_led; |
el15pjt | 7:14cfb0df30e6 | 229 | a_led = Alertlevel[alert].sa_led; |
el15pjt | 7:14cfb0df30e6 | 230 | gg_led = Alertlevel[alert].sgg_led; |
el15pjt | 7:14cfb0df30e6 | 231 | } |
el15pjt | 7:14cfb0df30e6 | 232 | |
el15pjt | 7:14cfb0df30e6 | 233 | } |
el15pjt | 7:14cfb0df30e6 | 234 | @endcode*/ |
el15pjt | 7:14cfb0df30e6 | 235 | void setleds(); |
el15pjt | 7:14cfb0df30e6 | 236 | void setbuzzer(); |
el15pjt | 7:14cfb0df30e6 | 237 | |
el15pjt | 7:14cfb0df30e6 | 238 | |
el15pjt | 7:14cfb0df30e6 | 239 | void menu(); |
el15pjt | 7:14cfb0df30e6 | 240 | /** |
el15pjt | 7:14cfb0df30e6 | 241 | { |
el15pjt | 7:14cfb0df30e6 | 242 | Function called to invoke a menu within a while loop with button interupts used to move pages and adjust within a switch statment |
el15pjt | 7:14cfb0df30e6 | 243 | @param g_sw1_flag 0 or 1 used to advance page |
el15pjt | 7:14cfb0df30e6 | 244 | @param g_sw2_flag 0 or 1 used to adjust current item |
el15pjt | 7:14cfb0df30e6 | 245 | @code |
el15pjt | 7:14cfb0df30e6 | 246 | while(1) { |
el15pjt | 7:14cfb0df30e6 | 247 | |
el15pjt | 7:14cfb0df30e6 | 248 | |
el15pjt | 7:14cfb0df30e6 | 249 | if (g_sw1_flag) { |
el15pjt | 7:14cfb0df30e6 | 250 | g_sw1_flag = 0; |
el15pjt | 7:14cfb0df30e6 | 251 | page++; /// Moves page |
el15pjt | 7:14cfb0df30e6 | 252 | lcd.clear(); |
el15pjt | 7:14cfb0df30e6 | 253 | } |
el15pjt | 7:14cfb0df30e6 | 254 | switch (page) { |
el15pjt | 7:14cfb0df30e6 | 255 | case 0: |
el15pjt | 7:14cfb0df30e6 | 256 | if (g_sw2_flag) { |
el15pjt | 7:14cfb0df30e6 | 257 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 258 | backlight(); |
el15pjt | 7:14cfb0df30e6 | 259 | lcd.clear(); |
el15pjt | 7:14cfb0df30e6 | 260 | } else { |
el15pjt | 7:14cfb0df30e6 | 261 | int lightbar = bright*84; |
el15pjt | 7:14cfb0df30e6 | 262 | sprintf(buffer2,"*****MENU*****"); |
el15pjt | 7:14cfb0df30e6 | 263 | sprintf(buffer1,"BACKLIGHT"); |
el15pjt | 7:14cfb0df30e6 | 264 | sprintf(buffer3,"%.0f%%",bright*100); |
el15pjt | 7:14cfb0df30e6 | 265 | lcd.printString(buffer2,0,0); |
el15pjt | 7:14cfb0df30e6 | 266 | lcd.printString(buffer1,0,1); |
el15pjt | 7:14cfb0df30e6 | 267 | lcd.printString(buffer3,0,2); |
el15pjt | 7:14cfb0df30e6 | 268 | lcd.drawRect(0,38,lightbar,7,1); |
el15pjt | 7:14cfb0df30e6 | 269 | lcd.refresh(); |
el15pjt | 7:14cfb0df30e6 | 270 | |
el15pjt | 7:14cfb0df30e6 | 271 | } |
el15pjt | 7:14cfb0df30e6 | 272 | break; |
el15pjt | 7:14cfb0df30e6 | 273 | |
el15pjt | 7:14cfb0df30e6 | 274 | case 1: |
el15pjt | 7:14cfb0df30e6 | 275 | if (g_sw2_flag) { |
el15pjt | 7:14cfb0df30e6 | 276 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 277 | if (offset == 20) { |
el15pjt | 7:14cfb0df30e6 | 278 | offset = 0; |
el15pjt | 7:14cfb0df30e6 | 279 | } else { |
el15pjt | 7:14cfb0df30e6 | 280 | offset += 1; |
el15pjt | 7:14cfb0df30e6 | 281 | } |
el15pjt | 7:14cfb0df30e6 | 282 | } else { |
el15pjt | 7:14cfb0df30e6 | 283 | length2 = sprintf(buffer2,"*****MENU*****"); |
el15pjt | 7:14cfb0df30e6 | 284 | length1 = sprintf(buffer1,"OFFSET"); |
el15pjt | 7:14cfb0df30e6 | 285 | length3 = sprintf(buffer3,"%i",offset); |
el15pjt | 7:14cfb0df30e6 | 286 | lcd.printString(buffer2,0,0); |
el15pjt | 7:14cfb0df30e6 | 287 | lcd.printString(buffer1,0,1); |
el15pjt | 7:14cfb0df30e6 | 288 | lcd.printString(buffer3,0,2); |
el15pjt | 7:14cfb0df30e6 | 289 | lcd.refresh(); |
el15pjt | 7:14cfb0df30e6 | 290 | } |
el15pjt | 7:14cfb0df30e6 | 291 | |
el15pjt | 7:14cfb0df30e6 | 292 | break; |
el15pjt | 7:14cfb0df30e6 | 293 | |
el15pjt | 7:14cfb0df30e6 | 294 | case 2: |
el15pjt | 7:14cfb0df30e6 | 295 | if (g_sw2_flag) { |
el15pjt | 7:14cfb0df30e6 | 296 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 297 | if (units == METRIC) { |
el15pjt | 7:14cfb0df30e6 | 298 | units = IMPERIAL; |
el15pjt | 7:14cfb0df30e6 | 299 | } else { |
el15pjt | 7:14cfb0df30e6 | 300 | units = METRIC; |
el15pjt | 7:14cfb0df30e6 | 301 | } |
el15pjt | 7:14cfb0df30e6 | 302 | } |
el15pjt | 7:14cfb0df30e6 | 303 | if (units == METRIC) { |
el15pjt | 7:14cfb0df30e6 | 304 | sprintf(buffer3,"METRIC"); |
el15pjt | 7:14cfb0df30e6 | 305 | lcd.printString(buffer3,0,2); |
el15pjt | 7:14cfb0df30e6 | 306 | } else { |
el15pjt | 7:14cfb0df30e6 | 307 | sprintf(buffer3,"IMPERIAL"); |
el15pjt | 7:14cfb0df30e6 | 308 | lcd.printString(buffer3,0,2); |
el15pjt | 7:14cfb0df30e6 | 309 | } |
el15pjt | 7:14cfb0df30e6 | 310 | |
el15pjt | 7:14cfb0df30e6 | 311 | sprintf(buffer2,"*****MENU*****"); |
el15pjt | 7:14cfb0df30e6 | 312 | sprintf(buffer1,"UNITS"); |
el15pjt | 7:14cfb0df30e6 | 313 | lcd.printString(buffer2,0,0); |
el15pjt | 7:14cfb0df30e6 | 314 | lcd.printString(buffer1,0,1); |
el15pjt | 7:14cfb0df30e6 | 315 | lcd.refresh(); |
el15pjt | 7:14cfb0df30e6 | 316 | |
el15pjt | 7:14cfb0df30e6 | 317 | break; |
el15pjt | 7:14cfb0df30e6 | 318 | |
el15pjt | 7:14cfb0df30e6 | 319 | case 3: |
el15pjt | 7:14cfb0df30e6 | 320 | |
el15pjt | 7:14cfb0df30e6 | 321 | if (g_sw2_flag) { |
el15pjt | 7:14cfb0df30e6 | 322 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 323 | submenu(); |
el15pjt | 7:14cfb0df30e6 | 324 | } |
el15pjt | 7:14cfb0df30e6 | 325 | length2 = sprintf(buffer3,"*****MENU*****"); |
el15pjt | 7:14cfb0df30e6 | 326 | length3 = sprintf(buffer1,"RANGE"); |
el15pjt | 7:14cfb0df30e6 | 327 | length3 = sprintf(buffer2,"PARAMETERS"); |
el15pjt | 7:14cfb0df30e6 | 328 | lcd.printString(buffer3,0,0); |
el15pjt | 7:14cfb0df30e6 | 329 | lcd.printString(buffer1,0,1); |
el15pjt | 7:14cfb0df30e6 | 330 | lcd.printString(buffer2,0,2); |
el15pjt | 7:14cfb0df30e6 | 331 | |
el15pjt | 7:14cfb0df30e6 | 332 | |
el15pjt | 7:14cfb0df30e6 | 333 | break; |
el15pjt | 7:14cfb0df30e6 | 334 | |
el15pjt | 7:14cfb0df30e6 | 335 | default: |
el15pjt | 7:14cfb0df30e6 | 336 | lcd.clear(); |
el15pjt | 7:14cfb0df30e6 | 337 | return; |
el15pjt | 7:14cfb0df30e6 | 338 | } |
el15pjt | 7:14cfb0df30e6 | 339 | } |
el15pjt | 7:14cfb0df30e6 | 340 | @endcode |
el15pjt | 7:14cfb0df30e6 | 341 | */ |
el15pjt | 7:14cfb0df30e6 | 342 | void menu(); |
el15pjt | 7:14cfb0df30e6 | 343 | /** |
el15pjt | 7:14cfb0df30e6 | 344 | @code |
el15pjt | 7:14cfb0df30e6 | 345 | while(1) { |
el15pjt | 7:14cfb0df30e6 | 346 | /// innterupt used to shift page |
el15pjt | 7:14cfb0df30e6 | 347 | if (g_sw1_flag) { |
el15pjt | 7:14cfb0df30e6 | 348 | g_sw1_flag = 0; |
el15pjt | 7:14cfb0df30e6 | 349 | subpage++; |
el15pjt | 7:14cfb0df30e6 | 350 | } |
el15pjt | 7:14cfb0df30e6 | 351 | switch (subpage) { |
el15pjt | 7:14cfb0df30e6 | 352 | ///interupt used to adjust range |
el15pjt | 7:14cfb0df30e6 | 353 | case 0: |
el15pjt | 7:14cfb0df30e6 | 354 | if (g_sw2_flag) { |
el15pjt | 7:14cfb0df30e6 | 355 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 356 | if (r2 == r3) { |
el15pjt | 7:14cfb0df30e6 | 357 | r2 = 1; |
el15pjt | 7:14cfb0df30e6 | 358 | } else { |
el15pjt | 7:14cfb0df30e6 | 359 | r2 = r2+1; |
el15pjt | 7:14cfb0df30e6 | 360 | } |
el15pjt | 7:14cfb0df30e6 | 361 | } |
el15pjt | 7:14cfb0df30e6 | 362 | length2 = sprintf(buffer1,"*****MENU*****"); |
el15pjt | 7:14cfb0df30e6 | 363 | length3 = sprintf(buffer2,"RANGE"); |
el15pjt | 7:14cfb0df30e6 | 364 | length3 = sprintf(buffer3,"PARAMETERS"); |
el15pjt | 7:14cfb0df30e6 | 365 | length4 = sprintf(buffer4,"1Cm to %iCm",r2); |
el15pjt | 7:14cfb0df30e6 | 366 | lcd.printString(buffer1,0,0); |
el15pjt | 7:14cfb0df30e6 | 367 | lcd.printString(buffer2,0,1); |
el15pjt | 7:14cfb0df30e6 | 368 | lcd.printString(buffer3,0,2); |
el15pjt | 7:14cfb0df30e6 | 369 | lcd.printString(buffer4,0,3); |
el15pjt | 7:14cfb0df30e6 | 370 | break; |
el15pjt | 7:14cfb0df30e6 | 371 | |
el15pjt | 7:14cfb0df30e6 | 372 | case 1: |
el15pjt | 7:14cfb0df30e6 | 373 | |
el15pjt | 7:14cfb0df30e6 | 374 | if (g_sw2_flag) { |
el15pjt | 7:14cfb0df30e6 | 375 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 376 | if (r3 == r4) { |
el15pjt | 7:14cfb0df30e6 | 377 | r3 = r2; |
el15pjt | 7:14cfb0df30e6 | 378 | } else { |
el15pjt | 7:14cfb0df30e6 | 379 | r3 += 1; |
el15pjt | 7:14cfb0df30e6 | 380 | } |
el15pjt | 7:14cfb0df30e6 | 381 | } |
el15pjt | 7:14cfb0df30e6 | 382 | |
el15pjt | 7:14cfb0df30e6 | 383 | sprintf(buffer1,"*****MENU*****"); |
el15pjt | 7:14cfb0df30e6 | 384 | sprintf(buffer2,"RANGE"); |
el15pjt | 7:14cfb0df30e6 | 385 | sprintf(buffer3,"PARAMETERS"); |
el15pjt | 7:14cfb0df30e6 | 386 | sprintf(buffer4,"%iCm to %iCm",r2,r3); |
el15pjt | 7:14cfb0df30e6 | 387 | lcd.printString(buffer1,0,0); |
el15pjt | 7:14cfb0df30e6 | 388 | lcd.printString(buffer2,0,1); |
el15pjt | 7:14cfb0df30e6 | 389 | lcd.printString(buffer3,0,2); |
el15pjt | 7:14cfb0df30e6 | 390 | lcd.printString(buffer4,0,3); |
el15pjt | 7:14cfb0df30e6 | 391 | break; |
el15pjt | 7:14cfb0df30e6 | 392 | |
el15pjt | 7:14cfb0df30e6 | 393 | case 2: |
el15pjt | 7:14cfb0df30e6 | 394 | |
el15pjt | 7:14cfb0df30e6 | 395 | if (g_sw2_flag) { |
el15pjt | 7:14cfb0df30e6 | 396 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 397 | if (r4 == r5) { |
el15pjt | 7:14cfb0df30e6 | 398 | r4 = r3; |
el15pjt | 7:14cfb0df30e6 | 399 | } else { |
el15pjt | 7:14cfb0df30e6 | 400 | r4 += 1; |
el15pjt | 7:14cfb0df30e6 | 401 | } |
el15pjt | 7:14cfb0df30e6 | 402 | } |
el15pjt | 7:14cfb0df30e6 | 403 | |
el15pjt | 7:14cfb0df30e6 | 404 | sprintf(buffer1,"*****MENU*****"); |
el15pjt | 7:14cfb0df30e6 | 405 | sprintf(buffer2,"RANGE"); |
el15pjt | 7:14cfb0df30e6 | 406 | sprintf(buffer3,"PARAMETERS"); |
el15pjt | 7:14cfb0df30e6 | 407 | sprintf(buffer4,"%iCm to %iCm",r3,r4); |
el15pjt | 7:14cfb0df30e6 | 408 | lcd.printString(buffer1,0,0); |
el15pjt | 7:14cfb0df30e6 | 409 | lcd.printString(buffer2,0,1); |
el15pjt | 7:14cfb0df30e6 | 410 | lcd.printString(buffer3,0,2); |
el15pjt | 7:14cfb0df30e6 | 411 | lcd.printString(buffer4,0,3); |
el15pjt | 7:14cfb0df30e6 | 412 | break; |
el15pjt | 7:14cfb0df30e6 | 413 | |
el15pjt | 7:14cfb0df30e6 | 414 | case 3: |
el15pjt | 7:14cfb0df30e6 | 415 | |
el15pjt | 7:14cfb0df30e6 | 416 | if (g_sw2_flag) { |
el15pjt | 7:14cfb0df30e6 | 417 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 418 | if (r5 == r6) { |
el15pjt | 7:14cfb0df30e6 | 419 | r5 = r4; |
el15pjt | 7:14cfb0df30e6 | 420 | } else { |
el15pjt | 7:14cfb0df30e6 | 421 | r5 += 1; |
el15pjt | 7:14cfb0df30e6 | 422 | } |
el15pjt | 7:14cfb0df30e6 | 423 | } |
el15pjt | 7:14cfb0df30e6 | 424 | |
el15pjt | 7:14cfb0df30e6 | 425 | sprintf(buffer1,"*****MENU*****"); |
el15pjt | 7:14cfb0df30e6 | 426 | sprintf(buffer2,"RANGE"); |
el15pjt | 7:14cfb0df30e6 | 427 | sprintf(buffer3,"PARAMETERS"); |
el15pjt | 7:14cfb0df30e6 | 428 | sprintf(buffer4,"%iCm to %iCm",r4,r5); |
el15pjt | 7:14cfb0df30e6 | 429 | lcd.printString(buffer1,0,0); |
el15pjt | 7:14cfb0df30e6 | 430 | lcd.printString(buffer2,0,1); |
el15pjt | 7:14cfb0df30e6 | 431 | lcd.printString(buffer3,0,2); |
el15pjt | 7:14cfb0df30e6 | 432 | lcd.printString(buffer4,0,3); |
el15pjt | 7:14cfb0df30e6 | 433 | break; |
el15pjt | 7:14cfb0df30e6 | 434 | case 4: |
el15pjt | 7:14cfb0df30e6 | 435 | |
el15pjt | 7:14cfb0df30e6 | 436 | if (g_sw2_flag) { |
el15pjt | 7:14cfb0df30e6 | 437 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 438 | if (r6 == r7) { |
el15pjt | 7:14cfb0df30e6 | 439 | r6 = r5; |
el15pjt | 7:14cfb0df30e6 | 440 | } else { |
el15pjt | 7:14cfb0df30e6 | 441 | r6 += 1; |
el15pjt | 7:14cfb0df30e6 | 442 | } |
el15pjt | 7:14cfb0df30e6 | 443 | } |
el15pjt | 7:14cfb0df30e6 | 444 | |
el15pjt | 7:14cfb0df30e6 | 445 | length2 = sprintf(buffer1,"*****MENU*****"); |
el15pjt | 7:14cfb0df30e6 | 446 | length3 = sprintf(buffer2,"RANGE"); |
el15pjt | 7:14cfb0df30e6 | 447 | length3 = sprintf(buffer3,"PARAMETERS"); |
el15pjt | 7:14cfb0df30e6 | 448 | length3 = sprintf(buffer4,"%iCm to %iCm",r5,r6); |
el15pjt | 7:14cfb0df30e6 | 449 | lcd.printString(buffer1,0,0); |
el15pjt | 7:14cfb0df30e6 | 450 | lcd.printString(buffer2,0,1); |
el15pjt | 7:14cfb0df30e6 | 451 | lcd.printString(buffer3,0,2); |
el15pjt | 7:14cfb0df30e6 | 452 | lcd.printString(buffer4,0,3); |
el15pjt | 7:14cfb0df30e6 | 453 | break; |
el15pjt | 7:14cfb0df30e6 | 454 | case 5: |
el15pjt | 7:14cfb0df30e6 | 455 | |
el15pjt | 7:14cfb0df30e6 | 456 | if (g_sw2_flag) { |
el15pjt | 7:14cfb0df30e6 | 457 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 458 | if (r7 == 300) { |
el15pjt | 7:14cfb0df30e6 | 459 | r7 = r6; |
el15pjt | 7:14cfb0df30e6 | 460 | } else { |
el15pjt | 7:14cfb0df30e6 | 461 | r7 += 1; |
el15pjt | 7:14cfb0df30e6 | 462 | } |
el15pjt | 7:14cfb0df30e6 | 463 | } |
el15pjt | 7:14cfb0df30e6 | 464 | |
el15pjt | 7:14cfb0df30e6 | 465 | length2 = sprintf(buffer1,"*****MENU*****"); |
el15pjt | 7:14cfb0df30e6 | 466 | length3 = sprintf(buffer2,"RANGE"); |
el15pjt | 7:14cfb0df30e6 | 467 | length3 = sprintf(buffer3,"PARAMETERS"); |
el15pjt | 7:14cfb0df30e6 | 468 | length3 = sprintf(buffer4,"%iCm to %iCm",r6,r7); |
el15pjt | 7:14cfb0df30e6 | 469 | lcd.printString(buffer1,0,0); |
el15pjt | 7:14cfb0df30e6 | 470 | lcd.printString(buffer2,0,1); |
el15pjt | 7:14cfb0df30e6 | 471 | lcd.printString(buffer3,0,2); |
el15pjt | 7:14cfb0df30e6 | 472 | lcd.printString(buffer4,0,3); |
el15pjt | 7:14cfb0df30e6 | 473 | break; |
el15pjt | 7:14cfb0df30e6 | 474 | |
el15pjt | 7:14cfb0df30e6 | 475 | default: |
el15pjt | 7:14cfb0df30e6 | 476 | lcd.clear(); |
el15pjt | 7:14cfb0df30e6 | 477 | // save(); |
el15pjt | 7:14cfb0df30e6 | 478 | return; |
el15pjt | 7:14cfb0df30e6 | 479 | } |
el15pjt | 7:14cfb0df30e6 | 480 | } |
el15pjt | 7:14cfb0df30e6 | 481 | } |
el15pjt | 7:14cfb0df30e6 | 482 | @endcode |
el15pjt | 7:14cfb0df30e6 | 483 | */ |
el15pjt | 7:14cfb0df30e6 | 484 | void submenu(); |
el15pjt | 7:14cfb0df30e6 | 485 | void save(); |
el15pjt | 7:14cfb0df30e6 | 486 | void load(); |
el15pjt | 7:14cfb0df30e6 | 487 | void standby1(); |
el15pjt | 7:14cfb0df30e6 | 488 | |
el15pjt | 7:14cfb0df30e6 | 489 | #endif |