1 | #include <bluetoe/bindings/nrf51.hpp>
|
2 | #include <bluetoe/services/csc.hpp>
|
3 | #include <bluetoe/server.hpp>
|
4 | #include <bluetoe/sensor_location.hpp>
|
5 | #include <nrf.h>
|
6 |
|
7 | struct handler {
|
8 |
|
9 | /*
|
10 | * Functions required by the bluetoe CSC implementation to support wheel and crank revolutions
|
11 | */
|
12 | std::pair< std::uint32_t, std::uint16_t > cumulative_wheel_revolutions_and_time()
|
13 | {
|
14 | return std::make_pair( wheel_revolutions_, last_wheel_event_time_ );
|
15 | }
|
16 |
|
17 | std::pair< std::uint16_t, std::uint16_t > cumulative_crank_revolutions_and_time()
|
18 | {
|
19 | return std::make_pair( crank_revolutions_, last_crank_event_time_ );
|
20 | }
|
21 |
|
22 | void set_cumulative_wheel_revolutions( std::uint32_t new_value );
|
23 |
|
24 | volatile std::uint32_t wheel_revolutions_;
|
25 | volatile std::uint16_t last_wheel_event_time_;
|
26 |
|
27 | volatile std::uint32_t crank_revolutions_;
|
28 | volatile std::uint16_t last_crank_event_time_;
|
29 | };
|
30 |
|
31 | static constexpr char server_name[] = "Gruener Blitz";
|
32 |
|
33 | using bicycle = bluetoe::server<
|
34 | bluetoe::server_name< server_name >,
|
35 | bluetoe::appearance::cycling_speed_and_cadence_sensor,
|
36 | bluetoe::cycling_speed_and_cadence<
|
37 | bluetoe::sensor_location::hip,
|
38 | bluetoe::csc::wheel_revolution_data_supported,
|
39 | bluetoe::csc::crank_revolution_data_supported,
|
40 | bluetoe::csc::handler< handler >
|
41 | >
|
42 | >;
|
43 |
|
44 | bicycle gatt;
|
45 |
|
46 | void handler::set_cumulative_wheel_revolutions( std::uint32_t new_value )
|
47 | {
|
48 | wheel_revolutions_ = new_value;
|
49 | gatt.confirm_cumulative_wheel_revolutions( gatt );
|
50 | }
|
51 |
|
52 | bluetoe::nrf51< bicycle > server;
|
53 |
|
54 | void init_bike_hardware();
|
55 |
|
56 | int main()
|
57 | {
|
58 | init_bike_hardware();
|
59 |
|
60 | for ( ;; )
|
61 | server.run( gatt );
|
62 | }
|
63 | // ab hier kommt der nrf51 hardware-Teil: https://github.com/TorstenRobitzki/bluetoe/blob/master/examples/nrf51/cycling_speed_and_cadence.cpp
|