hal.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * hal.h
  3. *
  4. * Created on: Aug 3, 2016
  5. * Author: sebastian
  6. */
  7. #ifndef HAL_H_
  8. #define HAL_H_
  9. #include "events.h"
  10. //these are the wPi numberings
  11. #define RELAIS_HEAT 29
  12. #define RELAIS_PUMP 25
  13. #define RELAIS_POWER 28
  14. #define PIN_PRESSURE_CTRL 7
  15. #define PIN_PROXIMITY_SENSOR 6
  16. #define PIN_INT0 2 // Top button
  17. #define PIN_INT1 0 // Bottom button
  18. #define PIN_FLOW 3 // Flow sensor
  19. #define PIN_DISP 4
  20. #define FLOW_ML_PULSE (1000.0/2219) // Flow sensor: volume (ml) per pulse
  21. #define PIN_ROTARY1 15
  22. #define PIN_ROTARY2 16
  23. #define ROTARY_RESOLUTION 127
  24. #define ROTARY_STEPSIZE 15
  25. #define TIME_FLOWRESET 600 //Wait time in ms to reset flow counter after the last received flow signal
  26. #define TIME_BUTTONLONGPRESS 3 //Time in s until a Signal for a long pressed button is sent
  27. #define BREW_MANUAL_TRIGGER 7500 //specifies the ms after which a brew_manual signal is triggered
  28. /*
  29. * Explanation for the signal levels
  30. * SigInt_Psh Button is pushed
  31. * SigInt_Rls Button is released
  32. * SigInt_RlsLong Button is pressed for more than TIME_BUTTONLONGPRESS seconds
  33. * SigPressCls Pressure control is closed, System is heating
  34. * SigPressOpn Pressure control is open, heating is off
  35. * SigProxOpn Proximity Sensor is uncovered
  36. * SigProxCvrd Proximity Sensor is covered
  37. */
  38. /*
  39. * Functions of the buttons, the letter in brackets defines if the event is triggered
  40. * on push(P), release(R) or long pressing(RLong) of the button
  41. * TOP Button: Turn machine on(R), start brewing(P),
  42. *
  43. * BOTTOM button: Stop brewing immediately(P), Turn machine off(RLong),
  44. */
  45. enum HalSig {
  46. SigInt0Psh = 1,
  47. SigInt0Rls = 2,
  48. SigInt0RlsLong = 3,
  49. SigInt1Psh = 4,
  50. SigInt1Rls = 5,
  51. SigInt1RlsLong = 6,
  52. SigPressCls = 7,
  53. SigPressOpn = 8,
  54. SigProxOpn = 9,
  55. SigProxCvrd = 10,
  56. SigBrewOn = 11,
  57. SigBrewOff = 12,
  58. SigPowerUp = 13,
  59. SigPowerDown = 14,
  60. SigRotCW = 15,
  61. SigRotCCW = 16
  62. };
  63. extern const char* SigName[];
  64. void halInit(void);
  65. void halDisplayOff();
  66. void halDisplayOn();
  67. void halRelaisOn(int relais);
  68. void halRelaisOff(int relais);
  69. void halRelaisSet(int relais, int state);
  70. int halGetRelaisState(int relais);
  71. void halIntRotary(void);
  72. void halInt0(void);
  73. void halInt1(void);
  74. void flowResetTimerHandler(void);
  75. void halFlowTimerHandler(void);
  76. void halIntFlow(void);
  77. void halIntPressure(void);
  78. void halStartHeatingTime(void);
  79. void halStopHeatingTime(void);
  80. void halIntProximity(void);
  81. uint64_t halGetTotalHeatingTime(void);
  82. void halSetTotalHeatingTime(uint64_t newTime);
  83. float halGetFlow(void);
  84. uint16_t halGetFlowTime(void);
  85. float halGetLastFlow(void);
  86. uint16_t halGetLastFlowTime(void);
  87. uint16_t halGetFlowResetTime(void);
  88. void halSetFlowResetTime(uint16_t val);
  89. void halResetFlow(void);
  90. bool halIsHeating(void);
  91. bool halProxSensorCovered(void);
  92. int halGetInt0(void);
  93. int halGetInt1(void);
  94. void halSendSignal(HalSig value);
  95. void halMachineOn(void);
  96. void halMachineOff(void);
  97. void halInt0TimerHandler(void);
  98. void halInt1TimerHandler(void);
  99. void halIdleTimerHandler(void);
  100. void halEnterIdle(void);
  101. void halLeaveIdle(void);
  102. bool halIdle(HalSig value);
  103. void halResetIdleTimer(void);
  104. void halPumpOn();
  105. void halPumpOff(void);
  106. void timespec_diff(timespec *start, timespec *stop, timespec *result);
  107. void halTerminate(event_t *event);
  108. void halWriteBackCache(void);
  109. #endif /* HAL_H_ */