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: SDFileSystem mbed
Fork of PES4_Programme by
source/main.cpp@55:bdab541f434d, 2018-03-30 (annotated)
- Committer:
- cittecla
- Date:
- Fri Mar 30 13:05:13 2018 +0000
- Revision:
- 55:bdab541f434d
- Parent:
- 53:1c61cadbcb35
- Child:
- 56:218601547d13
expanded meadication read; added medication print test tool
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cittecla | 3:94026b29e994 | 1 | #include "main.h" |
cittecla | 2:72886e996098 | 2 | |
itslinear | 17:bbafd216e059 | 3 | |
cittecla | 52:701d0c2f47d7 | 4 | int state = 44; |
cittecla | 41:f054a83f9556 | 5 | int oldState; |
cittecla | 2:72886e996098 | 6 | |
cittecla | 2:72886e996098 | 7 | Serial pc(USBTX, USBRX); // tx, rx |
aeschsim | 40:b5e533e1e033 | 8 | |
aeschsim | 40:b5e533e1e033 | 9 | /* PWM Test Tool */ |
aeschsim | 40:b5e533e1e033 | 10 | int channel; |
aeschsim | 40:b5e533e1e033 | 11 | int dutyCycle; |
cittecla | 55:bdab541f434d | 12 | int day; |
cittecla | 55:bdab541f434d | 13 | int moment; |
cittecla | 55:bdab541f434d | 14 | s_user user[2]; |
cittecla | 2:72886e996098 | 15 | |
cittecla | 2:72886e996098 | 16 | int main() |
cittecla | 2:72886e996098 | 17 | { |
cittecla | 2:72886e996098 | 18 | pc.baud(460800); |
cittecla | 2:72886e996098 | 19 | printf("start...\r\n"); |
cittecla | 2:72886e996098 | 20 | |
aeschsim | 34:9d6dd3a12641 | 21 | while(1) { |
cittecla | 41:f054a83f9556 | 22 | if(state != oldState) { |
aeschsim | 34:9d6dd3a12641 | 23 | printf("state: %d\r\n",state); |
cittecla | 41:f054a83f9556 | 24 | oldState = state; |
aeschsim | 34:9d6dd3a12641 | 25 | } |
aeschsim | 34:9d6dd3a12641 | 26 | switch (state) { |
aeschsim | 34:9d6dd3a12641 | 27 | case 0: |
aeschsim | 34:9d6dd3a12641 | 28 | printf("Hello World"); |
aeschsim | 40:b5e533e1e033 | 29 | state = 47; |
aeschsim | 34:9d6dd3a12641 | 30 | break; |
aeschsim | 34:9d6dd3a12641 | 31 | case 1: |
aeschsim | 34:9d6dd3a12641 | 32 | break; |
aeschsim | 34:9d6dd3a12641 | 33 | case 2: |
aeschsim | 34:9d6dd3a12641 | 34 | break; |
aeschsim | 34:9d6dd3a12641 | 35 | case 3: |
aeschsim | 34:9d6dd3a12641 | 36 | break; |
cittecla | 2:72886e996098 | 37 | |
aeschsim | 34:9d6dd3a12641 | 38 | case 10: |
aeschsim | 34:9d6dd3a12641 | 39 | break; |
aeschsim | 34:9d6dd3a12641 | 40 | case 11: |
aeschsim | 34:9d6dd3a12641 | 41 | break; |
cittecla | 2:72886e996098 | 42 | |
aeschsim | 34:9d6dd3a12641 | 43 | case 15: |
aeschsim | 34:9d6dd3a12641 | 44 | break; |
aeschsim | 34:9d6dd3a12641 | 45 | case 16: |
aeschsim | 34:9d6dd3a12641 | 46 | break; |
aeschsim | 34:9d6dd3a12641 | 47 | case 17: |
aeschsim | 34:9d6dd3a12641 | 48 | break; |
aeschsim | 34:9d6dd3a12641 | 49 | |
aeschsim | 34:9d6dd3a12641 | 50 | case 25: |
aeschsim | 34:9d6dd3a12641 | 51 | break; |
aeschsim | 34:9d6dd3a12641 | 52 | case 26: |
aeschsim | 34:9d6dd3a12641 | 53 | break; |
aeschsim | 34:9d6dd3a12641 | 54 | case 27: |
aeschsim | 34:9d6dd3a12641 | 55 | break; |
aeschsim | 34:9d6dd3a12641 | 56 | case 28: |
aeschsim | 34:9d6dd3a12641 | 57 | break; |
cittecla | 2:72886e996098 | 58 | |
cittecla | 2:72886e996098 | 59 | |
aeschsim | 34:9d6dd3a12641 | 60 | case 35: |
aeschsim | 34:9d6dd3a12641 | 61 | break; |
aeschsim | 34:9d6dd3a12641 | 62 | case 36: |
aeschsim | 34:9d6dd3a12641 | 63 | break; |
aeschsim | 34:9d6dd3a12641 | 64 | case 37: |
aeschsim | 34:9d6dd3a12641 | 65 | break; |
aeschsim | 34:9d6dd3a12641 | 66 | case 38: |
aeschsim | 34:9d6dd3a12641 | 67 | break; |
aeschsim | 27:bf0577ecfa6e | 68 | |
aeschsim | 40:b5e533e1e033 | 69 | /**************************************************************/ |
aeschsim | 40:b5e533e1e033 | 70 | /* Test Zone */ |
cittecla | 53:1c61cadbcb35 | 71 | |
cittecla | 52:701d0c2f47d7 | 72 | /* init PWM board */ |
cittecla | 52:701d0c2f47d7 | 73 | case 44: |
cittecla | 55:bdab541f434d | 74 | printf("Init PWM\r\n"); |
cittecla | 53:1c61cadbcb35 | 75 | initPWM(50); |
cittecla | 53:1c61cadbcb35 | 76 | enableOutput(); |
cittecla | 52:701d0c2f47d7 | 77 | state = 47; |
cittecla | 52:701d0c2f47d7 | 78 | break; |
aeschsim | 40:b5e533e1e033 | 79 | |
aeschsim | 40:b5e533e1e033 | 80 | /* Time test tool: set Time */ |
aeschsim | 34:9d6dd3a12641 | 81 | case 45: |
aeschsim | 34:9d6dd3a12641 | 82 | s_time time; |
aeschsim | 34:9d6dd3a12641 | 83 | time.second = 30; |
aeschsim | 34:9d6dd3a12641 | 84 | time.minute = 53; |
aeschsim | 34:9d6dd3a12641 | 85 | time.hour = 12; |
aeschsim | 34:9d6dd3a12641 | 86 | time.day = 27; |
aeschsim | 34:9d6dd3a12641 | 87 | time.weekday = 2; |
aeschsim | 34:9d6dd3a12641 | 88 | time.month = 3; |
aeschsim | 34:9d6dd3a12641 | 89 | time.year = 18; |
cittecla | 55:bdab541f434d | 90 | printf("set now time\r\n"); |
aeschsim | 34:9d6dd3a12641 | 91 | setTime(&time); |
cittecla | 55:bdab541f434d | 92 | printf("read time: %02d:%02d:%02d, %02d.%02d.20%02d, weekday: %d\r\n",time.hour, time.minute, time.second, time.day, time.month, time.year, time.weekday); |
aeschsim | 40:b5e533e1e033 | 93 | state = 47; |
cittecla | 55:bdab541f434d | 94 | printf("change state to: %d\r\n",state); |
aeschsim | 34:9d6dd3a12641 | 95 | break; |
aeschsim | 40:b5e533e1e033 | 96 | |
aeschsim | 40:b5e533e1e033 | 97 | /* Time test tool: get Time */ |
aeschsim | 34:9d6dd3a12641 | 98 | case 46: |
aeschsim | 34:9d6dd3a12641 | 99 | wait(5); |
aeschsim | 34:9d6dd3a12641 | 100 | time = getTime(); |
cittecla | 55:bdab541f434d | 101 | printf("read time: %02d:%02d:%02d, %02d.%02d.20%02d, weekday: %d\r\n",time.hour, time.minute, time.second, time.day, time.month, time.year, time.weekday); |
aeschsim | 40:b5e533e1e033 | 102 | state = 47; |
aeschsim | 40:b5e533e1e033 | 103 | break; |
aeschsim | 40:b5e533e1e033 | 104 | |
aeschsim | 40:b5e533e1e033 | 105 | /* Console State Switch */ |
aeschsim | 40:b5e533e1e033 | 106 | case 47: |
cittecla | 55:bdab541f434d | 107 | printf("\n\rState Switch: Enter next State: \n\r"); |
cittecla | 55:bdab541f434d | 108 | printf("45\tset Time\n\r46\tread Time\n\r47\tState Switch\n\r48\tServo Board Test Tool\n\r49\tenable servo output\n\r50\tdisable servo output\n\r51\ttest SD Card\n\r52\tread medication\n\r53\tMedication display test tool\n\r"); |
aeschsim | 40:b5e533e1e033 | 109 | pc.scanf("%d", &state); |
cittecla | 55:bdab541f434d | 110 | printf("Switch to State %d\n\r",state); |
aeschsim | 40:b5e533e1e033 | 111 | fflush(stdin); |
aeschsim | 34:9d6dd3a12641 | 112 | break; |
aeschsim | 40:b5e533e1e033 | 113 | |
aeschsim | 40:b5e533e1e033 | 114 | /* Servo-Board Test Tool */ |
aeschsim | 34:9d6dd3a12641 | 115 | case 48: |
cittecla | 55:bdab541f434d | 116 | printf("\n\r\n\rServo-Board Test Tool\n\rEnter Channel Number and then Duty Cycle\n\r"); |
cittecla | 55:bdab541f434d | 117 | printf("for exit, enter Channel > 15\n\r"); |
aeschsim | 40:b5e533e1e033 | 118 | channel = 0; |
aeschsim | 40:b5e533e1e033 | 119 | while (channel < 16) { |
cittecla | 55:bdab541f434d | 120 | printf("Channel Number: "); |
aeschsim | 40:b5e533e1e033 | 121 | pc.scanf("%d", &channel); |
cittecla | 55:bdab541f434d | 122 | printf("\r\nchannel: %d\n\rDuty Cycle 0..4095: ",channel); |
aeschsim | 40:b5e533e1e033 | 123 | pc.scanf("%d", &dutyCycle); |
cittecla | 55:bdab541f434d | 124 | printf("\n\r%d\n\r",dutyCycle); |
aeschsim | 46:cdc24a24e4e3 | 125 | setPWM((char)channel, (int)dutyCycle); |
aeschsim | 40:b5e533e1e033 | 126 | fflush(stdin); |
aeschsim | 40:b5e533e1e033 | 127 | } |
cittecla | 55:bdab541f434d | 128 | printf("leave Servo-Board Test Tool\n\r"); |
aeschsim | 40:b5e533e1e033 | 129 | state = 47; |
aeschsim | 40:b5e533e1e033 | 130 | break; |
aeschsim | 40:b5e533e1e033 | 131 | |
aeschsim | 40:b5e533e1e033 | 132 | case 49: |
cittecla | 42:ba59ed6a2a06 | 133 | enableOutput(); |
cittecla | 55:bdab541f434d | 134 | printf("Servo output enabled\r\n\n"); |
aeschsim | 40:b5e533e1e033 | 135 | state = 47; |
aeschsim | 34:9d6dd3a12641 | 136 | break; |
cittecla | 2:72886e996098 | 137 | |
aeschsim | 34:9d6dd3a12641 | 138 | case 50: |
cittecla | 42:ba59ed6a2a06 | 139 | disableOutput(); |
cittecla | 55:bdab541f434d | 140 | printf("Servo output disabled\r\n\n"); |
aeschsim | 40:b5e533e1e033 | 141 | state = 47; |
aeschsim | 40:b5e533e1e033 | 142 | break; |
cittecla | 53:1c61cadbcb35 | 143 | |
cittecla | 42:ba59ed6a2a06 | 144 | case 51: |
cittecla | 52:701d0c2f47d7 | 145 | testSd(); |
cittecla | 55:bdab541f434d | 146 | printf("\rSD Card test finished\r\n\n"); |
cittecla | 55:bdab541f434d | 147 | state = 47; |
cittecla | 55:bdab541f434d | 148 | break; |
cittecla | 55:bdab541f434d | 149 | |
cittecla | 55:bdab541f434d | 150 | case 52: |
cittecla | 55:bdab541f434d | 151 | user[0] = readMedication(0); |
cittecla | 55:bdab541f434d | 152 | if(user[0].valid) { |
cittecla | 55:bdab541f434d | 153 | printf("\rtest read successful\r\n\n"); |
cittecla | 55:bdab541f434d | 154 | } else { |
cittecla | 55:bdab541f434d | 155 | printf("\rread failed\r\n\n"); |
cittecla | 55:bdab541f434d | 156 | } |
cittecla | 42:ba59ed6a2a06 | 157 | state = 47; |
cittecla | 53:1c61cadbcb35 | 158 | break; |
cittecla | 55:bdab541f434d | 159 | |
cittecla | 55:bdab541f434d | 160 | case 53: |
cittecla | 55:bdab541f434d | 161 | if(user[0].valid == false) { |
cittecla | 55:bdab541f434d | 162 | printf("\r\nNo valid data in struct, try to run case 52\r\n\n"); |
cittecla | 55:bdab541f434d | 163 | } else { |
cittecla | 55:bdab541f434d | 164 | printf("\r\nMedication display test tool:\r\n"); |
cittecla | 55:bdab541f434d | 165 | printf("Enter Day (0..6) and Moment (0..4)\r\nTo exit enter Day > 6:\r\n"); |
cittecla | 55:bdab541f434d | 166 | day = 0; |
cittecla | 55:bdab541f434d | 167 | while (day < 7) { |
cittecla | 55:bdab541f434d | 168 | printf("\r\nDay Number: "); |
cittecla | 55:bdab541f434d | 169 | pc.scanf("%d", &day); |
cittecla | 55:bdab541f434d | 170 | if(day < 7) { |
cittecla | 55:bdab541f434d | 171 | printf("\r\nDay: %d\n\rMoment 0..3: ",day); |
cittecla | 55:bdab541f434d | 172 | pc.scanf("%d", &moment); |
cittecla | 55:bdab541f434d | 173 | printf("\r\nMedication for weekday %d Moment %d is ",day,moment); |
cittecla | 55:bdab541f434d | 174 | for(int i=0; i<6; i++) { |
cittecla | 55:bdab541f434d | 175 | printf("%d", user[0].medication.day[day].moment[moment].medContainer.container[i]); |
cittecla | 55:bdab541f434d | 176 | } |
cittecla | 55:bdab541f434d | 177 | } |
cittecla | 55:bdab541f434d | 178 | printf("\r\n"); |
cittecla | 55:bdab541f434d | 179 | fflush(stdin); |
cittecla | 55:bdab541f434d | 180 | } |
cittecla | 55:bdab541f434d | 181 | printf("exit Tool\n\r"); |
cittecla | 55:bdab541f434d | 182 | } |
cittecla | 53:1c61cadbcb35 | 183 | |
aeschsim | 40:b5e533e1e033 | 184 | default: |
aeschsim | 40:b5e533e1e033 | 185 | state = 47; /* Go to State Switch */ |
aeschsim | 34:9d6dd3a12641 | 186 | break; |
aeschsim | 34:9d6dd3a12641 | 187 | } |
cittecla | 2:72886e996098 | 188 | } |
cittecla | 55:bdab541f434d | 189 | printf("exit while 1 loop"); |
cittecla | 2:72886e996098 | 190 | } |