forked from CircuitMess/Clockstar-Firmware
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathancs.cpp
76 lines (64 loc) · 1.99 KB
/
ancs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <driver/gpio.h>
#include <nvs_flash.h>
#include <esp_log.h>
#include "Periph/Bluetooth.h"
#include "BLE/GAP.h"
#include "BLE/Client.h"
#include "Notifs/ANCS/Client.h"
void init(){
gpio_config_t io_conf = {
.pin_bit_mask = 1 << 13,
.mode = GPIO_MODE_INPUT,
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE
};
gpio_config(&io_conf);
auto ret = nvs_flash_init();
if(ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND){
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
// esp_log_level_set("BLE", ESP_LOG_VERBOSE);
// esp_log_level_set("BLE::Client", ESP_LOG_VERBOSE);
// esp_log_level_set("BLE::Service", ESP_LOG_VERBOSE);
// esp_log_level_set("BLE::ServiceInfo", ESP_LOG_VERBOSE);
// esp_log_level_set("BLE::Char", ESP_LOG_VERBOSE);
// esp_log_level_set("BLE::CharInfo", ESP_LOG_VERBOSE);
// esp_log_level_set("ANCS", ESP_LOG_VERBOSE);
auto bt = new Bluetooth();
auto gap = new BLE::GAP();
auto client = new BLE::Client(gap);
auto ancs = new ANCS::Client(client);
ancs->setOnConnect([](){
printf("ANCS connected\n");
});
ancs->setOnDisconnect([](){
printf("ANCS disconnected\n");
});
auto print = [](const Notif& notif){
printf("App ID: %s\n", notif.appID.c_str());
printf("Title: %s\n", notif.title.c_str());
printf("Subtitle: %s\n", notif.subtitle.c_str());
printf("Message: %s\n", notif.message.c_str());
printf("Category: %s\n", ANCS::labelCategory((ANCS::CategoryID) notif.category));
printf("Pos: %s / Neg: %s\n", notif.label.pos.c_str(), notif.label.neg.c_str());
printf("\n");
};
ancs->setOnNotifAdd([print](Notif notif){
printf("Add 0x%x\n", notif.uid);
print(notif);
});
ancs->setOnNotifModify([print](Notif notif){
printf("Modify 0x%x\n", notif.uid);
print(notif);
});
ancs->setOnNotifRemove([](uint32_t uid){
printf("Removing 0x%x\n", uid);
});
}
extern "C" void app_main(void){
init();
vTaskDelete(nullptr);
}