portexpander.ino 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifdef ENABLE_I2C_PORTEXPANDER
  2. void portexpander_setup() {
  3. #ifdef FIRMWARE_VARIANT_HEATCONTROL
  4. pcf8574.pinMode(P0, OUTPUT, HIGH); // LED red, status testmode active
  5. pcf8574.pinMode(P1, OUTPUT, HIGH); // LED red, status heating locked
  6. pcf8574.pinMode(P2, INPUT_PULLUP); // switch input - bypass control for heating
  7. pcf8574.pinMode(P3, INPUT_PULLUP); // switch input - bypass control for pump
  8. pcf8574.pinMode(P4, INPUT_PULLUP); // input status heating active (return line)
  9. pcf8574.pinMode(P5, INPUT_PULLUP); // input heat request from room thermostat
  10. pcf8574.pinMode(P6, OUTPUT, HIGH); // output - control pump
  11. pcf8574.pinMode(P7, OUTPUT, HIGH); // output - control heating
  12. #else
  13. pcf8574.pinMode(P0, INPUT_PULLUP);
  14. pcf8574.pinMode(P1, INPUT_PULLUP);
  15. pcf8574.pinMode(P2, INPUT_PULLUP);
  16. pcf8574.pinMode(P3, INPUT_PULLUP);
  17. pcf8574.pinMode(P4, INPUT_PULLUP);
  18. pcf8574.pinMode(P5, INPUT_PULLUP);
  19. pcf8574.pinMode(P6, INPUT_PULLUP);
  20. pcf8574.pinMode(P7, INPUT_PULLUP);
  21. #endif
  22. sendLog(F("PCF8574 init..."));
  23. if (pcf8574.begin())
  24. {
  25. sendLog(F(" OK"));
  26. }
  27. else
  28. {
  29. sendLog(F(" ERROR"));
  30. }
  31. }
  32. void portexpander_readInputs() {
  33. PCF8574::DigitalInput _di = pcf8574.digitalReadAll();
  34. #ifdef FIRMWARE_VARIANT_HEATCONTROL
  35. // read inputs - inverse logic as active is LOW...
  36. bool _changes = false;
  37. if(heatcontrol_in_sw_disableControl_heating != !_di.p2) {
  38. heatcontrol_in_sw_disableControl_heating = !_di.p2;
  39. heatcontrol_publish_sw_disableControl_heating();
  40. _changes = true;
  41. }
  42. if(heatcontrol_in_sw_disableControl_pump != !_di.p3) {
  43. heatcontrol_in_sw_disableControl_pump = !_di.p3;
  44. heatcontrol_publish_sw_disableControl_pump();
  45. _changes = true;
  46. }
  47. if(heatcontrol_in_heat_active != !_di.p4) {
  48. heatcontrol_in_heat_active = !_di.p4;
  49. heatcontrol_publish_in_heat_active();
  50. _changes = true;
  51. }
  52. if(heatcontrol_in_heat_request != !_di.p5) {
  53. heatcontrol_in_heat_request = !_di.p5;
  54. heatcontrol_publish_in_heat_request();
  55. _changes = true;
  56. }
  57. if(_changes && debug > 0) {
  58. snprintf(logBuf, LOG_BUFFER_SIZE, "PCF8574 inputs changed: SW_H_DIR=%d, SW_P_DIR=%d, STAT_HEAT=%d, IN_RT=%d", heatcontrol_in_sw_disableControl_heating, heatcontrol_in_sw_disableControl_pump, heatcontrol_in_heat_active, heatcontrol_in_heat_request);
  59. sendLog(logBuf, LOGLEVEL_DEBUG);
  60. }
  61. #endif
  62. }
  63. void portexpander_toggleOutputs() {
  64. #ifdef FIRMWARE_VARIANT_HEATCONTROL
  65. heatcontrol_out_stat_testmode = !heatcontrol_out_stat_testmode;
  66. pcf8574.digitalWrite(P0, heatcontrol_out_stat_testmode);
  67. heatcontrol_out_stat_locked = !heatcontrol_out_stat_locked;
  68. pcf8574.digitalWrite(P1, heatcontrol_out_stat_locked);
  69. heatcontrol_out_heat = !heatcontrol_out_heat;
  70. pcf8574.digitalWrite(P6, heatcontrol_out_heat);
  71. heatcontrol_out_pump = !heatcontrol_out_pump;
  72. pcf8574.digitalWrite(P7, heatcontrol_out_pump);
  73. #endif
  74. }
  75. #endif