Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
7.6 KiB

  1. /*
  2. BUTTON MODULE
  3. */
  4. #pragma once
  5. namespace ButtonMask {
  6. enum {
  7. Pushbutton = 1 << 0,
  8. Switch = 1 << 1,
  9. DefaultHigh = 1 << 2,
  10. SetPullup = 1 << 3,
  11. SetPulldown = 1 << 4
  12. };
  13. } // namespace ButtonMask
  14. constexpr const unsigned char _buttonPin(unsigned char index) {
  15. return (
  16. (index == 0) ? BUTTON1_PIN :
  17. (index == 1) ? BUTTON2_PIN :
  18. (index == 2) ? BUTTON3_PIN :
  19. (index == 3) ? BUTTON4_PIN :
  20. (index == 4) ? BUTTON5_PIN :
  21. (index == 5) ? BUTTON6_PIN :
  22. (index == 6) ? BUTTON7_PIN :
  23. (index == 7) ? BUTTON8_PIN : GPIO_NONE
  24. );
  25. }
  26. constexpr const unsigned char _buttonConfigBitmask(unsigned char index) {
  27. return (
  28. (index == 0) ? (BUTTON1_CONFIG) :
  29. (index == 1) ? (BUTTON2_CONFIG) :
  30. (index == 2) ? (BUTTON3_CONFIG) :
  31. (index == 3) ? (BUTTON4_CONFIG) :
  32. (index == 4) ? (BUTTON5_CONFIG) :
  33. (index == 5) ? (BUTTON6_CONFIG) :
  34. (index == 6) ? (BUTTON7_CONFIG) :
  35. (index == 7) ? (BUTTON8_CONFIG) : (BUTTON_PUSHBUTTON | BUTTON_SET_PULLUP | BUTTON_DEFAULT_HIGH)
  36. );
  37. }
  38. constexpr const unsigned char _buttonPress(unsigned char index) {
  39. return (
  40. (index == 0) ? BUTTON1_PRESS :
  41. (index == 1) ? BUTTON2_PRESS :
  42. (index == 2) ? BUTTON3_PRESS :
  43. (index == 3) ? BUTTON4_PRESS :
  44. (index == 4) ? BUTTON5_PRESS :
  45. (index == 5) ? BUTTON6_PRESS :
  46. (index == 6) ? BUTTON7_PRESS :
  47. (index == 7) ? BUTTON8_PRESS : BUTTON_ACTION_NONE
  48. );
  49. }
  50. constexpr const unsigned char _buttonClick(unsigned char index) {
  51. return (
  52. (index == 0) ? BUTTON1_CLICK :
  53. (index == 1) ? BUTTON2_CLICK :
  54. (index == 2) ? BUTTON3_CLICK :
  55. (index == 3) ? BUTTON4_CLICK :
  56. (index == 4) ? BUTTON5_CLICK :
  57. (index == 5) ? BUTTON6_CLICK :
  58. (index == 6) ? BUTTON7_CLICK :
  59. (index == 7) ? BUTTON8_CLICK : BUTTON_ACTION_NONE
  60. );
  61. }
  62. constexpr const unsigned char _buttonDoubleClick(unsigned char index) {
  63. return (
  64. (index == 0) ? BUTTON1_DBLCLICK :
  65. (index == 1) ? BUTTON2_DBLCLICK :
  66. (index == 2) ? BUTTON3_DBLCLICK :
  67. (index == 3) ? BUTTON4_DBLCLICK :
  68. (index == 4) ? BUTTON5_DBLCLICK :
  69. (index == 5) ? BUTTON6_DBLCLICK :
  70. (index == 6) ? BUTTON7_DBLCLICK :
  71. (index == 7) ? BUTTON8_DBLCLICK : BUTTON_ACTION_NONE
  72. );
  73. }
  74. constexpr const unsigned char _buttonTripleClick(unsigned char index) {
  75. return (
  76. (index == 0) ? BUTTON1_TRIPLECLICK :
  77. (index == 1) ? BUTTON2_TRIPLECLICK :
  78. (index == 2) ? BUTTON3_TRIPLECLICK :
  79. (index == 3) ? BUTTON4_TRIPLECLICK :
  80. (index == 4) ? BUTTON5_TRIPLECLICK :
  81. (index == 5) ? BUTTON6_TRIPLECLICK :
  82. (index == 6) ? BUTTON7_TRIPLECLICK :
  83. (index == 7) ? BUTTON8_TRIPLECLICK : BUTTON_ACTION_NONE
  84. );
  85. }
  86. constexpr const unsigned char _buttonLongClick(unsigned char index) {
  87. return (
  88. (index == 0) ? BUTTON1_LNGCLICK :
  89. (index == 1) ? BUTTON2_LNGCLICK :
  90. (index == 2) ? BUTTON3_LNGCLICK :
  91. (index == 3) ? BUTTON4_LNGCLICK :
  92. (index == 4) ? BUTTON5_LNGCLICK :
  93. (index == 5) ? BUTTON6_LNGCLICK :
  94. (index == 6) ? BUTTON7_LNGCLICK :
  95. (index == 7) ? BUTTON8_LNGCLICK : BUTTON_ACTION_NONE
  96. );
  97. }
  98. constexpr const unsigned char _buttonLongLongClick(unsigned char index) {
  99. return (
  100. (index == 0) ? BUTTON1_LNGLNGCLICK :
  101. (index == 1) ? BUTTON2_LNGLNGCLICK :
  102. (index == 2) ? BUTTON3_LNGLNGCLICK :
  103. (index == 3) ? BUTTON4_LNGLNGCLICK :
  104. (index == 4) ? BUTTON5_LNGLNGCLICK :
  105. (index == 5) ? BUTTON6_LNGLNGCLICK :
  106. (index == 6) ? BUTTON7_LNGLNGCLICK :
  107. (index == 7) ? BUTTON8_LNGLNGCLICK : BUTTON_ACTION_NONE
  108. );
  109. }
  110. constexpr const unsigned char _buttonRelay(unsigned char index) {
  111. return (
  112. (index == 0) ? (BUTTON1_RELAY - 1) :
  113. (index == 1) ? (BUTTON2_RELAY - 1) :
  114. (index == 2) ? (BUTTON3_RELAY - 1) :
  115. (index == 3) ? (BUTTON4_RELAY - 1) :
  116. (index == 4) ? (BUTTON5_RELAY - 1) :
  117. (index == 5) ? (BUTTON6_RELAY - 1) :
  118. (index == 6) ? (BUTTON7_RELAY - 1) :
  119. (index == 7) ? (BUTTON8_RELAY - 1) : RELAY_NONE
  120. );
  121. }
  122. constexpr const unsigned long _buttonDebounceDelay() {
  123. return BUTTON_DEBOUNCE_DELAY;
  124. }
  125. constexpr const unsigned long _buttonDebounceDelay(unsigned char index) {
  126. return (
  127. (index == 0) ? BUTTON1_DEBOUNCE_DELAY :
  128. (index == 1) ? BUTTON2_DEBOUNCE_DELAY :
  129. (index == 2) ? BUTTON3_DEBOUNCE_DELAY :
  130. (index == 3) ? BUTTON4_DEBOUNCE_DELAY :
  131. (index == 4) ? BUTTON5_DEBOUNCE_DELAY :
  132. (index == 5) ? BUTTON6_DEBOUNCE_DELAY :
  133. (index == 6) ? BUTTON7_DEBOUNCE_DELAY :
  134. (index == 7) ? BUTTON8_DEBOUNCE_DELAY : _buttonDebounceDelay()
  135. );
  136. }
  137. constexpr const unsigned long _buttonRepeatDelay() {
  138. return BUTTON_REPEAT_DELAY;
  139. }
  140. constexpr const unsigned long _buttonRepeatDelay(unsigned char index) {
  141. return (
  142. (index == 0) ? BUTTON1_REPEAT_DELAY :
  143. (index == 1) ? BUTTON2_REPEAT_DELAY :
  144. (index == 2) ? BUTTON3_REPEAT_DELAY :
  145. (index == 3) ? BUTTON4_REPEAT_DELAY :
  146. (index == 4) ? BUTTON5_REPEAT_DELAY :
  147. (index == 5) ? BUTTON6_REPEAT_DELAY :
  148. (index == 6) ? BUTTON7_REPEAT_DELAY :
  149. (index == 7) ? BUTTON8_REPEAT_DELAY : _buttonRepeatDelay()
  150. );
  151. }
  152. constexpr const unsigned long _buttonLongClickDelay() {
  153. return BUTTON_LNGCLICK_DELAY;
  154. }
  155. constexpr const unsigned long _buttonLongClickDelay(unsigned char index) {
  156. return (
  157. (index == 0) ? BUTTON1_LNGCLICK_DELAY :
  158. (index == 1) ? BUTTON2_LNGCLICK_DELAY :
  159. (index == 2) ? BUTTON3_LNGCLICK_DELAY :
  160. (index == 3) ? BUTTON4_LNGCLICK_DELAY :
  161. (index == 4) ? BUTTON5_LNGCLICK_DELAY :
  162. (index == 5) ? BUTTON6_LNGCLICK_DELAY :
  163. (index == 6) ? BUTTON7_LNGCLICK_DELAY :
  164. (index == 7) ? BUTTON8_LNGCLICK_DELAY : _buttonLongClickDelay()
  165. );
  166. }
  167. constexpr const unsigned long _buttonLongLongClickDelay() {
  168. return BUTTON_LNGLNGCLICK_DELAY;
  169. }
  170. constexpr const unsigned long _buttonLongLongClickDelay(unsigned char index) {
  171. return (
  172. (index == 0) ? BUTTON1_LNGLNGCLICK_DELAY :
  173. (index == 1) ? BUTTON2_LNGLNGCLICK_DELAY :
  174. (index == 2) ? BUTTON3_LNGLNGCLICK_DELAY :
  175. (index == 3) ? BUTTON4_LNGLNGCLICK_DELAY :
  176. (index == 4) ? BUTTON5_LNGLNGCLICK_DELAY :
  177. (index == 5) ? BUTTON6_LNGLNGCLICK_DELAY :
  178. (index == 6) ? BUTTON7_LNGLNGCLICK_DELAY :
  179. (index == 7) ? BUTTON8_LNGLNGCLICK_DELAY : _buttonLongLongClickDelay()
  180. );
  181. }
  182. constexpr const bool _buttonMqttSendAllEvents(unsigned char index) {
  183. return (
  184. (index == 0) ? (1 == BUTTON1_MQTT_SEND_ALL_EVENTS) :
  185. (index == 1) ? (1 == BUTTON2_MQTT_SEND_ALL_EVENTS) :
  186. (index == 2) ? (1 == BUTTON3_MQTT_SEND_ALL_EVENTS) :
  187. (index == 3) ? (1 == BUTTON4_MQTT_SEND_ALL_EVENTS) :
  188. (index == 4) ? (1 == BUTTON5_MQTT_SEND_ALL_EVENTS) :
  189. (index == 5) ? (1 == BUTTON6_MQTT_SEND_ALL_EVENTS) :
  190. (index == 6) ? (1 == BUTTON7_MQTT_SEND_ALL_EVENTS) :
  191. (index == 7) ? (1 == BUTTON8_MQTT_SEND_ALL_EVENTS) : (1 == BUTTON_MQTT_SEND_ALL_EVENTS)
  192. );
  193. }
  194. constexpr const bool _buttonMqttRetain(unsigned char index) {
  195. return (
  196. (index == 0) ? (1 == BUTTON1_MQTT_RETAIN) :
  197. (index == 1) ? (1 == BUTTON2_MQTT_RETAIN) :
  198. (index == 2) ? (1 == BUTTON3_MQTT_RETAIN) :
  199. (index == 3) ? (1 == BUTTON4_MQTT_RETAIN) :
  200. (index == 4) ? (1 == BUTTON5_MQTT_RETAIN) :
  201. (index == 5) ? (1 == BUTTON6_MQTT_RETAIN) :
  202. (index == 6) ? (1 == BUTTON7_MQTT_RETAIN) :
  203. (index == 7) ? (1 == BUTTON8_MQTT_RETAIN) : (1 == BUTTON_MQTT_RETAIN)
  204. );
  205. }