123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
-
-
- #include "config.h"
- #include "log.h"
- #include "ble.h"
- #include "crafty.h"
-
-
-
-
-
-
-
-
-
- static uint8_t uuid_base[16] = {
- 0x00, 0x00, 0x00, 0xFF, 0x4c, 0x45, 0x4b, 0x43,
- 0x49, 0x42, 0x26, 0x5a, 0x52, 0x4f, 0x54, 0x53,
- };
- static uint8_t uuid_base2[16] = {
- 0x00, 0x00, 0x00, 0xFF, 0x4c, 0x45, 0x4b, 0x43,
- 0x49, 0x42, 0x26, 0x5a, 0x52, 0x4f, 0x54, 0x53,
- };
-
-
- #define UUID_WRITE_SRVC 0x01
- #define UUID_CURRENT_TEMP 0x11
- #define UUID_TARGET_TEMP 0x21
- #define UUID_BATTERY 0x41
- #define UUID_HEATER_ON 0x81
- #define UUID_HEATER_OFF 0x91
-
- int16_t crafty_get_current_temp(void) {
- uuid_base[3] = UUID_CURRENT_TEMP;
-
- uint8_t buff[2];
- int32_t r = ble_read(uuid_base, buff, sizeof(buff));
- if (r != sizeof(buff)) {
- debug("ble_read unexpected value %ld", r);
- return -1;
- }
-
- uint16_t *v = (uint16_t *)buff;
- return *v;
- }
-
- int16_t crafty_get_target_temp(void) {
- uuid_base[3] = UUID_TARGET_TEMP;
-
- uint8_t buff[2];
- int32_t r = ble_read(uuid_base, buff, sizeof(buff));
- if (r != sizeof(buff)) {
- debug("ble_read unexpected value %ld", r);
- return -1;
- }
-
- uint16_t *v = (uint16_t *)buff;
- return *v;
- }
-
- int8_t crafty_set_target_temp(uint16_t value) {
- uuid_base[3] = UUID_WRITE_SRVC;
- uuid_base2[3] = UUID_TARGET_TEMP;
-
- uint8_t buff[2];
- uint16_t *v = (uint16_t *)buff;
- *v = value;
-
- int8_t r = ble_write(uuid_base, uuid_base2, buff, sizeof(buff));
- if (r != 0) {
- debug("ble_write unexpected value %d", r);
- }
- return r;
- }
-
- int8_t crafty_set_heater_state(bool value) {
- uuid_base[3] = UUID_WRITE_SRVC;
-
- if (value) {
- uuid_base2[3] = UUID_HEATER_ON;
- } else {
- uuid_base2[3] = UUID_HEATER_OFF;
- }
-
- uint16_t d = 0;
- int8_t r = ble_write(uuid_base, uuid_base2, (uint8_t *)&d, sizeof(d));
- if (r != 0) {
- debug("ble_write unexpected value %d", r);
- }
- return r;
- }
-
- int8_t crafty_get_battery_state(void) {
- uuid_base[3] = UUID_BATTERY;
-
- uint8_t buff[2];
- int32_t r = ble_read(uuid_base, buff, sizeof(buff));
- if (r != sizeof(buff)) {
- debug("ble_read unexpected value %ld", r);
- return -1;
- }
-
- uint16_t *v = (uint16_t *)buff;
- return *v;
- }
|