Revision 166:1a6a85e8d2e7
b/tidsense/Makefile | ||
---|---|---|
45 | 45 |
uart.o \ |
46 | 46 |
event.o \ |
47 | 47 |
report.o \ |
48 |
audio_power.o \ |
|
48 | 49 |
|
49 | 50 |
SENSOR_OBJECTS_V2 = \ |
50 | 51 |
board_v2.o \ |
b/tidsense/audio_power.c | ||
---|---|---|
1 |
#include "scheduler.h" |
|
2 |
#include "report.h" |
|
3 |
#include "audio_power_def.h" |
|
4 |
#include "audio_power.h" |
|
5 |
|
|
6 |
i2c_bus_t *power_bus; |
|
7 |
sched_task_t *audio_power_task; |
|
8 |
|
|
9 |
/* static definitions */ |
|
10 |
static void audio_power_task_fn(void); |
|
11 |
|
|
12 |
bool audio_power_setup(i2c_bus_t *b) { |
|
13 |
power_bus = b; |
|
14 |
|
|
15 |
if(!audio_power_probe()) |
|
16 |
return false; |
|
17 |
|
|
18 |
audio_power_task = sched_task_create(audio_power_task_fn, 30, 0, |
|
19 |
SCHED_ENABLED); |
|
20 |
return true; |
|
21 |
} |
|
22 |
|
|
23 |
bool audio_power_probe(void) { |
|
24 |
uint8_t data; |
|
25 |
|
|
26 |
i2c_error_t status = i2c_read_generic(power_bus, AUDIO_POWER_DEVICE, 0x00, |
|
27 |
&data, 1); |
|
28 |
if(status != I2C_SUCCESS) |
|
29 |
return false; |
|
30 |
if(data != AUDIO_POWER_SIG) |
|
31 |
return false; |
|
32 |
return true; |
|
33 |
} |
|
34 |
|
|
35 |
static void audio_power_task_fn(void) { |
|
36 |
audio_power_lipo_data_t lipo; |
|
37 |
audio_power_mppt_data_t mppt; |
|
38 |
report_t report; |
|
39 |
|
|
40 |
if(!report_start(&report, AUDIO_POWER_NAMESPACE)) |
|
41 |
return; |
|
42 |
|
|
43 |
/* read lipo status */ |
|
44 |
i2c_error_t status = i2c_read_generic(power_bus, AUDIO_POWER_DEVICE, |
|
45 |
AUDIO_POWER_LIPO_REG, &lipo, sizeof(lipo)); |
|
46 |
if(status == I2C_SUCCESS) { |
|
47 |
report_add_payload(&report, |
|
48 |
AUDIO_POWER_LIPO_CHARGE_CAPACITY | SENSOR_SIZE_16BIT | SENSOR_SIGNED, |
|
49 |
&lipo.charge_capacity); |
|
50 |
report_add_payload(&report, |
|
51 |
AUDIO_POWER_LIPO_CHARGE | SENSOR_SIZE_16BIT | SENSOR_SIGNED, |
|
52 |
&lipo.charge); |
|
53 |
report_add_payload(&report, |
|
54 |
AUDIO_POWER_LIPO_CURRENT | SENSOR_SIZE_16BIT | SENSOR_SIGNED, |
|
55 |
&lipo.current); |
|
56 |
report_add_payload(&report, |
|
57 |
AUDIO_POWER_LIPO_VOLTAGE | SENSOR_SIZE_16BIT | SENSOR_SIGNED, |
|
58 |
&lipo.voltage); |
|
59 |
report_add_payload(&report, |
|
60 |
AUDIO_POWER_LIPO_STATE | SENSOR_SIZE_8BIT, |
|
61 |
&lipo.state); |
|
62 |
} |
|
63 |
|
|
64 |
/* check mppt validity, read status */ |
|
65 |
uint8_t mppt_status; |
|
66 |
status = i2c_read_generic(power_bus, AUDIO_POWER_DEVICE, |
|
67 |
AUDIO_POWER_MPPT_STATUS_REG, &mppt_status, 1); |
|
68 |
if(status == I2C_SUCCESS && mppt_status == 0) { |
|
69 |
status = i2c_read_generic(power_bus, AUDIO_POWER_DEVICE, |
|
70 |
AUDIO_POWER_MPPT_REG, &mppt, sizeof(mppt)); |
|
71 |
if(status == I2C_SUCCESS) { |
|
72 |
report_add_payload(&report, |
|
73 |
AUDIO_POWER_SLA_VOLTAGE | SENSOR_SIZE_16BIT, |
|
74 |
&mppt.sla_voltage); |
|
75 |
report_add_payload(&report, |
|
76 |
AUDIO_POWER_PV_VOLTAGE | SENSOR_SIZE_16BIT, |
|
77 |
&mppt.pv_voltage); |
|
78 |
report_add_payload(&report, |
|
79 |
AUDIO_POWER_SLA_LOAD_CURRENT | SENSOR_SIZE_16BIT, |
|
80 |
&mppt.load_current); |
|
81 |
report_add_payload(&report, |
|
82 |
AUDIO_POWER_SLA_OVERDISCHARGE_VOLTAGE | SENSOR_SIZE_16BIT, |
|
83 |
&mppt.overdischarge_voltage); |
|
84 |
report_add_payload(&report, |
|
85 |
AUDIO_POWER_SLA_FULL_VOLTAGE | SENSOR_SIZE_16BIT, |
|
86 |
&mppt.full_voltage); |
|
87 |
report_add_payload(&report, |
|
88 |
AUDIO_POWER_SLA_FLAGS | SENSOR_SIZE_8BIT, |
|
89 |
&mppt.flags); |
|
90 |
report_add_payload(&report, |
|
91 |
AUDIO_POWER_SLA_TEMPERATURE | SENSOR_SIZE_8BIT, |
|
92 |
&mppt.temperature); |
|
93 |
report_add_payload(&report, |
|
94 |
AUDIO_POWER_SLA_CHARGE_CURRENT | SENSOR_SIZE_16BIT, |
|
95 |
&mppt.charge_current); |
|
96 |
report_add_payload(&report, |
|
97 |
AUDIO_POWER_SLA_CHARGE | SENSOR_SIZE_16BIT | SENSOR_SIGNED, |
|
98 |
&mppt.charge); |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
report_send(&report); |
|
103 |
} |
|
104 |
|
b/tidsense/audio_power.h | ||
---|---|---|
1 |
#ifndef __audio_power_h_ |
|
2 |
#define __audio_power_h_ |
|
3 |
|
|
4 |
#include <stdbool.h> |
|
5 |
|
|
6 |
#include "i2cmaster.h" |
|
7 |
|
|
8 |
#define AUDIO_POWER_DEVICE 0x30 |
|
9 |
#define AUDIO_POWER_SIG 0xBD |
|
10 |
|
|
11 |
#define AUDIO_POWER_LIPO_REG 0x10 |
|
12 |
#define AUDIO_POWER_MPPT_REG 0x20 |
|
13 |
#define AUDIO_POWER_MPPT_STATUS_REG 0x30 |
|
14 |
|
|
15 |
typedef struct { |
|
16 |
int16_t charge_capacity; |
|
17 |
int16_t charge; |
|
18 |
int16_t current; |
|
19 |
int16_t voltage; |
|
20 |
uint8_t state; |
|
21 |
} audio_power_lipo_data_t; |
|
22 |
|
|
23 |
typedef struct { |
|
24 |
uint16_t sla_voltage; |
|
25 |
uint16_t pv_voltage; |
|
26 |
uint16_t load_current; |
|
27 |
uint16_t overdischarge_voltage; |
|
28 |
uint16_t full_voltage; |
|
29 |
uint8_t flags; |
|
30 |
uint8_t temperature; |
|
31 |
uint16_t charge_current; |
|
32 |
uint16_t charge; |
|
33 |
} audio_power_mppt_data_t; |
|
34 |
|
|
35 |
bool audio_power_setup(i2c_bus_t *b); |
|
36 |
bool audio_power_probe(void); |
|
37 |
|
|
38 |
#endif // __audio_power_h_ |
|
39 |
|
b/tidsense/board_v2.c | ||
---|---|---|
10 | 10 |
#include "nv.h" |
11 | 11 |
#include "dma.h" |
12 | 12 |
#include "backpack.h" |
13 |
#include "audio_power.h" |
|
13 | 14 |
#include "core_sensors_def.h" |
15 |
#include "command.h" |
|
14 | 16 |
|
15 | 17 |
#include <hal.h> |
16 | 18 |
#include <phy.h> |
... | ... | |
115 | 117 |
|
116 | 118 |
analog_generic_setup(&battery_voltage, &battery_config, PSTR("battery")); |
117 | 119 |
|
120 |
bool audio_power_status = audio_power_setup(&sensor_i2c_bus); |
|
121 |
debug_sensor_status("mppt_pwr", audio_power_status? 0:1); |
|
122 |
|
|
118 | 123 |
/* |
119 | 124 |
if(nv_has_feature(FEATURE_SOLAR)) { |
120 | 125 |
analog_generic_setup(&solar_voltage, &solar_voltage_config, PSTR("solar")); |
... | ... | |
163 | 168 |
sensors_register(SENSOR(&vwc)); |
164 | 169 |
} |
165 | 170 |
|
171 |
command_set_i2c_bus(&sensor_i2c_bus); |
|
172 |
|
|
166 | 173 |
sei(); |
167 | 174 |
|
168 | 175 |
debugf("setup: end\n"); |
b/tidsense/command.c | ||
---|---|---|
44 | 44 |
network_free_request(req); |
45 | 45 |
} |
46 | 46 |
|
47 |
void command_set_i2c_bus(i2c_bus_t *bus) { |
|
48 |
cmd_i2c_bus = bus; |
|
49 |
} |
|
50 |
|
|
47 | 51 |
void cmd_setup_resp(command_id_t cmd, NWK_DataReq_t *req, void *hdr, NWK_DataInd_t *ind) { |
48 | 52 |
req->dstAddr = ind->srcAddr; |
49 | 53 |
req->dstEndpoint = CONTROL_ENDPOINT; |
b/tidsense/command.h | ||
---|---|---|
3 | 3 |
|
4 | 4 |
#include <nwk.h> |
5 | 5 |
|
6 |
#include "i2cmaster.h" |
|
6 | 7 |
#include "version.h" |
7 | 8 |
#include "network.h" |
8 | 9 |
|
... | ... | |
69 | 70 |
} cmd_i2c_t; |
70 | 71 |
|
71 | 72 |
void command_setup(void); |
73 |
void command_set_i2c_bus(i2c_bus_t *bus); |
|
72 | 74 |
void cmd_nodeinfo(NWK_DataInd_t *ind); |
73 | 75 |
|
74 | 76 |
void command_data_confirm(NWK_DataReq_t *req); |
b/tidsense/debug.h | ||
---|---|---|
48 | 48 |
* @param status the status code to report |
49 | 49 |
*/ |
50 | 50 |
# define debug_sensor_status(name, status) \ |
51 |
debugf(" % 10S: %S (%d)\n", PSTR(name), status == 0 ? debug_str_ok : \
|
|
51 |
debugf(" % 10S: %S (%d)\n", PSTR(name), (status) == 0 ? debug_str_ok : \
|
|
52 | 52 |
debug_str_fail, status) |
53 | 53 |
|
54 | 54 |
# if(JSON_OUTPUT) |
Also available in: Unified diff