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.

99 lines
2.5 KiB

  1. /*
  2. LightFox module
  3. Copyright (C) 2019 by Andrey F. Kupreychik <foxle@quickfox.ru>
  4. */
  5. #ifdef FOXEL_LIGHTFOX_DUAL
  6. // -----------------------------------------------------------------------------
  7. // DEFINITIONS
  8. // -----------------------------------------------------------------------------
  9. #define LIGHTFOX_CODE_START 0xA0
  10. #define LIGHTFOX_CODE_LEARN 0xF1
  11. #define LIGHTFOX_CODE_CLEAR 0xF2
  12. #define LIGHTFOX_CODE_STOP 0xA1
  13. // -----------------------------------------------------------------------------
  14. // PUBLIC
  15. // -----------------------------------------------------------------------------
  16. void lightfoxLearn() {
  17. Serial.write(LIGHTFOX_CODE_START);
  18. Serial.write(LIGHTFOX_CODE_LEARN);
  19. Serial.write(0x00);
  20. Serial.write(LIGHTFOX_CODE_STOP);
  21. Serial.println();
  22. Serial.flush();
  23. DEBUG_MSG_P(PSTR("[LIGHTFOX] Learn comman sent\n"));
  24. }
  25. void lightfoxClear() {
  26. Serial.write(LIGHTFOX_CODE_START);
  27. Serial.write(LIGHTFOX_CODE_CLEAR);
  28. Serial.write(0x00);
  29. Serial.write(LIGHTFOX_CODE_STOP);
  30. Serial.println();
  31. Serial.flush();
  32. DEBUG_MSG_P(PSTR("[LIGHTFOX] Clear comman sent\n"));
  33. }
  34. // -----------------------------------------------------------------------------
  35. // WEB
  36. // -----------------------------------------------------------------------------
  37. #if WEB_SUPPORT
  38. void _lightfoxWebSocketOnSend(JsonObject& root) {
  39. root["lightfoxVisible"] = 1;
  40. }
  41. void _lightfoxWebSocketOnAction(uint32_t client_id, const char * action, JsonObject& data) {
  42. if (strcmp(action, "lightfoxLearn") == 0) lightfoxLearn();
  43. if (strcmp(action, "lightfoxClear") == 0) lightfoxClear();
  44. }
  45. #endif
  46. // -----------------------------------------------------------------------------
  47. // TERMINAL
  48. // -----------------------------------------------------------------------------
  49. #if TERMINAL_SUPPORT
  50. void _lightfoxInitCommands() {
  51. settingsRegisterCommand(F("LIGHTFOX.LEARN"), [](Embedis* e) {
  52. lightfoxLearn();
  53. DEBUG_MSG_P(PSTR("+OK\n"));
  54. });
  55. settingsRegisterCommand(F("LIGHTFOX.CLEAR"), [](Embedis* e) {
  56. lightfoxClear();
  57. DEBUG_MSG_P(PSTR("+OK\n"));
  58. });
  59. }
  60. #endif
  61. // -----------------------------------------------------------------------------
  62. // SETUP & LOOP
  63. // -----------------------------------------------------------------------------
  64. void lightfoxSetup() {
  65. #if WEB_SUPPORT
  66. wsOnSendRegister(_lightfoxWebSocketOnSend);
  67. wsOnActionRegister(_lightfoxWebSocketOnAction);
  68. #endif
  69. #if TERMINAL_SUPPORT
  70. _lightfoxInitCommands();
  71. #endif
  72. }
  73. #endif