@@ -80,43 +80,43 @@ static void js_gpio_init(struct mjs* mjs) {
80
80
if (!edge ) edge = "rising" ;
81
81
82
82
// convert strings to mode
83
- // FIXME: make me pretty ^_^
83
+ // FIXME: make me even prettier, maybe? ^_^
84
84
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
+ }
117
118
} 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" );
120
120
}
121
121
122
122
// convert pull
@@ -128,7 +128,7 @@ static void js_gpio_init(struct mjs* mjs) {
128
128
} else if (strcmp (pull , "down" ) == 0 ) {
129
129
pull_mode = GpioPullDown ;
130
130
} 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" );
132
132
}
133
133
134
134
// get state
@@ -410,7 +410,7 @@ static void js_gpio_destroy(void* inst) {
410
410
// The module destructor is only ever called shortly before the mjs
411
411
// destructor is called, which may not free our owned object. It looks
412
412
// like it does do so (since no memory leaks manifest themselves),
413
- // but idk \(-_-)/
413
+ // but idk, seems janky \(-_-)/
414
414
}
415
415
416
416
// free buffers
@@ -423,6 +423,8 @@ static void js_gpio_destroy(void* inst) {
423
423
furi_record_close (RECORD_EXPANSION );
424
424
}
425
425
426
+ // TODO: ADC
427
+
426
428
static const JsModuleDescriptor js_gpio_desc = {
427
429
"gpio" ,
428
430
js_gpio_create ,
0 commit comments