-
Notifications
You must be signed in to change notification settings - Fork 0
/
HyperDevice31I2CSlave.cpp
76 lines (58 loc) · 1.42 KB
/
HyperDevice31I2CSlave.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 "hyper_device_31_v3.gen.h"
#include "hyper_device_core_v3.h"
#include "hyper_extension_bus.h"
#include "HyperDevice31I2CSlave.h"
static hyper_device_31_t _device = {0};
/*
Decode device data and dispatch attributes.
Return:
- `0` on success;
- `-1` if the decoding of data as device fails.
*/
static int hyper_device_31_set_data(
uint8_t *data,
uint8_t len
) {
hyper_result_t res = hyper_device_31_decode(
&_device,
data,
len
);
if (res != HYPER_OK) {
return -1;
}
uint8_t _dispatched_count =
hyper_device_31_dispatch(&_device);
return 0;
}
/*
Encode device data.
Return:
- `0` on success;
- `-1` if the encoding of the device fails.
*/
static int hyper_device_31_get_data(
uint8_t *data,
uint8_t *len
) {
hyper_result_t ret = hyper_device_31_encode(
&_device,
data,
len
);
if (ret != HYPER_OK) {
return -1;
}
return 0;
}
HyperDevice31I2CSlave::HyperDevice31I2CSlave() { }
void HyperDevice31I2CSlave::begin(const uint8_t id[6]) {
hyper_device_31_init(&_device, (uint8_t *)id);
hyper_extension_bus_slave_init(hyper_device_31_get_data, hyper_device_31_set_data);
}
void HyperDevice31I2CSlave::setFCAPLemnaSensorDensity_1(float x) {
hyper_device_31_set_fcap_lemna_density_0_1(&_device, x);
}
void HyperDevice31I2CSlave::setFCAPLemnaSensorDistance_1(float x) {
hyper_device_31_set_fcap_lemna_sensor_distance_0_1(&_device, x);
}