Skip to content

Commit d4a3f4f

Browse files
style: js_gpio
1 parent 6c2efd7 commit d4a3f4f

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

applications/system/js_app/modules/js_gpio.c

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -80,43 +80,43 @@ static void js_gpio_init(struct mjs* mjs) {
8080
if(!edge) edge = "rising";
8181

8282
// convert strings to mode
83-
// FIXME: make me pretty ^_^
83+
// FIXME: make me even prettier, maybe? ^_^
8484
GpioMode mode;
85-
if(strcmp(direction, "out") == 0 && strcmp(out_mode, "push_pull") == 0) {
86-
mode = GpioModeOutputPushPull;
87-
} else if(strcmp(direction, "out") == 0 && strcmp(out_mode, "open_drain") == 0) {
88-
mode = GpioModeOutputOpenDrain;
89-
} else if(strcmp(direction, "in") == 0 && strcmp(in_mode, "analog") == 0) {
90-
mode = GpioModeAnalog;
91-
} else if(strcmp(direction, "in") == 0 && strcmp(in_mode, "plain_digital") == 0) {
92-
mode = GpioModeInput;
93-
} else if(
94-
strcmp(direction, "in") == 0 && strcmp(in_mode, "interrupt") == 0 &&
95-
strcmp(edge, "rising") == 0) {
96-
mode = GpioModeInterruptRise;
97-
} else if(
98-
strcmp(direction, "in") == 0 && strcmp(in_mode, "interrupt") == 0 &&
99-
strcmp(edge, "falling") == 0) {
100-
mode = GpioModeInterruptFall;
101-
} else if(
102-
strcmp(direction, "in") == 0 && strcmp(in_mode, "interrupt") == 0 &&
103-
strcmp(edge, "both") == 0) {
104-
mode = GpioModeInterruptRiseFall;
105-
} else if(
106-
strcmp(direction, "in") == 0 && strcmp(in_mode, "event") == 0 &&
107-
strcmp(edge, "rising") == 0) {
108-
mode = GpioModeEventRise;
109-
} else if(
110-
strcmp(direction, "in") == 0 && strcmp(in_mode, "event") == 0 &&
111-
strcmp(edge, "falling") == 0) {
112-
mode = GpioModeEventFall;
113-
} else if(
114-
strcmp(direction, "in") == 0 && strcmp(in_mode, "event") == 0 &&
115-
strcmp(edge, "both") == 0) {
116-
mode = GpioModeEventRiseFall;
85+
if(strcmp(direction, "out") == 0) {
86+
if(strcmp(out_mode, "push_pull") == 0)
87+
mode = GpioModeOutputPushPull;
88+
else if(strcmp(out_mode, "open_drain") == 0)
89+
mode = GpioModeOutputOpenDrain;
90+
else
91+
JS_ERROR_AND_RETURN(mjs, MJS_BAD_ARGS_ERROR, "invalid outMode");
92+
} else if(strcmp(direction, "in") == 0) {
93+
if(strcmp(in_mode, "analog") == 0) {
94+
mode = GpioModeAnalog;
95+
} else if(strcmp(in_mode, "plain_digital") == 0) {
96+
mode = GpioModeInput;
97+
} else if(strcmp(in_mode, "interrupt") == 0) {
98+
if(strcmp(edge, "rising") == 0)
99+
mode = GpioModeInterruptRise;
100+
else if(strcmp(edge, "falling") == 0)
101+
mode = GpioModeInterruptFall;
102+
else if(strcmp(edge, "both") == 0)
103+
mode = GpioModeInterruptRiseFall;
104+
else
105+
JS_ERROR_AND_RETURN(mjs, MJS_BAD_ARGS_ERROR, "invalid edge");
106+
} else if(strcmp(in_mode, "event") == 0) {
107+
if(strcmp(edge, "rising") == 0)
108+
mode = GpioModeEventRise;
109+
else if(strcmp(edge, "falling") == 0)
110+
mode = GpioModeEventFall;
111+
else if(strcmp(edge, "both") == 0)
112+
mode = GpioModeEventRiseFall;
113+
else
114+
JS_ERROR_AND_RETURN(mjs, MJS_BAD_ARGS_ERROR, "invalid edge");
115+
} else {
116+
JS_ERROR_AND_RETURN(mjs, MJS_BAD_ARGS_ERROR, "invalid inMode");
117+
}
117118
} else {
118-
JS_ERROR_AND_RETURN(
119-
mjs, MJS_BAD_ARGS_ERROR, "Invalid combination of fields in mode object");
119+
JS_ERROR_AND_RETURN(mjs, MJS_BAD_ARGS_ERROR, "invalid direction");
120120
}
121121

122122
// convert pull
@@ -128,7 +128,7 @@ static void js_gpio_init(struct mjs* mjs) {
128128
} else if(strcmp(pull, "down") == 0) {
129129
pull_mode = GpioPullDown;
130130
} else {
131-
JS_ERROR_AND_RETURN(mjs, MJS_BAD_ARGS_ERROR, "Invalid pull mode");
131+
JS_ERROR_AND_RETURN(mjs, MJS_BAD_ARGS_ERROR, "invalid pull");
132132
}
133133

134134
// get state
@@ -410,7 +410,7 @@ static void js_gpio_destroy(void* inst) {
410410
// The module destructor is only ever called shortly before the mjs
411411
// destructor is called, which may not free our owned object. It looks
412412
// like it does do so (since no memory leaks manifest themselves),
413-
// but idk \(-_-)/
413+
// but idk, seems janky \(-_-)/
414414
}
415415

416416
// free buffers
@@ -423,6 +423,8 @@ static void js_gpio_destroy(void* inst) {
423423
furi_record_close(RECORD_EXPANSION);
424424
}
425425

426+
// TODO: ADC
427+
426428
static const JsModuleDescriptor js_gpio_desc = {
427429
"gpio",
428430
js_gpio_create,

0 commit comments

Comments
 (0)