-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
70 lines (53 loc) · 1.62 KB
/
main.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
/*
* SPDX-License-Identifier: MIT
* Copyright © 2023 Lesosoftware https://github.com/leso-kn.
*
* pebble-le - Example program.
*/
#include <pebble-le/pebble-le.h>
#include <iostream>
#include <mutex>
//
#define PBL_APP_UUID "WatchApp-UUID-here-0000-000000000000" // TODO argv[1]
#define MESSAGE "Hello :)" // TODO argv[2]
#define MESSAGE_DICT_KEY 1
//
std::mutex *m;
void on_connectivity(const char *bt_addr, bool connected)
{
if (connected)
{
// Send Some Data!
std::cout << ">> Send Demo Data." << std::endl;
DictionaryIterator *iter;
pebble_le_app_message_outbox_begin(&iter);
dict_write_data(iter, MESSAGE_DICT_KEY, (const unsigned char*)MESSAGE, sizeof(MESSAGE));
pebble_le_app_message_outbox_send(bt_addr, PBL_APP_UUID, iter);
}
else
{
// Exit the program
m->unlock();
}
}
bool on_app_message(DictionaryIterator *iter, const char *app_uuid, const char *bt_addr)
{
std::cout << "<< Received an AppMessage saying \"" << iter->cursor->value << "\"" << std::endl;
// Returning false would send a NACK-packet to Pebble - true means ACK
return true;
}
int main(int argc, char const *argv[])
{
// Enable communication logging
pebble_le_log_level = PebbleLELogLevel::VERBOSE;
// Subscribe to connectivity events
pebble_le_register_watch_connectivity(&on_connectivity);
pebble_le_register_inbox_received(&on_app_message);
// Connect to a nearby Pebble!
pebble_le_connect();
// Use a mutex to keep the program alive until watch disconnects
m = new std::mutex();
m->lock();
m->lock();
return 0;
}