Skip to content

Commit 9348a85

Browse files
committed
mcu targets: store timezone & dst from debugger connection; use when debugger not available
1 parent 21b7192 commit 9348a85

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed

manifest_core.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,30 @@
3939
"~": [
4040
"$(BUILD)/devices/esp/setup/network"
4141
],
42-
"setup/network": "./setupwifi"
43-
}
42+
"setup/network": "./setupwifi",
43+
"setup/timezone": "./setuptimezone"
44+
},
45+
"preload": "setup/timezone"
4446
},
4547
"esp32": {
4648
"modules": {
4749
"~": [
4850
"$(BUILD)/devices/esp32/setup/network"
4951
],
50-
"setup/network": "./setupwifi"
51-
}
52+
"setup/network": "./setupwifi",
53+
"setup/timezone": "./setuptimezone"
54+
},
55+
"preload": "setup/timezone"
5256
},
5357
"pico": {
5458
"modules": {
5559
"~": [
5660
"$(BUILD)/devices/pico/setup/network"
5761
],
58-
"setup/network": "./setupwifi"
59-
}
62+
"setup/network": "./setupwifi",
63+
"setup/timezone": "./setuptimezone"
64+
},
65+
"preload": "setup/timezone"
6066
}
6167
}
6268
}

nodered.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Moddable Tech, Inc.
2+
* Copyright (c) 2022-2023 Moddable Tech, Inc.
33
*
44
* This file is part of the Moddable SDK Runtime.
55
*
@@ -40,6 +40,14 @@ void xs_nodered_util_generateId(xsMachine *the)
4040
xsmcSetStringBuffer(xsResult, id, sizeof(id));
4141
}
4242

43+
void xs_nodered_util_debugging(xsMachine *the)
44+
{
45+
#ifdef mxDebug
46+
extern xsBooleanValue fxIsConnected(xsMachine* the);
47+
xsmcSetBoolean(xsResult, fxIsConnected(the));
48+
#endif
49+
}
50+
4351
void xs_buffer_prototype_indexOf(xsMachine *the)
4452
{
4553
int offset = 0;

nodered.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const configFlowID = "__config";
3434
const globalContextID = "__global";
3535

3636
function generateId() @ "xs_nodered_util_generateId";
37+
function debugging() @ "xs_nodered_util_debugging";
3738

3839
class RED {
3940
static #compatibility = [];
@@ -104,6 +105,7 @@ class RED {
104105
}
105106
}
106107
static mcu = class {
108+
static debugging = debugging;
107109
static getNodeConstructor(type) {
108110
const Class = nodeClasses.get(type);
109111
if (!Class) {

setuptimezone.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2023 Moddable Tech, Inc.
3+
*
4+
* This file is part of the Moddable SDK Runtime.
5+
*
6+
* The Moddable SDK Runtime is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* The Moddable SDK Runtime is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
*/
20+
21+
import "nodered"; // import for global side effects
22+
import Time from "time";
23+
import Preference from "preference";
24+
25+
export default function (done) {
26+
const timezone = Preference.get("time", "zone");
27+
const dst = Preference.get("time", "dst");
28+
if (RED.mcu.debugging()) {
29+
if (Time.timezone !== timezone)
30+
Preference.set("time", "zone", Time.timezone);
31+
if (Time.dst !== dst)
32+
Preference.set("time", "dst", Time.dst);
33+
}
34+
else if ((undefined !== timezone) && (undefined !== dst)) {
35+
Time.timezone = timezone;
36+
Time.dst = dst;
37+
}
38+
39+
done();
40+
}

0 commit comments

Comments
 (0)