248 if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF)) |
248 if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF)) |
249 initlog(current_unit->name); |
249 initlog(current_unit->name); |
250 syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]); |
250 syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]); |
251 current_unit->mode = mode; |
251 current_unit->mode = mode; |
252 /* Allways turn everything off after a mode change */ |
252 /* Allways turn everything off after a mode change */ |
253 current_unit->PID_I_err = current_unit->PID_err_old = 0.0; |
253 current_unit->PID_iState = current_unit->PID_dState = 0.0; |
254 current_unit->heater_state = current_unit->cooler_state = current_unit->fan_state = 0; |
254 current_unit->heater_state = current_unit->cooler_state = current_unit->fan_state = 0; |
255 current_unit->heater_wait = current_unit->cooler_wait = current_unit->fan_wait = 0; |
255 current_unit->heater_wait = current_unit->cooler_wait = current_unit->fan_wait = 0; |
256 device_out(current_unit->heater_address, current_unit->heater_state); |
256 device_out(current_unit->heater_address, current_unit->heater_state); |
257 device_out(current_unit->cooler_address, current_unit->cooler_state); |
257 device_out(current_unit->cooler_address, current_unit->cooler_state); |
258 device_out(current_unit->fan_address, current_unit->fan_state); |
258 device_out(current_unit->fan_address, current_unit->fan_state); |
1349 Out = pTerm + dTerm + iTerm; |
1349 Out = pTerm + dTerm + iTerm; |
1350 if (Out > 100.0) |
1350 if (Out > 100.0) |
1351 Out = 100.0; |
1351 Out = 100.0; |
1352 if (Out < -100.0) |
1352 if (Out < -100.0) |
1353 Out = -100.0; |
1353 Out = -100.0; |
1354 // if /* (P_err != 0.0) */ (i == 1) { |
1354 if (debug) |
1355 if (debug) |
1355 fprintf(stdout, "sp=%.2f pv=%.2f dState=%.2f P_err=%.2f iState=%.2f Out=%.2f\n", |
1356 fprintf(stdout, "sp=%.2f pv=%.2f err_old=%.2f P_err=%.2f I_err=%.2f Out=%.2f\n", |
1356 sp, pv, unit->PID_dState, P_err, unit->PID_iState, Out); |
1357 sp, pv, unit->PID_err_old, P_err, unit->PID_I_err, Out); |
1357 syslog(LOG_NOTICE, "sp=%.2f pv=%.2f dState=%.2f P_err=%.2f iState=%.2f Out=%.2f pTerm=%.2f iTerm=%.2f dTerm=%.2f, N=%.2f", |
1358 syslog(LOG_NOTICE, "sp=%.2f pv=%.2f err_old=%.2f P_err=%.2f I_err=%.2f Out=%.2f pTerm=%.2f iTerm=%.2f dTerm=%.2f, N=%.2f", |
1358 sp, pv, unit->PID_dState, P_err, unit->PID_iState, Out, pTerm, iTerm, dTerm, pTerm + dTerm + iTerm); |
1359 sp, pv, unit->PID_err_old, P_err, unit->PID_I_err, Out, pTerm, iTerm, dTerm, pTerm + dTerm + iTerm); |
1359 unit->PID_dState = pv; |
1360 // } |
|
1361 unit->PID_err_old = P_err; |
|
1362 |
1360 |
1363 if (unit->heater_address) { |
1361 if (unit->heater_address) { |
1364 if (Out >= 1) { |
1362 if (Out >= 1) { |
1365 if (unit->heater_wait < unit->heater_delay) { |
1363 if (unit->heater_wait < unit->heater_delay) { |
1366 unit->heater_wait++; |
1364 unit->heater_wait++; |
1367 syslog(LOG_NOTICE, "heater_wait + %d/%d", unit->heater_wait, unit->heater_delay); |
1365 syslog(LOG_NOTICE, "heater_wait + %d/%d", unit->heater_wait, unit->heater_delay); |
1368 } else { |
1366 } else { |
1369 if (! unit->heater_state && ! unit->cooler_state) { |
1367 if (! unit->heater_state && ! unit->cooler_state) { |
1370 syslog(LOG_NOTICE, "Heater Off => On"); |
1368 syslog(LOG_NOTICE, "Heater Off => On"); |
1371 unit->heater_state = 100; |
1369 unit->heater_state = 100; |
1372 } |
|
1373 } |
1370 } |
|
1371 } |
|
1372 } else { |
|
1373 if (unit->heater_wait > 0) { |
|
1374 unit->heater_wait--; |
|
1375 syslog(LOG_NOTICE, "heater_wait - %d/%d", unit->heater_wait, unit->heater_delay); |
1374 } else { |
1376 } else { |
1375 if (unit->heater_wait > 0) { |
1377 if (unit->heater_state) { |
1376 unit->heater_wait--; |
1378 syslog(LOG_NOTICE, "Heater On => Off"); |
1377 syslog(LOG_NOTICE, "heater_wait - %d/%d", unit->heater_wait, unit->heater_delay); |
1379 unit->heater_state = 0; |
1378 } else { |
|
1379 if (unit->heater_state) { |
|
1380 syslog(LOG_NOTICE, "Heater On => Off"); |
|
1381 unit->heater_state = 0; |
|
1382 } |
|
1383 } |
1380 } |
1384 } |
1381 } |
1385 device_out(unit->heater_address, unit->heater_state); |
1382 } |
|
1383 device_out(unit->heater_address, unit->heater_state); |
1386 } |
1384 } |
1387 if (unit->cooler_address) { |
1385 if (unit->cooler_address) { |
1388 if (Out <= -1) { |
1386 if (Out <= -1) { |
1389 if (unit->cooler_wait < unit->cooler_delay) { |
1387 if (unit->cooler_wait < unit->cooler_delay) { |
1390 unit->cooler_wait++; |
1388 unit->cooler_wait++; |
1391 syslog(LOG_NOTICE, "cooler_wait + %d/%d", unit->cooler_wait, unit->cooler_delay); |
1389 syslog(LOG_NOTICE, "cooler_wait + %d/%d", unit->cooler_wait, unit->cooler_delay); |
1392 } else { |
1390 } else { |
1393 if (! unit->cooler_state && ! unit->heater_state) { |
1391 if (! unit->cooler_state && ! unit->heater_state) { |
1394 syslog(LOG_NOTICE, "Cooler Off => On"); |
1392 syslog(LOG_NOTICE, "Cooler Off => On"); |
1395 unit->cooler_state = 100; |
1393 unit->cooler_state = 100; |
1396 } |
|
1397 } |
1394 } |
|
1395 } |
|
1396 } else { |
|
1397 if (unit->cooler_wait > 0) { |
|
1398 unit->cooler_wait--; |
|
1399 syslog(LOG_NOTICE, "cooler_wait - %d/%d", unit->cooler_wait, unit->cooler_delay); |
1398 } else { |
1400 } else { |
1399 if (unit->cooler_wait > 0) { |
1401 if (unit->cooler_state) { |
1400 unit->cooler_wait--; |
1402 syslog(LOG_NOTICE, "Cooler On => Off"); |
1401 syslog(LOG_NOTICE, "cooler_wait - %d/%d", unit->cooler_wait, unit->cooler_delay); |
1403 unit->cooler_state = 0; |
1402 } else { |
|
1403 if (unit->cooler_state) { |
|
1404 syslog(LOG_NOTICE, "Cooler On => Off"); |
|
1405 unit->cooler_state = 0; |
|
1406 } |
|
1407 } |
1404 } |
1408 } |
1405 } |
1409 device_out(unit->cooler_address, unit->cooler_state); |
1406 } |
|
1407 device_out(unit->cooler_address, unit->cooler_state); |
1410 } |
1408 } |
1411 if (unit->heater_address && unit->cooler_address && unit->fan_address) { |
1409 if (unit->heater_address && unit->cooler_address && unit->fan_address) { |
1412 /* |
1410 /* |
1413 * If the temperature difference between air and beer is more then |
1411 * If the temperature difference between air and beer is more then |
1414 * xxx degrees, turn the fan on to make an airflow. |
1412 * xxx degrees, turn the fan on to make an airflow. |
1415 * Maybe, run the fan too if the heater is on because the heater in |
1413 * Maybe, run the fan too if the heater is on because the heater in |
1416 * most cases will be some sort of radiating heat device. |
1414 * most cases will be some sort of radiating heat device. |
1417 * For cooling ??? dunno yet. |
1415 * For cooling ??? dunno yet. |
1418 */ |
1416 */ |
1419 if (((unit->air_temperature - unit->beer_temperature) > 1000) || |
1417 if (((unit->air_temperature - unit->beer_temperature) > 1000) || |
1420 ((unit->air_temperature - unit->beer_temperature) < -1000)) { |
1418 ((unit->air_temperature - unit->beer_temperature) < -1000)) { |
1421 if (! unit->fan_state) |
1419 if (! unit->fan_state) |
1422 syslog(LOG_NOTICE, "Fan Off => On"); |
1420 syslog(LOG_NOTICE, "Fan Off => On"); |
1423 unit->fan_state = 100; |
1421 unit->fan_state = 100; |
1424 } else { |
1422 } else { |
1425 if (unit->fan_state) |
1423 if (unit->fan_state) |
1426 syslog(LOG_NOTICE, "Fan On => Off"); |
1424 syslog(LOG_NOTICE, "Fan On => Off"); |
1427 unit->fan_state = 0; |
1425 unit->fan_state = 0; |
1428 } |
1426 } |
1429 device_out(unit->fan_address, unit->fan_state); |
1427 device_out(unit->fan_address, unit->fan_state); |
1430 } |
1428 } |
1431 } else { |
1429 } else { |
1432 P_err = 0.0; |
1430 P_err = 0.0; |
1433 unit->PID_I_err = 0.0; |
1431 unit->PID_iState = 0.0; |
1434 unit->PID_err_old = 0.0; |
1432 unit->PID_dState = 0.0; |
1435 } |
1433 } |
1436 } |
1434 } |
1437 |
1435 |
1438 #ifdef HAVE_WIRINGPI_H |
1436 #ifdef HAVE_WIRINGPI_H |
1439 piLock(LOCK_MENU); |
1437 piLock(LOCK_MENU); |