Skip to content

Commit 6ca54db

Browse files
committed
Ensure that pinMode/digitalWrite is re-constituted properly by dump() and save() (fix #833)
1 parent e1622a7 commit 6ca54db

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Add `E.setBootCode` to allow JS scripts to be run without being in RAM (fix #740)
1414
'Expecting a number or something iterable, got X' changed to exception rather than warning (gives stack trace)
1515
Drop '.init' and '.fini' symbols, allowing GCC 5.x compilation on STM32
16+
Ensure that pinMode/digitalWrite is re-constituted properly by dump() and save() (fix #833)
1617

1718
1v85 : Ensure HttpServerResponse.writeHead actually sends the header right away
1819
- enables WebSocket Server support from JS

src/jsinteractive.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "jsinteractive.h"
1616
#include "jshardware.h"
1717
#include "jstimer.h"
18+
#include "jspin.h"
1819
#include "jswrapper.h"
1920
#include "jswrap_json.h"
2021
#include "jswrap_io.h"
@@ -640,11 +641,11 @@ void jsiDumpHardwareInitialisation(vcbprintf_callback user_callback, void *user_
640641
if (IS_PIN_USED_INTERNALLY(pin)) continue;
641642
JshPinState state = jshPinGetState(pin);
642643
JshPinState statem = state&JSHPINSTATE_MASK;
643-
if (statem == JSHPINSTATE_GPIO_OUT || statem == JSHPINSTATE_GPIO_OUT_OPENDRAIN) {
644+
if (statem == JSHPINSTATE_GPIO_OUT && !jshGetPinStateIsManual(pin)) {
644645
bool isOn = (state&JSHPINSTATE_PIN_IS_ON)!=0;
645646
if (!isOn && IS_PIN_A_LED(pin)) continue;
646-
cbprintf(user_callback, user_data, "digitalWrite(%p,%d);\n",pin,isOn?1:0);
647-
} else if (/*statem == JSHPINSTATE_GPIO_IN ||*/statem == JSHPINSTATE_GPIO_IN_PULLUP || statem == JSHPINSTATE_GPIO_IN_PULLDOWN) {
647+
cbprintf(user_callback, user_data, "digitalWrite(%p, %d);\n",pin,isOn?1:0);
648+
} else {
648649
#ifdef DEFAULT_CONSOLE_RX_PIN
649650
// the console input pin is always a pullup now - which is expected
650651
if (pin == DEFAULT_CONSOLE_RX_PIN &&
@@ -655,14 +656,15 @@ void jsiDumpHardwareInitialisation(vcbprintf_callback user_callback, void *user_
655656
statem == BTN1_PINSTATE) continue;
656657
#endif
657658
// don't bother with normal inputs, as they come up in this state (ish) anyway
658-
const char *s = "";
659-
if (statem == JSHPINSTATE_GPIO_IN_PULLUP) s="_pullup";
660-
if (statem == JSHPINSTATE_GPIO_IN_PULLDOWN) s="_pulldown";
661-
cbprintf(user_callback, user_data, "pinMode(%p,\"input%s\");\n",pin,s);
659+
const char *s = 0;
660+
// JSHPINSTATE_GPIO_IN is the default - don't do anything for it
661+
if (statem == JSHPINSTATE_GPIO_IN_PULLUP) s="input_pullup";
662+
else if (statem == JSHPINSTATE_GPIO_IN_PULLDOWN) s="input_pulldown";
663+
else if (statem == JSHPINSTATE_GPIO_OUT) s="output";
664+
else if (statem == JSHPINSTATE_GPIO_OUT_OPENDRAIN) s="opendrain";
665+
if (s) cbprintf(user_callback, user_data, "pinMode(%p, \"%s\");\n",pin,s);
662666
}
663667

664-
if (statem == JSHPINSTATE_GPIO_OUT_OPENDRAIN)
665-
cbprintf(user_callback, user_data, "pinMode(%p,\"opendrain\");\n",pin);
666668
}
667669
}
668670

0 commit comments

Comments
 (0)