246 int server(void) |
246 int server(void) |
247 { |
247 { |
248 char buf[1024], *filename, target[40], heater[40], cooler[40], fan[40], door[40]; |
248 char buf[1024], *filename, target[40], heater[40], cooler[40], fan[40], door[40]; |
249 time_t now, last = (time_t)0; |
249 time_t now, last = (time_t)0; |
250 units_list *unit; |
250 units_list *unit; |
|
251 profiles_list *profile; |
|
252 prof_step *step; |
251 int rc, run = 1, seconds = 0, minutes = 0, piddelay = 0, temp, deviation; |
253 int rc, run = 1, seconds = 0, minutes = 0, piddelay = 0, temp, deviation; |
|
254 int run_seconds, run_minutes, run_hours; |
252 float err = 0.0, sp, pv, P_err, D_err, Out; |
255 float err = 0.0, sp, pv, P_err, D_err, Out; |
253 #ifdef HAVE_WIRINGPI_H |
256 #ifdef HAVE_WIRINGPI_H |
254 struct tm *tm; |
257 struct tm *tm; |
255 int row; |
258 int row; |
256 #else |
259 #else |
419 /* |
422 /* |
420 * unit->profile - uuid of the selected profile. |
423 * unit->profile - uuid of the selected profile. |
421 * unit->prof_started - start time or 0 if not yet running. |
424 * unit->prof_started - start time or 0 if not yet running. |
422 * unit->prof_state - PROFILE_OFF|PROFILE_PAUSE|PROFILE_RUN|PROFILE_DONE |
425 * unit->prof_state - PROFILE_OFF|PROFILE_PAUSE|PROFILE_RUN|PROFILE_DONE |
423 * unit->prof_target - Calculated target temperature. |
426 * unit->prof_target - Calculated target temperature. |
|
427 * unit->prof_paused - Internal pause counter. |
424 */ |
428 */ |
425 // off. Target is ?? |
429 for (profile = Config.profiles; profile; profile = profile->next) { |
426 // pause Target is keep target. |
430 if (strcmp(unit->profile, profile->uuid) == 0) { |
427 // run. Target must be calculated using steps. |
431 /* |
428 // done. Target is last target. |
432 * Set initial temperature for this profile. |
|
433 */ |
|
434 switch (unit->prof_state) { |
|
435 case PROFILE_OFF: |
|
436 /* |
|
437 * Setup initial temperature. |
|
438 */ |
|
439 unit->prof_target = profile->inittemp; |
|
440 break; |
|
441 case PROFILE_PAUSE: |
|
442 /* |
|
443 * Keep current temperature, measure pause time. |
|
444 */ |
|
445 break; |
|
446 case PROFILE_RUN: |
|
447 /* |
|
448 * Calculate current profile step en desired temperature. |
|
449 * When all done, set state to PROFILE_DONE. |
|
450 */ |
|
451 run_seconds = (int)(now - unit->prof_started - unit->prof_paused); |
|
452 run_minutes = run_seconds / 60; |
|
453 run_hours = run_minutes / 60; |
|
454 if (debug) |
|
455 fprintf(stdout, "run_hours=%d minutes=%d seconds=%d\n", run_hours, run_minutes, run_seconds); |
|
456 |
|
457 for (step = profile->steps; step; step = step->next) { |
|
458 } |
|
459 break; |
|
460 case PROFILE_DONE: |
|
461 /* |
|
462 * Keep this state. |
|
463 */ |
|
464 break; |
|
465 } /* switch */ |
|
466 } |
|
467 } |
429 } |
468 } |
430 |
469 |
431 /* |
470 /* |
432 * Manual switching |
471 * Manual switching |
433 */ |
472 */ |