Skip to content

Commit

Permalink
Merge pull request espruino#2348 from bobrippling/setui-types
Browse files Browse the repository at this point in the history
Split `setUI` types into overloaded functions
  • Loading branch information
gfwilliams authored Apr 12, 2023
2 parents 4a10815 + 87eeaad commit f9055e6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
44 changes: 30 additions & 14 deletions libs/banglejs/jswrap_bangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ Watch](http://www.espruino.com/Bangle.js)
/*TYPESCRIPT{
"class" : "Bangle"
}
static CLOCK: boolean;
static CLOCK: ShortBoolean;
static strokes: undefined | { [key: string]: Unistroke };
*/
/*TYPESCRIPT
type ShortBoolean = boolean | 0 | 1;
*/


/*JSON{
Expand Down Expand Up @@ -2258,13 +2261,13 @@ void jswrap_banglejs_setPollInterval(JsVarFloat interval) {
}

/*TYPESCRIPT
type BangleOptions = {
wakeOnBTN1: boolean;
wakeOnBTN2: boolean;
wakeOnBTN3: boolean;
wakeOnFaceUp: boolean;
wakeOnTouch: boolean;
wakeOnTwist: boolean;
type BangleOptions<Boolean = boolean> = {
wakeOnBTN1: Boolean;
wakeOnBTN2: Boolean;
wakeOnBTN3: Boolean;
wakeOnFaceUp: Boolean;
wakeOnTouch: Boolean;
wakeOnTwist: Boolean;
twistThreshold: number;
twistMaxY: number;
twistTimeout: number;
Expand All @@ -2288,7 +2291,7 @@ type BangleOptions = {
["options","JsVar",""]
],
"ifdef" : "BANGLEJS",
"typescript" : "setOptions(options: { [key in keyof BangleOptions]?: BangleOptions[key] }): void;"
"typescript" : "setOptions(options: { [key in keyof BangleOptions]?: BangleOptions<ShortBoolean>[key] }): void;"
}
Set internal options used for gestures, etc...
Expand Down Expand Up @@ -2608,7 +2611,7 @@ void jswrap_banglejs_lcdWr(JsVarInt cmd, JsVar *data) {
],
"return" : ["bool","Is HRM on?"],
"ifdef" : "BANGLEJS",
"typescript" : "setHRMPower(isOn: boolean, appID: string): boolean;"
"typescript" : "setHRMPower(isOn: ShortBoolean, appID: string): boolean;"
}
Set the power to the Heart rate monitor
Expand Down Expand Up @@ -2681,7 +2684,7 @@ void gpsClearLine() {
],
"return" : ["bool","Is the GPS on?"],
"ifdef" : "BANGLEJS",
"typescript" : "setGPSPower(isOn: boolean, appID: string): boolean;"
"typescript" : "setGPSPower(isOn: ShortBoolean, appID: string): boolean;"
}
Set the power to the GPS.
Expand Down Expand Up @@ -2771,7 +2774,7 @@ JsVar *jswrap_banglejs_getGPSFix() {
],
"return" : ["bool","Is the Compass on?"],
"ifdef" : "BANGLEJS",
"typescript" : "setCompassPower(isOn: boolean, appID: string): boolean;"
"typescript" : "setCompassPower(isOn: ShortBoolean, appID: string): boolean;"
}
Set the power to the Compass
Expand Down Expand Up @@ -2867,7 +2870,7 @@ void jswrap_banglejs_resetCompass() {
],
"return" : ["bool","Is the Barometer on?"],
"#if" : "defined(DTNO1_F5) || defined(BANGLEJS_Q3) || defined(DICKENS)",
"typescript" : "setBarometerPower(isOn: boolean, appID: string): boolean;"
"typescript" : "setBarometerPower(isOn: ShortBoolean, appID: string): boolean;"
}
Set the power to the barometer IC. Once enabled, `Bangle.pressure` events are
fired each time a new barometer reading is available.
Expand Down Expand Up @@ -5566,6 +5569,13 @@ might expect an LED, this is an object that behaves like a pin, but which just
displays a circle on the display
*/

/*TYPESCRIPT
type SetUIArg<Mode> = Mode | {
mode: Mode,
back?: () => void,
remove?: () => void,
};
*/
/*JSON{
"type" : "staticmethod",
"class" : "Bangle",
Expand All @@ -5576,7 +5586,13 @@ displays a circle on the display
["callback","JsVar","A function with one argument which is the direction"]
],
"ifdef" : "BANGLEJS",
"typescript" : "setUI(type?: \"updown\" | \"leftright\" | \"clock\" | \"clockupdown\" | { mode: \"custom\"; back?: () => void; touch?: TouchCallback; swipe?: SwipeCallback; drag?: DragCallback; btn?: (n: number) => void, remove?: () => void, clock?: boolean }, callback?: (direction?: -1 | 1) => void): void;"
"typescript" : [
"setUI(type?: undefined): void;",
"setUI(type: SetUIArg<\"updown\" | \"leftright\">, callback: (direction?: -1 | 1) => void): void;",
"setUI(type: SetUIArg<\"clock\">): void;",
"setUI(type: SetUIArg<\"clockupdown\">, callback?: (direction: -1 | 1) => void): void;",
"setUI(type: SetUIArg<\"custom\"> & { touch?: TouchCallback; swipe?: SwipeCallback; drag?: DragCallback; btn?: (n: 1 | 2 | 3) => void; clock?: boolean | 0 | 1 }): void;"
]
}
This puts Bangle.js into the specified UI input mode, and calls the callback
provided when there is user input.
Expand Down
7 changes: 5 additions & 2 deletions src/jswrap_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -856,9 +856,12 @@ JsVar *jswrap_interface_setWatch(
"name" : "clearWatch",
"generate" : "jswrap_interface_clearWatch",
"params" : [
["id","JsVarArray","The id returned by a previous call to setWatch. **Only one argument is allowed.**"]
["id","JsVarArray","The id returned by a previous call to setWatch. **Only one argument is allowed.** (or pass nothing to clear all watches)"]
],
"typescript" : "declare function clearWatch(id: number): void;"
"typescript" : [
"declare function clearWatch(id: number): void;",
"declare function clearWatch(): void;"
]
}
Clear the Watch that was created with setWatch. If no parameter is supplied, all watches will be removed.
Expand Down
2 changes: 1 addition & 1 deletion src/jswrap_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ void jswrap_object_removeListener(JsVar *parent, JsVar *event, JsVar *callback)
"name" : "removeAllListeners",
"generate" : "jswrap_object_removeAllListeners",
"params" : [
["event","JsVar","The name of the event, for instance `'data'`. If not specified *all* listeners are removed."]
["event","JsVar","[optional] The name of the event, for instance `'data'`. If not specified *all* listeners are removed."]
]
}
Removes all listeners (if `event===undefined`), or those of the specified event.
Expand Down

0 comments on commit f9055e6

Please sign in to comment.