Skip to content

Commit a70bddc

Browse files
committed
PlatformIO: Replace C99-style designated init
Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
1 parent 3160f4c commit a70bddc

2 files changed

Lines changed: 56 additions & 53 deletions

File tree

examples/platformio/cp.ino

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include <osdp.hpp>
99

1010
OSDP::ControlPanel cp;
11+
osdp_pd_info_t pd_info[] = {
12+
{},
13+
};
1114

1215
int serial1_send_func(void *data, uint8_t *buf, int len)
1316
{
@@ -36,24 +39,28 @@ int serial1_recv_func(void *data, uint8_t *buf, int len)
3639
return read;
3740
}
3841

39-
osdp_pd_info_t pd_info[] = {
40-
{
41-
.name = "pd[101]",
42-
.baud_rate = (int)115200,
43-
.address = 101,
44-
.flags = 0,
45-
.id = {},
46-
.cap = nullptr,
47-
.channel = {
48-
.data = nullptr,
49-
.id = 0,
50-
.recv = serial1_recv_func,
51-
.send = serial1_send_func,
52-
.flush = nullptr
53-
},
54-
.scbk = nullptr,
55-
},
56-
};
42+
void init_cp_info()
43+
{
44+
pd_info[0].name = "pd[101]";
45+
pd_info[0].baud_rate = 115200;
46+
pd_info[0].address = 101;
47+
pd_info[0].flags = 0;
48+
pd_info[0].id.version = 0;
49+
pd_info[0].id.model = 0;
50+
pd_info[0].id.vendor_code = 0;
51+
pd_info[0].id.serial_number = 0;
52+
pd_info[0].id.firmware_version = 0;
53+
pd_info[0].cap = nullptr;
54+
pd_info[0].channel.data = nullptr;
55+
pd_info[0].channel.id = 0;
56+
pd_info[0].channel.recv = serial1_recv_func;
57+
pd_info[0].channel.recv_pkt = nullptr;
58+
pd_info[0].channel.send = serial1_send_func;
59+
pd_info[0].channel.flush = nullptr;
60+
pd_info[0].channel.release_pkt = nullptr;
61+
pd_info[0].channel.close = nullptr;
62+
pd_info[0].scbk = nullptr;
63+
}
5764

5865
int event_handler(void *data, int pd, struct osdp_event *event)
5966
{
@@ -70,6 +77,7 @@ void setup()
7077

7178
cp.logger_init("osdp::cp", OSDP_LOG_DEBUG, NULL);
7279

80+
init_cp_info();
7381
cp.setup(1, pd_info);
7482
cp.set_event_callback(event_handler, nullptr);
7583
}

examples/platformio/pd.ino

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
#include <osdp.hpp>
99

1010
OSDP::PeripheralDevice pd;
11+
osdp_pd_info_t info_pd = {};
12+
static const struct osdp_pd_cap pd_cap[] = {
13+
{ OSDP_PD_CAP_READER_LED_CONTROL, 1, 1 },
14+
{ OSDP_PD_CAP_READER_AUDIBLE_OUTPUT, 1, 1 },
15+
{ static_cast<uint8_t>(-1), 0, 0 } /* Sentinel */
16+
};
1117

1218
int serial1_send_func(void *data, uint8_t *buf, int len)
1319
{
@@ -36,40 +42,28 @@ int serial1_recv_func(void *data, uint8_t *buf, int len)
3642
return read;
3743
}
3844

39-
osdp_pd_info_t info_pd = {
40-
.name = "pd[101]",
41-
.baud_rate = 9600,
42-
.address = 101,
43-
.flags = 0,
44-
.id = {
45-
.version = 1,
46-
.model = 153,
47-
.vendor_code = 31337,
48-
.serial_number = 0x01020304,
49-
.firmware_version = 0x0A0B0C0D,
50-
},
51-
.cap = (struct osdp_pd_cap []) {
52-
{
53-
.function_code = OSDP_PD_CAP_READER_LED_CONTROL,
54-
.compliance_level = 1,
55-
.num_items = 1
56-
},
57-
{
58-
.function_code = OSDP_PD_CAP_READER_AUDIBLE_OUTPUT,
59-
.compliance_level = 1,
60-
.num_items = 1
61-
},
62-
{ static_cast<uint8_t>(-1), 0, 0 } /* Sentinel */
63-
},
64-
.channel = {
65-
.data = nullptr,
66-
.id = 0,
67-
.recv = serial1_recv_func,
68-
.send = serial1_send_func,
69-
.flush = nullptr
70-
},
71-
.scbk = nullptr,
72-
};
45+
void init_pd_info()
46+
{
47+
info_pd.name = "pd[101]";
48+
info_pd.baud_rate = 9600;
49+
info_pd.address = 101;
50+
info_pd.flags = 0;
51+
info_pd.id.version = 1;
52+
info_pd.id.model = 153;
53+
info_pd.id.vendor_code = 31337;
54+
info_pd.id.serial_number = 0x01020304;
55+
info_pd.id.firmware_version = 0x0A0B0C0D;
56+
info_pd.cap = pd_cap;
57+
info_pd.channel.data = nullptr;
58+
info_pd.channel.id = 0;
59+
info_pd.channel.recv = serial1_recv_func;
60+
info_pd.channel.recv_pkt = nullptr;
61+
info_pd.channel.send = serial1_send_func;
62+
info_pd.channel.flush = nullptr;
63+
info_pd.channel.release_pkt = nullptr;
64+
info_pd.channel.close = nullptr;
65+
info_pd.scbk = nullptr;
66+
}
7367

7468
int pd_command_handler(void *data, struct osdp_cmd *cmd)
7569
{
@@ -86,6 +80,7 @@ void setup()
8680

8781
pd.logger_init("osdp::pd", OSDP_LOG_DEBUG, NULL);
8882

83+
init_pd_info();
8984
pd.setup(&info_pd);
9085

9186
pd.set_command_callback(pd_command_handler, nullptr);
@@ -95,4 +90,4 @@ void loop()
9590
{
9691
pd.refresh();
9792
delay(1000);
98-
}
93+
}

0 commit comments

Comments
 (0)