1+ /*
2+ MIT License
3+
4+ Copyright (c) 2024 Felix Biego
5+
6+ Permission is hereby granted, free of charge, to any person obtaining a copy
7+ of this software and associated documentation files (the "Software"), to deal
8+ in the Software without restriction, including without limitation the rights
9+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ copies of the Software, and to permit persons to whom the Software is
11+ furnished to do so, subject to the following conditions:
12+
13+ The above copyright notice and this permission notice shall be included in all
14+ copies or substantial portions of the Software.
15+
16+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ SOFTWARE.
23+
24+ ______________ _____
25+ ___ __/___ /_ ___(_)_____ _______ _______
26+ __ /_ __ __ \__ / _ _ \__ __ `/_ __ \
27+ _ __/ _ /_/ /_ / / __/_ /_/ / / /_/ /
28+ /_/ /_.___/ /_/ \___/ _\__, / \____/
29+ /____/
30+
31+ */
32+
33+ #include < ChronosESP32.h>
34+
35+ ChronosESP32 watch (" Chronos Nav" ); // set the bluetooth name
36+
37+ bool change = false ;
38+
39+ void connectionCallback (bool state)
40+ {
41+ Serial.print (" Connection state: " );
42+ Serial.println (state ? " Connected" : " Disconnected" );
43+ }
44+
45+ void notificationCallback (Notification notification)
46+ {
47+ Serial.print (" Notification received at " );
48+ Serial.println (notification.time );
49+ Serial.print (" From: " );
50+ Serial.print (notification.app );
51+ Serial.print (" \t Icon: " );
52+ Serial.println (notification.icon );
53+ Serial.println (notification.message );
54+ }
55+
56+ void configCallback (Config config, uint32_t a, uint32_t b)
57+ {
58+ switch (config)
59+ {
60+ case CF_NAV_DATA:
61+ Serial.print (" Navigation state: " );
62+ Serial.println (a ? " Active" : " Inactive" );
63+ change = true ;
64+ if (a){
65+ Navigation nav = watch.getNavigation ();
66+ Serial.println (nav.directions );
67+ Serial.println (nav.eta );
68+ Serial.println (nav.duration );
69+ Serial.println (nav.distance );
70+ Serial.println (nav.title );
71+ }
72+ break ;
73+ case CF_NAV_ICON:
74+ Serial.print (" Navigation Icon data, position: " );
75+ Serial.println (a);
76+ Serial.print (" Icon CRC: " );
77+ Serial.printf (" 0x%04X\n " , b);
78+ break ;
79+ }
80+ }
81+
82+ void setup ()
83+ {
84+ Serial.begin (115200 );
85+
86+ // set the callbacks before calling begin funtion
87+ watch.setConnectionCallback (connectionCallback);
88+ watch.setNotificationCallback (notificationCallback);
89+ watch.setConfigurationCallback (configCallback);
90+
91+ watch.begin (); // initializes the BLE
92+ // make sure the ESP32 is not paired with your phone in the bluetooth settings
93+ // go to Chronos app > Watches tab > Watches button > Pair New Devices > Search > Select your board
94+ // you only need to do it once. To disconnect, click on the rotating icon (Top Right)
95+
96+ Serial.println (watch.getAddress ()); // mac address, call after begin()
97+
98+ watch.setBattery (80 ); // set the battery level, will be synced to the app
99+ }
100+
101+ void loop ()
102+ {
103+ watch.loop (); // handles internal routine functions
104+
105+ // if (change){
106+ // change = false;
107+
108+ // Navigation nav = watch.getNavigation();
109+ // if (nav.active){
110+ // Serial.println(nav.directions);
111+ // Serial.println(nav.eta);
112+ // Serial.println(nav.duration);
113+ // Serial.println(nav.distance);
114+ // Serial.println(nav.title);
115+ // }
116+ // }
117+
118+ }
0 commit comments