PES 4 - Smart Medication Dispenser / PES4_ProgrammeforDesignReview2

Dependencies:   SDFileSystem mbed

Fork of PES4_Programme by PES 4 - Smart Medication Dispenser

Committer:
itslinear
Date:
Mon Apr 09 15:43:45 2018 +0000
Revision:
90:d0805b58b0ae
Parent:
85:04fe3dff23f4
Child:
91:443b0ac21de0
added stuff;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cittecla 3:94026b29e994 1 #include "main.h"
aeschsim 59:1867088695f3 2 #define FADESPEED 5
aeschsim 59:1867088695f3 3 #define DEMOTIME 5
itslinear 17:bbafd216e059 4
EHess 85:04fe3dff23f4 5 int state = 44;
itslinear 17:bbafd216e059 6
cittecla 41:f054a83f9556 7 int oldState;
cittecla 2:72886e996098 8
cittecla 2:72886e996098 9 Serial pc(USBTX, USBRX); // tx, rx
aeschsim 40:b5e533e1e033 10
aeschsim 60:7554e4272b3b 11 DigitalIn lichtschranke(PC_5);
aeschsim 60:7554e4272b3b 12 InterruptIn userButton1(PB_5);
aeschsim 60:7554e4272b3b 13 InterruptIn userButton2(PB_4);
aeschsim 60:7554e4272b3b 14 DigitalIn glasDetection(PA_10);
aeschsim 60:7554e4272b3b 15 PwmOut summer(PC_8);
aeschsim 59:1867088695f3 16
aeschsim 40:b5e533e1e033 17 /* PWM Test Tool */
aeschsim 40:b5e533e1e033 18 int channel;
aeschsim 40:b5e533e1e033 19 int dutyCycle;
cittecla 55:bdab541f434d 20 int day;
cittecla 55:bdab541f434d 21 int moment;
itslinear 73:7fd3701def5b 22 s_user prescription[2];
cittecla 2:72886e996098 23
aeschsim 59:1867088695f3 24 /* Demo Tool */
aeschsim 59:1867088695f3 25 uint32_t color = 0;
aeschsim 59:1867088695f3 26 int colorTime = 0;
aeschsim 59:1867088695f3 27 int r,b,g;
aeschsim 59:1867088695f3 28
itslinear 72:172b40dd16ee 29 /* SD write Test*/
itslinear 72:172b40dd16ee 30 s_time medicationTime;
itslinear 72:172b40dd16ee 31 s_time outputTime;
itslinear 77:c2e22d1e5d44 32 s_time currentTime;
itslinear 72:172b40dd16ee 33 s_medContainer medication;
itslinear 80:6e3eb8246ced 34 //s_medContainer medInventory;
itslinear 80:6e3eb8246ced 35 s_medInventory medInventory;
itslinear 72:172b40dd16ee 36
itslinear 72:172b40dd16ee 37 int success = 1;
itslinear 73:7fd3701def5b 38
itslinear 80:6e3eb8246ced 39 char user = 1;
itslinear 80:6e3eb8246ced 40 /*
itslinear 73:7fd3701def5b 41 char med1[] = "A";
itslinear 73:7fd3701def5b 42 char med2[] = "B";
itslinear 73:7fd3701def5b 43 char med3[] = "C";
itslinear 73:7fd3701def5b 44 char med4[] = "D";
itslinear 73:7fd3701def5b 45 char med5[] = "E";
itslinear 73:7fd3701def5b 46 char med6[] = "F";
itslinear 80:6e3eb8246ced 47 */
itslinear 80:6e3eb8246ced 48 char fail[] = "shit happens";
itslinear 73:7fd3701def5b 49
itslinear 80:6e3eb8246ced 50 char *send;
itslinear 80:6e3eb8246ced 51
itslinear 73:7fd3701def5b 52 /*********/
itslinear 73:7fd3701def5b 53
aeschsim 79:c825bd2dea81 54 /* Switch Summer On/Off for demo Tool */
aeschsim 60:7554e4272b3b 55 void summ(void)
aeschsim 60:7554e4272b3b 56 {
aeschsim 60:7554e4272b3b 57 if(summer.read()>0) {
aeschsim 60:7554e4272b3b 58 summer.write(0.0f);
aeschsim 60:7554e4272b3b 59 } else {
aeschsim 60:7554e4272b3b 60 summer.write(0.5f);
aeschsim 60:7554e4272b3b 61 }
aeschsim 60:7554e4272b3b 62 }
aeschsim 60:7554e4272b3b 63
aeschsim 60:7554e4272b3b 64
cittecla 2:72886e996098 65 int main()
cittecla 2:72886e996098 66 {
itslinear 73:7fd3701def5b 67 /* SD write Test*/
aeschsim 79:c825bd2dea81 68
itslinear 77:c2e22d1e5d44 69 medicationTime = getTime();
itslinear 73:7fd3701def5b 70
itslinear 77:c2e22d1e5d44 71 outputTime = getTime();
itslinear 77:c2e22d1e5d44 72 currentTime = getTime();
itslinear 73:7fd3701def5b 73
itslinear 73:7fd3701def5b 74 medication.container[0] = 1;
itslinear 73:7fd3701def5b 75 medication.container[1] = 2;
itslinear 73:7fd3701def5b 76 medication.container[2] = 2;
itslinear 73:7fd3701def5b 77 medication.container[3] = 1;
itslinear 73:7fd3701def5b 78 medication.container[4] = 1;
itslinear 73:7fd3701def5b 79 medication.container[5] = 2;
itslinear 73:7fd3701def5b 80
itslinear 80:6e3eb8246ced 81 /*
itslinear 80:6e3eb8246ced 82 medInventory.container[0] = 5;
itslinear 80:6e3eb8246ced 83 medInventory.container[1] = 10;
itslinear 80:6e3eb8246ced 84 medInventory.container[2] = 15;
itslinear 80:6e3eb8246ced 85 medInventory.container[3] = 20;
itslinear 80:6e3eb8246ced 86 medInventory.container[4] = 25;
itslinear 80:6e3eb8246ced 87 medInventory.container[5] = 30;
itslinear 80:6e3eb8246ced 88 */
itslinear 73:7fd3701def5b 89 /************/
itslinear 73:7fd3701def5b 90
cittecla 2:72886e996098 91 pc.baud(460800);
cittecla 2:72886e996098 92 printf("start...\r\n");
cittecla 2:72886e996098 93
aeschsim 34:9d6dd3a12641 94 while(1) {
cittecla 41:f054a83f9556 95 if(state != oldState) {
cittecla 58:cda5298c9b7f 96 printf("\r\nstate: %d\r\n",state);
cittecla 41:f054a83f9556 97 oldState = state;
aeschsim 34:9d6dd3a12641 98 }
aeschsim 34:9d6dd3a12641 99 switch (state) {
aeschsim 34:9d6dd3a12641 100 case 0:
aeschsim 34:9d6dd3a12641 101 printf("Hello World");
aeschsim 40:b5e533e1e033 102 state = 47;
aeschsim 34:9d6dd3a12641 103 break;
itslinear 90:d0805b58b0ae 104
aeschsim 34:9d6dd3a12641 105 case 1:
itslinear 90:d0805b58b0ae 106 char command;
itslinear 90:d0805b58b0ae 107 if(pc.readable()) {
itslinear 90:d0805b58b0ae 108 command = pc.getc();
itslinear 90:d0805b58b0ae 109 } else if(command == 'w') {
itslinear 90:d0805b58b0ae 110 if(pc.writeable()) {
itslinear 90:d0805b58b0ae 111 printf("%s", send);
itslinear 90:d0805b58b0ae 112 }
itslinear 90:d0805b58b0ae 113 } else {
itslinear 90:d0805b58b0ae 114 state = 47;
itslinear 90:d0805b58b0ae 115 }
itslinear 90:d0805b58b0ae 116
aeschsim 34:9d6dd3a12641 117 break;
itslinear 90:d0805b58b0ae 118
aeschsim 34:9d6dd3a12641 119 case 2:
aeschsim 34:9d6dd3a12641 120 break;
aeschsim 34:9d6dd3a12641 121 case 3:
aeschsim 34:9d6dd3a12641 122 break;
cittecla 2:72886e996098 123
aeschsim 34:9d6dd3a12641 124 case 10:
aeschsim 34:9d6dd3a12641 125 break;
aeschsim 34:9d6dd3a12641 126 case 11:
aeschsim 34:9d6dd3a12641 127 break;
cittecla 2:72886e996098 128
aeschsim 34:9d6dd3a12641 129 case 15:
aeschsim 34:9d6dd3a12641 130 break;
aeschsim 34:9d6dd3a12641 131 case 16:
aeschsim 34:9d6dd3a12641 132 break;
aeschsim 34:9d6dd3a12641 133 case 17:
aeschsim 34:9d6dd3a12641 134 break;
aeschsim 34:9d6dd3a12641 135
aeschsim 34:9d6dd3a12641 136 case 25:
aeschsim 34:9d6dd3a12641 137 break;
aeschsim 34:9d6dd3a12641 138 case 26:
aeschsim 34:9d6dd3a12641 139 break;
aeschsim 34:9d6dd3a12641 140 case 27:
aeschsim 34:9d6dd3a12641 141 break;
aeschsim 34:9d6dd3a12641 142 case 28:
aeschsim 34:9d6dd3a12641 143 break;
cittecla 2:72886e996098 144
cittecla 2:72886e996098 145
aeschsim 34:9d6dd3a12641 146 case 35:
aeschsim 34:9d6dd3a12641 147 break;
aeschsim 34:9d6dd3a12641 148 case 36:
aeschsim 34:9d6dd3a12641 149 break;
aeschsim 34:9d6dd3a12641 150 case 37:
aeschsim 34:9d6dd3a12641 151 break;
aeschsim 34:9d6dd3a12641 152 case 38:
aeschsim 34:9d6dd3a12641 153 break;
aeschsim 27:bf0577ecfa6e 154
aeschsim 76:53a25f1dc2b6 155
aeschsim 40:b5e533e1e033 156 /**************************************************************/
aeschsim 40:b5e533e1e033 157 /* Test Zone */
itslinear 90:d0805b58b0ae 158
EHess 85:04fe3dff23f4 159 /* Speedtest Servo */
EHess 85:04fe3dff23f4 160 case 41:
EHess 85:04fe3dff23f4 161 setSpeed(1, 2);
EHess 85:04fe3dff23f4 162 wait(3);
EHess 85:04fe3dff23f4 163 setSpeed(1, 0);
EHess 85:04fe3dff23f4 164 wait(2);
EHess 85:04fe3dff23f4 165 setSpeed(1, 1);
EHess 85:04fe3dff23f4 166 wait(3);
EHess 85:04fe3dff23f4 167 state = 43;
EHess 85:04fe3dff23f4 168 break;
itslinear 90:d0805b58b0ae 169
EHess 83:d327a532c0ad 170 /* DutyCycle */
EHess 84:14ed3d02e782 171 case 42:
EHess 84:14ed3d02e782 172 printf("case 42:\r\n");
EHess 84:14ed3d02e782 173 initInterrupt();
EHess 84:14ed3d02e782 174 printf("initInterrupt\r\n");
EHess 84:14ed3d02e782 175 enableContainer(1);
itslinear 90:d0805b58b0ae 176 while(1) {
EHess 84:14ed3d02e782 177 printf("%i\r\n", getDutyCycle());
EHess 84:14ed3d02e782 178 printf("--- END ---\r\n");
EHess 84:14ed3d02e782 179 wait(0.2);
EHess 84:14ed3d02e782 180 }
EHess 84:14ed3d02e782 181 break;
itslinear 90:d0805b58b0ae 182
EHess 84:14ed3d02e782 183 /* Drehung 90° */
EHess 83:d327a532c0ad 184 case 43:
EHess 83:d327a532c0ad 185 printf("case 43:\r\n");
EHess 83:d327a532c0ad 186 initInterrupt();
EHess 83:d327a532c0ad 187 printf("initInterrupt\r\n");
EHess 83:d327a532c0ad 188 enableContainer(1);
itslinear 90:d0805b58b0ae 189 while(1) {
EHess 84:14ed3d02e782 190 nextPosition(1);
EHess 83:d327a532c0ad 191 printf("--- END ---\r\n");
EHess 85:04fe3dff23f4 192 wait(3);
EHess 83:d327a532c0ad 193 }
EHess 83:d327a532c0ad 194 break;
cittecla 53:1c61cadbcb35 195
cittecla 52:701d0c2f47d7 196 /* init PWM board */
cittecla 52:701d0c2f47d7 197 case 44:
cittecla 55:bdab541f434d 198 printf("Init PWM\r\n");
cittecla 53:1c61cadbcb35 199 initPWM(50);
cittecla 53:1c61cadbcb35 200 enableOutput();
EHess 85:04fe3dff23f4 201 state = 43;
cittecla 52:701d0c2f47d7 202 break;
aeschsim 40:b5e533e1e033 203
aeschsim 40:b5e533e1e033 204 /* Time test tool: set Time */
aeschsim 34:9d6dd3a12641 205 case 45:
aeschsim 34:9d6dd3a12641 206 s_time time;
aeschsim 34:9d6dd3a12641 207 time.second = 30;
aeschsim 34:9d6dd3a12641 208 time.minute = 53;
aeschsim 34:9d6dd3a12641 209 time.hour = 12;
aeschsim 34:9d6dd3a12641 210 time.day = 27;
aeschsim 34:9d6dd3a12641 211 time.weekday = 2;
aeschsim 34:9d6dd3a12641 212 time.month = 3;
aeschsim 34:9d6dd3a12641 213 time.year = 18;
cittecla 55:bdab541f434d 214 printf("set now time\r\n");
aeschsim 34:9d6dd3a12641 215 setTime(&time);
cittecla 55:bdab541f434d 216 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 217 state = 47;
cittecla 55:bdab541f434d 218 printf("change state to: %d\r\n",state);
aeschsim 34:9d6dd3a12641 219 break;
aeschsim 40:b5e533e1e033 220
aeschsim 40:b5e533e1e033 221 /* Time test tool: get Time */
aeschsim 34:9d6dd3a12641 222 case 46:
aeschsim 34:9d6dd3a12641 223 wait(5);
aeschsim 34:9d6dd3a12641 224 time = getTime();
cittecla 55:bdab541f434d 225 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 226 state = 47;
aeschsim 40:b5e533e1e033 227 break;
aeschsim 40:b5e533e1e033 228
aeschsim 40:b5e533e1e033 229 /* Console State Switch */
aeschsim 40:b5e533e1e033 230 case 47:
cittecla 55:bdab541f434d 231 printf("\n\rState Switch: Enter next State: \n\r");
aeschsim 76:53a25f1dc2b6 232 printf("45\tset Time\n\r46\tread Time\n\r47\tState Switch\n\r48\tServo Board Test Tool\n\r");
aeschsim 76:53a25f1dc2b6 233 printf("49\tenable servo output\n\r50\tdisable servo output\n\r");
aeschsim 76:53a25f1dc2b6 234 printf("51\ttest SD Card\n\r52\tread medication\n\r53\tMedication display test tool\n\r");
aeschsim 70:cc7ed2325202 235 printf("54\tWrite Medication\n\r55\tDemo Tool for Summer and RGB LED\n\r");
aeschsim 76:53a25f1dc2b6 236 printf("60\t \n\r");
aeschsim 76:53a25f1dc2b6 237 printf("61\t \n\r");
aeschsim 76:53a25f1dc2b6 238 printf("62\t \n\r");
aeschsim 40:b5e533e1e033 239 pc.scanf("%d", &state);
cittecla 55:bdab541f434d 240 printf("Switch to State %d\n\r",state);
aeschsim 40:b5e533e1e033 241 fflush(stdin);
aeschsim 34:9d6dd3a12641 242 break;
aeschsim 40:b5e533e1e033 243
aeschsim 40:b5e533e1e033 244 /* Servo-Board Test Tool */
aeschsim 34:9d6dd3a12641 245 case 48:
cittecla 55:bdab541f434d 246 printf("\n\r\n\rServo-Board Test Tool\n\rEnter Channel Number and then Duty Cycle\n\r");
cittecla 55:bdab541f434d 247 printf("for exit, enter Channel > 15\n\r");
aeschsim 40:b5e533e1e033 248 channel = 0;
aeschsim 40:b5e533e1e033 249 while (channel < 16) {
cittecla 55:bdab541f434d 250 printf("Channel Number: ");
aeschsim 40:b5e533e1e033 251 pc.scanf("%d", &channel);
cittecla 55:bdab541f434d 252 printf("\r\nchannel: %d\n\rDuty Cycle 0..4095: ",channel);
aeschsim 40:b5e533e1e033 253 pc.scanf("%d", &dutyCycle);
cittecla 55:bdab541f434d 254 printf("\n\r%d\n\r",dutyCycle);
aeschsim 46:cdc24a24e4e3 255 setPWM((char)channel, (int)dutyCycle);
aeschsim 40:b5e533e1e033 256 fflush(stdin);
aeschsim 40:b5e533e1e033 257 }
cittecla 55:bdab541f434d 258 printf("leave Servo-Board Test Tool\n\r");
aeschsim 40:b5e533e1e033 259 state = 47;
aeschsim 40:b5e533e1e033 260 break;
aeschsim 40:b5e533e1e033 261
aeschsim 40:b5e533e1e033 262 case 49:
cittecla 42:ba59ed6a2a06 263 enableOutput();
cittecla 55:bdab541f434d 264 printf("Servo output enabled\r\n\n");
aeschsim 40:b5e533e1e033 265 state = 47;
aeschsim 34:9d6dd3a12641 266 break;
cittecla 2:72886e996098 267
aeschsim 34:9d6dd3a12641 268 case 50:
cittecla 42:ba59ed6a2a06 269 disableOutput();
cittecla 55:bdab541f434d 270 printf("Servo output disabled\r\n\n");
aeschsim 40:b5e533e1e033 271 state = 47;
aeschsim 40:b5e533e1e033 272 break;
cittecla 53:1c61cadbcb35 273
cittecla 42:ba59ed6a2a06 274 case 51:
cittecla 52:701d0c2f47d7 275 testSd();
cittecla 55:bdab541f434d 276 printf("\rSD Card test finished\r\n\n");
cittecla 55:bdab541f434d 277 state = 47;
cittecla 55:bdab541f434d 278 break;
cittecla 58:cda5298c9b7f 279
cittecla 58:cda5298c9b7f 280
cittecla 55:bdab541f434d 281 case 52:
itslinear 73:7fd3701def5b 282 prescription[1] = readMedication(1);
itslinear 73:7fd3701def5b 283 if(prescription[1].valid) {
cittecla 56:218601547d13 284 printf("\rread successful\r\n\n");
cittecla 55:bdab541f434d 285 } else {
cittecla 55:bdab541f434d 286 printf("\rread failed\r\n\n");
cittecla 55:bdab541f434d 287 }
cittecla 42:ba59ed6a2a06 288 state = 47;
cittecla 53:1c61cadbcb35 289 break;
cittecla 55:bdab541f434d 290
cittecla 55:bdab541f434d 291 case 53:
itslinear 73:7fd3701def5b 292 if(prescription[1].valid == false) {
cittecla 57:79fed71031da 293 printf("\r\nNo valid data in struct, try to run case 52\r\n\n");
cittecla 55:bdab541f434d 294 } else {
cittecla 55:bdab541f434d 295 printf("\r\nMedication display test tool:\r\n");
cittecla 55:bdab541f434d 296 printf("Enter Day (0..6) and Moment (0..4)\r\nTo exit enter Day > 6:\r\n");
cittecla 55:bdab541f434d 297 day = 0;
cittecla 55:bdab541f434d 298 while (day < 7) {
cittecla 55:bdab541f434d 299 printf("\r\nDay Number: ");
cittecla 55:bdab541f434d 300 pc.scanf("%d", &day);
cittecla 55:bdab541f434d 301 if(day < 7) {
cittecla 55:bdab541f434d 302 printf("\r\nDay: %d\n\rMoment 0..3: ",day);
cittecla 55:bdab541f434d 303 pc.scanf("%d", &moment);
cittecla 55:bdab541f434d 304 printf("\r\nMedication for weekday %d Moment %d is ",day,moment);
cittecla 55:bdab541f434d 305 for(int i=0; i<6; i++) {
itslinear 73:7fd3701def5b 306 printf("%d", prescription[1].medication.day[day].moment[moment].medContainer.container[i]);
cittecla 55:bdab541f434d 307 }
itslinear 73:7fd3701def5b 308 printf("\r\nThe alarm clock is set for %02d:%02d",prescription[1].medication.day[day].moment[moment].time.hour,prescription[1].medication.day[day].moment[moment].time.minute);
cittecla 55:bdab541f434d 309 }
cittecla 55:bdab541f434d 310 printf("\r\n");
cittecla 55:bdab541f434d 311 fflush(stdin);
cittecla 55:bdab541f434d 312 }
cittecla 55:bdab541f434d 313 printf("exit Tool\n\r");
cittecla 55:bdab541f434d 314 }
cittecla 56:218601547d13 315 state = 47;
cittecla 56:218601547d13 316 break;
cittecla 58:cda5298c9b7f 317 case 54:
itslinear 73:7fd3701def5b 318 writeMedication(0,prescription[1]);
cittecla 58:cda5298c9b7f 319 state = 47;
cittecla 58:cda5298c9b7f 320 break;
aeschsim 59:1867088695f3 321 case 55:
aeschsim 59:1867088695f3 322 /* Demo Tool */
PESGruppe1 61:086bcd5ca968 323 enableOutput();
PESGruppe1 61:086bcd5ca968 324 printf("Servo output enabled\r\n\n");
aeschsim 70:cc7ed2325202 325 summer.period_us(500);
aeschsim 70:cc7ed2325202 326 summer.write(0.5f);
aeschsim 70:cc7ed2325202 327 wait(3);
aeschsim 70:cc7ed2325202 328 summer.write(0.0f);
PESGruppe1 61:086bcd5ca968 329
aeschsim 70:cc7ed2325202 330 userButton1.fall(&summ);
aeschsim 70:cc7ed2325202 331
aeschsim 70:cc7ed2325202 332 printf("Summer Interrupt on Button 0 enabled\n\r");
aeschsim 60:7554e4272b3b 333
PESGruppe1 61:086bcd5ca968 334 color = 0xFFFFFF;
PESGruppe1 61:086bcd5ca968 335 colorTime = 0;
PESGruppe1 61:086bcd5ca968 336 setLED(0,color);
PESGruppe1 61:086bcd5ca968 337 wait(5);
aeschsim 70:cc7ed2325202 338
aeschsim 70:cc7ed2325202 339 printf("start fading loop for DEMOTIME loops\n\r");
aeschsim 70:cc7ed2325202 340
aeschsim 59:1867088695f3 341 while(colorTime < DEMOTIME) {
PESGruppe1 61:086bcd5ca968 342 printf("fade1\n\r");
aeschsim 60:7554e4272b3b 343 for(r = 0; r <= 255; r++) {
aeschsim 59:1867088695f3 344 color &= 0x00FFFF;
PESGruppe1 61:086bcd5ca968 345 color |= (r<<16);
PESGruppe1 61:086bcd5ca968 346 setLED(0,color);
aeschsim 59:1867088695f3 347 wait_ms(FADESPEED);
aeschsim 59:1867088695f3 348 }
aeschsim 70:cc7ed2325202 349 printf("fade2\n\r");
aeschsim 60:7554e4272b3b 350 for(b = 255; b >= 0; b--) {
aeschsim 59:1867088695f3 351 color &= 0xFFFF00;
PESGruppe1 61:086bcd5ca968 352 color |= b;
PESGruppe1 61:086bcd5ca968 353 setLED(0,color);
aeschsim 59:1867088695f3 354 wait_ms(FADESPEED);
aeschsim 59:1867088695f3 355 }
aeschsim 70:cc7ed2325202 356 printf("fade3\n\r");
aeschsim 60:7554e4272b3b 357 for(g = 0; g <= 255; g++) {
aeschsim 59:1867088695f3 358 color &= 0xFF00FF;
PESGruppe1 61:086bcd5ca968 359 color |= (g<<8);
PESGruppe1 61:086bcd5ca968 360 setLED(0,color);
aeschsim 59:1867088695f3 361 wait_ms(FADESPEED);
aeschsim 59:1867088695f3 362 }
aeschsim 70:cc7ed2325202 363 printf("fade4\n\r");
aeschsim 59:1867088695f3 364 for(r = 255; r > 0; r--) {
aeschsim 59:1867088695f3 365 color &= 0x00FFFF;
PESGruppe1 61:086bcd5ca968 366 color |= (r<<16);
PESGruppe1 61:086bcd5ca968 367 setLED(0,color);
aeschsim 59:1867088695f3 368 wait_ms(FADESPEED);
aeschsim 59:1867088695f3 369 }
aeschsim 70:cc7ed2325202 370 printf("fade5\n\r");
aeschsim 59:1867088695f3 371 for(b = 0; b <= 255; b++) {
aeschsim 59:1867088695f3 372 color &= 0xFFFF00;
PESGruppe1 61:086bcd5ca968 373 color |= b;
PESGruppe1 61:086bcd5ca968 374 setLED(0,color);
aeschsim 59:1867088695f3 375 wait_ms(FADESPEED);
aeschsim 59:1867088695f3 376 }
aeschsim 70:cc7ed2325202 377 printf("fade6\n\r");
aeschsim 59:1867088695f3 378 for (g = 255; g > 0; g--) {
aeschsim 59:1867088695f3 379 color &= 0xFF00FF;
PESGruppe1 61:086bcd5ca968 380 color |= (g<<8);
PESGruppe1 61:086bcd5ca968 381 setLED(0,color);
aeschsim 59:1867088695f3 382 wait_ms(FADESPEED);
aeschsim 59:1867088695f3 383 }
aeschsim 59:1867088695f3 384 colorTime++;
aeschsim 59:1867088695f3 385 }
aeschsim 70:cc7ed2325202 386 printf("exit demo tool\n\r");
aeschsim 59:1867088695f3 387
aeschsim 59:1867088695f3 388 break;
itslinear 72:172b40dd16ee 389
itslinear 73:7fd3701def5b 390 case 60:
itslinear 73:7fd3701def5b 391 printf("write_medProtocol\n\r");
itslinear 72:172b40dd16ee 392 write_medProtocol(medicationTime, outputTime, medication, success, user);
itslinear 73:7fd3701def5b 393 printf("done\n\r");
itslinear 73:7fd3701def5b 394 state = 47;
itslinear 73:7fd3701def5b 395
itslinear 72:172b40dd16ee 396 break;
itslinear 72:172b40dd16ee 397
itslinear 73:7fd3701def5b 398 case 61:
itslinear 81:a869abf56e85 399 medInventory.currentTime = getTime();
itslinear 73:7fd3701def5b 400 printf("write_medInventory\n\r");
itslinear 80:6e3eb8246ced 401 //write_medInventory(medInventory,currentTime,med1,med2,med3,med4,med5,med6);
itslinear 80:6e3eb8246ced 402 write_medInventory(medInventory);
itslinear 73:7fd3701def5b 403 state = 47;
itslinear 72:172b40dd16ee 404
itslinear 73:7fd3701def5b 405 break;
itslinear 72:172b40dd16ee 406
itslinear 73:7fd3701def5b 407 case 62:
itslinear 73:7fd3701def5b 408 printf("write_medError\n\r");
itslinear 81:a869abf56e85 409 write_medError(fail, medicationTime);
itslinear 73:7fd3701def5b 410 state = 47;
itslinear 72:172b40dd16ee 411
itslinear 73:7fd3701def5b 412 break;
itslinear 72:172b40dd16ee 413
itslinear 77:c2e22d1e5d44 414 case 63:
itslinear 77:c2e22d1e5d44 415 printf("erase_errorPotocol\n\r");
itslinear 77:c2e22d1e5d44 416 erase_medError();
itslinear 77:c2e22d1e5d44 417 state = 47;
aeschsim 79:c825bd2dea81 418
itslinear 77:c2e22d1e5d44 419 break;
itslinear 72:172b40dd16ee 420
itslinear 77:c2e22d1e5d44 421 case 64:
itslinear 77:c2e22d1e5d44 422 printf("erase_medPotocol\n\r");
itslinear 77:c2e22d1e5d44 423 erase_medProtocol();
itslinear 77:c2e22d1e5d44 424 state = 47;
aeschsim 79:c825bd2dea81 425
itslinear 77:c2e22d1e5d44 426 break;
aeschsim 79:c825bd2dea81 427
aeschsim 82:2fc026430ff2 428
itslinear 80:6e3eb8246ced 429 case 65:
itslinear 80:6e3eb8246ced 430 printf("read_medPotocol\n\r");
itslinear 80:6e3eb8246ced 431 send = read_medProtocol(user);
itslinear 80:6e3eb8246ced 432 printf("%s", send);
itslinear 80:6e3eb8246ced 433 state = 47;
itslinear 80:6e3eb8246ced 434
itslinear 77:c2e22d1e5d44 435 break;
itslinear 80:6e3eb8246ced 436
itslinear 80:6e3eb8246ced 437 case 66:
itslinear 80:6e3eb8246ced 438 printf("read_medInventory\n\r");
itslinear 80:6e3eb8246ced 439 medInventory = read_medInventory();
itslinear 80:6e3eb8246ced 440 printf("done\r\n");
itslinear 81:a869abf56e85 441 printf("%s\r\n%d\r\n%s\r\n%d\r\n%s\r\n%d\r\n%s\r\n%d\r\n%s\r\n%d\r\n%s\r\n%d\r\n", medInventory.pill[0], medInventory.medContainer.container[0], medInventory.pill[1], medInventory.medContainer.container[1], medInventory.pill[2], medInventory.medContainer.container[2], medInventory.pill[3], medInventory.medContainer.container[3], medInventory.pill[4], medInventory.medContainer.container[4], medInventory.pill[5], medInventory.medContainer.container[5]);
itslinear 80:6e3eb8246ced 442 state = 47;
itslinear 81:a869abf56e85 443
itslinear 81:a869abf56e85 444 break;
itslinear 81:a869abf56e85 445
itslinear 81:a869abf56e85 446 case 67:
itslinear 81:a869abf56e85 447 printf("read_medError\n\r");
itslinear 81:a869abf56e85 448 send = read_medError();
itslinear 81:a869abf56e85 449 printf("%s", send);
itslinear 81:a869abf56e85 450 state = 47;
itslinear 81:a869abf56e85 451
itslinear 80:6e3eb8246ced 452 break;
itslinear 80:6e3eb8246ced 453
itslinear 90:d0805b58b0ae 454 case 68:
itslinear 90:d0805b58b0ae 455 printf("read_Inventory\n\r");
itslinear 90:d0805b58b0ae 456 send = read_Inventory();
itslinear 90:d0805b58b0ae 457 printf("%s", send);
itslinear 90:d0805b58b0ae 458 state = 47;
itslinear 90:d0805b58b0ae 459
itslinear 90:d0805b58b0ae 460 break;
itslinear 90:d0805b58b0ae 461
aeschsim 40:b5e533e1e033 462 default:
aeschsim 40:b5e533e1e033 463 state = 47; /* Go to State Switch */
aeschsim 34:9d6dd3a12641 464 break;
aeschsim 34:9d6dd3a12641 465 }
cittecla 2:72886e996098 466 }
cittecla 55:bdab541f434d 467 printf("exit while 1 loop");
cittecla 2:72886e996098 468 }