Skip to content

Commit 3c1e7cc

Browse files
committed
laurent: add separate USB relays support
Extend laurent driver, allowing using a relay to control USB circuits. For example, the relay might be connected to the DIP switch on RB1 / RB2 boards. Signed-off-by: Dmitry Baryshkov <[email protected]>
1 parent bad935c commit 3c1e7cc

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

drivers/laurent.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct laurent_options {
2323
const char *server;
2424
const char *password;
2525
unsigned int relay;
26+
int usb_relay;
2627
};
2728

2829
struct laurent {
@@ -42,6 +43,7 @@ void *laurent_parse_options(struct device_parser *dp)
4243

4344
options = calloc(1, sizeof(*options));
4445
options->password = DEFAULT_PASSWORD;
46+
options->usb_relay = -1;
4547

4648
device_parser_accept(dp, YAML_MAPPING_START_EVENT, NULL, 0);
4749
while (device_parser_accept(dp, YAML_SCALAR_EVENT, key, TOKEN_LENGTH)) {
@@ -54,6 +56,8 @@ void *laurent_parse_options(struct device_parser *dp)
5456
options->password = strdup(value);
5557
else if (!strcmp(key, "relay"))
5658
options->relay = strtoul(value, NULL, 0);
59+
else if (!strcmp(key, "usb_relay"))
60+
options->usb_relay = strtoul(value, NULL, 0);
5761
else
5862
errx(1, "%s: unknown option \"%s\"", __func__, key);
5963
}
@@ -124,7 +128,7 @@ static void *laurent_open(struct device *dev)
124128
return laurent;
125129
}
126130

127-
static int laurent_power(struct device *dev, bool on)
131+
static int laurent_control(struct device *dev, unsigned int relay, bool on)
128132
{
129133
struct laurent *laurent = dev->cdb;
130134
char buf[BUFSIZ];
@@ -145,7 +149,7 @@ static int laurent_power(struct device *dev, bool on)
145149

146150
len = snprintf(buf, sizeof(buf), "GET /cmd.cgi?psw=%s&cmd=REL,%u,%d HTTP/1.0\r\n\r\n",
147151
laurent->options->password,
148-
laurent->options->relay,
152+
relay,
149153
on);
150154
if (len < 0) {
151155
warn("asprintf failed\n");
@@ -190,8 +194,30 @@ static int laurent_power(struct device *dev, bool on)
190194
return -1;
191195
}
192196

197+
static int laurent_power(struct device *dev, bool on)
198+
{
199+
struct laurent *laurent = dev->cdb;
200+
201+
return laurent_control(dev,
202+
laurent->options->relay,
203+
on);
204+
}
205+
206+
static void laurent_usb(struct device *dev, bool on)
207+
{
208+
struct laurent *laurent = dev->cdb;
209+
210+
if (laurent->options->usb_relay < 0)
211+
return;
212+
213+
laurent_control(dev,
214+
laurent->options->usb_relay,
215+
on);
216+
}
217+
193218
const struct control_ops laurent_ops = {
194219
.parse_options = laurent_parse_options,
195220
.open = laurent_open,
196221
.power = laurent_power,
222+
.usb = laurent_usb,
197223
};

schema.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ properties:
152152
type: string
153153
relay:
154154
type: integer
155+
usb_relay:
156+
type: integer
155157
password:
156158
description: password to access the relays, defaults to 'Laurent'
157159
type: string

0 commit comments

Comments
 (0)