S&B Volcano vaporizer remote control with Pi Pico W
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.

volcano.c 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * volcano.c
  3. *
  4. * Copyright (c) 2023 Thomas Buck (thomas@xythobuz.de)
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * See <http://www.gnu.org/licenses/>.
  17. */
  18. #include "config.h"
  19. #include "log.h"
  20. #include "ble.h"
  21. #include "volcano.h"
  22. // Volcano UUIDs are always the same, except for the 4th byte
  23. #define UUID_WRITE_SRVC 0x00
  24. #define UUID_CURRENT_TEMP 0x01
  25. #define UUID_TARGET_TEMP 0x03
  26. #define UUID_HEATER_ON 0x0F
  27. #define UUID_HEATER_OFF 0x10
  28. #define UUID_PUMP_ON 0x13
  29. #define UUID_PUMP_OFF 0x14
  30. // "101100xx-5354-4f52-5a26-4249434b454c"
  31. static uint8_t uuid_base[16] = {
  32. 0x10, 0x11, 0x00, 0xFF, 0x53, 0x54, 0x4f, 0x52,
  33. 0x5a, 0x26, 0x42, 0x49, 0x43, 0x4b, 0x45, 0x4c,
  34. };
  35. static uint8_t uuid_base2[16] = {
  36. 0x10, 0x11, 0x00, 0xFF, 0x53, 0x54, 0x4f, 0x52,
  37. 0x5a, 0x26, 0x42, 0x49, 0x43, 0x4b, 0x45, 0x4c,
  38. };
  39. int16_t volcano_get_current_temp(void) {
  40. uuid_base[3] = UUID_CURRENT_TEMP;
  41. uint8_t buff[4];
  42. int32_t r = ble_read(uuid_base, buff, sizeof(buff));
  43. if (r != sizeof(buff)) {
  44. debug("ble_read unexpected value %ld", r);
  45. return -1;
  46. }
  47. uint32_t *v = (uint32_t *)buff;
  48. return *v;
  49. }
  50. int16_t volcano_get_target_temp(void) {
  51. uuid_base[3] = UUID_TARGET_TEMP;
  52. uint8_t buff[4];
  53. int32_t r = ble_read(uuid_base, buff, sizeof(buff));
  54. if (r != sizeof(buff)) {
  55. debug("ble_read unexpected value %ld", r);
  56. return -1;
  57. }
  58. uint32_t *v = (uint32_t *)buff;
  59. return *v;
  60. }
  61. int8_t volcano_set_target_temp(uint16_t value) {
  62. uuid_base[3] = UUID_WRITE_SRVC;
  63. uuid_base2[3] = UUID_TARGET_TEMP;
  64. uint8_t buff[4];
  65. uint32_t *v = (uint32_t *)buff;
  66. *v = value;
  67. int8_t r = ble_write(uuid_base, uuid_base2, buff, sizeof(buff));
  68. if (r != 0) {
  69. debug("ble_write unexpected value %d", r);
  70. }
  71. return r;
  72. }
  73. int8_t volcano_set_heater_state(bool value) {
  74. uuid_base[3] = UUID_WRITE_SRVC;
  75. if (value) {
  76. uuid_base2[3] = UUID_HEATER_ON;
  77. } else {
  78. uuid_base2[3] = UUID_HEATER_OFF;
  79. }
  80. uint8_t d = 0;
  81. int8_t r = ble_write(uuid_base, uuid_base2, &d, sizeof(d));
  82. if (r != 0) {
  83. debug("ble_write unexpected value %d", r);
  84. }
  85. return r;
  86. }
  87. int8_t volcano_set_pump_state(bool value) {
  88. uuid_base[3] = UUID_WRITE_SRVC;
  89. if (value) {
  90. uuid_base2[3] = UUID_PUMP_ON;
  91. } else {
  92. uuid_base2[3] = UUID_PUMP_OFF;
  93. }
  94. uint8_t d = 0;
  95. int8_t r = ble_write(uuid_base, uuid_base2, &d, sizeof(d));
  96. if (r != 0) {
  97. debug("ble_write unexpected value %d", r);
  98. }
  99. return r;
  100. }