Skip to content

Commit 03b715d

Browse files
Add .d.ts files and rename C++ functions to not shadow TS counterpart.
1 parent c975d8b commit 03b715d

File tree

5 files changed

+159
-50
lines changed

5 files changed

+159
-50
lines changed

enums.d.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Auto-generated. Do not edit.
2+
3+
4+
/**
5+
* (c) 2021, Micro:bit Educational Foundation and contributors
6+
*
7+
* SPDX-License-Identifier: MIT
8+
*/
9+
10+
declare const enum FullPowerSource {
11+
//% block="button A"
12+
A = 1, // MICROBIT_ID_BUTTON_A
13+
//% block="button B"
14+
B = 2, // MICROBIT_ID_BUTTON_B
15+
//% block="pin P0"
16+
P0 = 100, // MICROBIT_ID_IO_P0
17+
//% block="pin P1"
18+
P1 = 101, // MICROBIT_ID_IO_P1
19+
//% block="pin P2"
20+
P2 = 102, // MICROBIT_ID_IO_P2
21+
}
22+
23+
24+
declare const enum LowPowerMode {
25+
//% block="continue"
26+
Continue = 0,
27+
//% block="wait"
28+
Wait = 1,
29+
}
30+
31+
32+
declare const enum LowPowerEnable {
33+
//% block="prevent"
34+
Prevent = 0,
35+
//% block="allow"
36+
Allow = 1,
37+
}
38+
declare namespace power {
39+
}
40+
41+
// Auto-generated. Do not edit. Really.

power.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ enum class LowPowerMode {
4040

4141
enum class LowPowerEnable {
4242
//% block="prevent"
43-
Prevent,
43+
Prevent = 0,
4444
//% block="allow"
45-
Allow
45+
Allow = 1
4646
};
4747

4848

@@ -55,7 +55,7 @@ namespace power {
5555
int timerEventValue = 1;
5656
#endif // MICROBIT_CODAL
5757

58-
void lowPowerRequest(LowPowerMode mode = LowPowerMode::Continue);
58+
void _lowPowerRequest(LowPowerMode mode = LowPowerMode::Continue);
5959

6060
/**
6161
* Request low power when the next idle
@@ -66,7 +66,7 @@ void lowPowerRequest(LowPowerMode mode = LowPowerMode::Continue);
6666
//% weight=700
6767
//% block="request low power||and $mode"
6868
//%
69-
void lowPowerRequest(LowPowerMode mode) {
69+
void _lowPowerRequest(LowPowerMode mode) {
7070
#if MICROBIT_CODAL
7171
if ( mode == LowPowerMode::Wait)
7272
uBit.power.deepSleep();
@@ -88,7 +88,7 @@ void lowPowerRequest(LowPowerMode mode) {
8888
//% interval.shadow=longTimePicker
8989
//% block="request low power for $interval ms"
9090
//%
91-
void lowPowerPause(int interval) {
91+
void _lowPowerPause(int interval) {
9292
#if MICROBIT_CODAL
9393
uBit.power.deepSleep(interval);
9494
#else
@@ -106,7 +106,7 @@ void lowPowerPause(int interval) {
106106
//% weight=500
107107
//% block="low power %enable"
108108
//%
109-
void lowPowerEnable(LowPowerEnable enable) {
109+
void _lowPowerEnable(LowPowerEnable enable) {
110110
#if MICROBIT_CODAL
111111
switch ( enable)
112112
{
@@ -130,7 +130,7 @@ void lowPowerEnable(LowPowerEnable enable) {
130130
*/
131131
//% help=power/low-power-is-enabled
132132
//%
133-
bool lowPowerIsEnabled() {
133+
bool _lowPowerIsEnabled() {
134134
#if MICROBIT_CODAL
135135
return uBit.power.powerDownIsEnabled();
136136
#else
@@ -152,7 +152,7 @@ bool lowPowerIsEnabled() {
152152
//% afterOnStart=true
153153
//% block="full power every $interval ms"
154154
//%
155-
void fullPowerEvery(int interval, Action code) {
155+
void _fullPowerEvery(int interval, Action code) {
156156
#if MICROBIT_CODAL
157157
registerWithDal( MICROBIT_ID_MAKECODE_POWER, timerEventValue, code);
158158
// CODAL_TIMER_EVENT_FLAGS_WAKEUP makes the timer event trigger power up
@@ -171,7 +171,7 @@ void fullPowerEvery(int interval, Action code) {
171171
*/
172172
//% help=power/full-power-source-enable
173173
//%
174-
void fullPowerSourceEnable(FullPowerSource source, bool enable) {
174+
void _fullPowerSourceEnable(FullPowerSource source, bool enable) {
175175
#if MICROBIT_CODAL
176176
switch ( source)
177177
{
@@ -205,7 +205,7 @@ void fullPowerSourceEnable(FullPowerSource source, bool enable) {
205205
*/
206206
//% help=power/full-power-source-is-enabled
207207
//%
208-
bool fullPowerSourceIsEnabled(FullPowerSource source) {
208+
bool _fullPowerSourceIsEnabled(FullPowerSource source) {
209209
#if MICROBIT_CODAL
210210
switch ( source)
211211
{
@@ -242,8 +242,8 @@ bool fullPowerSourceIsEnabled(FullPowerSource source) {
242242
//% weight=900
243243
//% block="full power on %source"
244244
//%
245-
void fullPowerOn(FullPowerSource source) {
246-
fullPowerSourceEnable(source, true);
245+
void _fullPowerOn(FullPowerSource source) {
246+
_fullPowerSourceEnable(source, true);
247247
}
248248

249249

power.ts

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,6 @@
44
* SPDX-License-Identifier: MIT
55
*/
66

7-
const enum FullPowerSource {
8-
//% block="button A"
9-
A = DAL.MICROBIT_ID_BUTTON_A, // 1
10-
//% block="button B"
11-
B = DAL.MICROBIT_ID_BUTTON_B, // 2
12-
//% block="pin P0"
13-
P0 = DAL.MICROBIT_ID_IO_P0, // 100
14-
//% block="pin P1"
15-
P1 = DAL.MICROBIT_ID_IO_P1, // 101
16-
//% block="pin P2"
17-
P2 = DAL.MICROBIT_ID_IO_P2 // 102
18-
}
19-
20-
21-
const enum LowPowerMode {
22-
//% block="continue"
23-
Continue = 0,
24-
//% block="wait"
25-
Wait = 1
26-
}
27-
28-
29-
const enum LowPowerEnable {
30-
//% block="prevent"
31-
Prevent = 0,
32-
//% block="allow"
33-
Allow = 1
34-
}
35-
36-
377
//% block="Power"
388
//% icon="\uf011"
399
//% color=#AA278D
@@ -48,7 +18,7 @@ namespace power {
4818
//% weight=700
4919
//% block="request low power||and $mode"
5020
//% parts="v2"
51-
//% shim=power::lowPowerRequest
21+
//% shim=power::_lowPowerRequest
5222
export function lowPowerRequest(mode?: LowPowerMode): void {
5323
basic.pause(0)
5424
}
@@ -63,7 +33,7 @@ export function lowPowerRequest(mode?: LowPowerMode): void {
6333
//% interval.shadow=longTimePicker
6434
//% block="request low power for $interval ms"
6535
//% parts="v2"
66-
//% shim=power::lowPowerPause
36+
//% shim=power::_lowPowerPause
6737
export function lowPowerPause(interval: number): void {
6838
basic.pause(interval)
6939
}
@@ -77,7 +47,7 @@ export function lowPowerPause(interval: number): void {
7747
//% weight=500
7848
//% block="low power %enable"
7949
//% parts="v2"
80-
//% shim=power::lowPowerEnable
50+
//% shim=power::_lowPowerEnable
8151
export function lowPowerEnable(enable: LowPowerEnable): void {
8252
return
8353
}
@@ -86,7 +56,7 @@ export function lowPowerEnable(enable: LowPowerEnable): void {
8656
* Determine if low power is enabled
8757
*/
8858
//% help=power/low-power-is-enabled
89-
//% shim=power::lowPowerIsEnabled
59+
//% shim=power::_lowPowerIsEnabled
9060
export function lowPowerIsEnabled(): boolean {
9161
return false
9262
}
@@ -104,7 +74,7 @@ export function lowPowerIsEnabled(): boolean {
10474
//% afterOnStart=true
10575
//% block="full power every $interval ms"
10676
//% parts="v2"
107-
//% shim=power::fullPowerEvery
77+
//% shim=power::_fullPowerEvery
10878
export function fullPowerEvery(interval: number, code: () => void): void {
10979
loops.everyInterval(interval, code)
11080
}
@@ -115,7 +85,7 @@ export function fullPowerEvery(interval: number, code: () => void): void {
11585
* @param enable true to trigger full power
11686
*/
11787
//% help=power/full-power-source-enable
118-
//% shim=power::fullPowerSourceEnable
88+
//% shim=power::_fullPowerSourceEnable
11989
export function fullPowerSourceEnable(source: FullPowerSource, enable: boolean): void {
12090
return
12191
}
@@ -126,7 +96,7 @@ export function fullPowerSourceEnable(source: FullPowerSource, enable: boolean):
12696
* @return true if the source will trigger full power
12797
*/
12898
//% help=power/full-power-source-is-enabled
129-
//% shim=power::fullPowerSourceIsEnabled
99+
//% shim=power::_fullPowerSourceIsEnabled
130100
export function fullPowerSourceIsEnabled(source: FullPowerSource): boolean {
131101
return false
132102
}
@@ -140,7 +110,7 @@ export function fullPowerSourceIsEnabled(source: FullPowerSource): boolean {
140110
//% weight=900
141111
//% block="full power on %source"
142112
//% parts="v2"
143-
//% shim=power::fullPowerOn
113+
//% shim=power::_fullPowerOn
144114
export function fullPowerOn(source: FullPowerSource): void {
145115
return
146116
}

pxt.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"files": [
99
"power.cpp",
1010
"power.ts",
11+
"shims.d.ts",
12+
"enums.d.ts",
1113
"README.md",
1214
"basic-sleep-wake.md"
1315
],

shims.d.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Auto-generated. Do not edit.
2+
3+
4+
5+
//% block="Power"
6+
//% icon="\uf011"
7+
//% color=#AA278D
8+
declare namespace power {
9+
10+
/**
11+
* Request low power when the next idle
12+
* @param mode If Continue, then return immediately; if Wait, then pause until a power-up event occurs
13+
*/
14+
//% help=power/low-power-request
15+
//% group="micro:bit (V2)"
16+
//% weight=700
17+
//% block="request low power||and $mode"
18+
//% shim=power::_lowPowerRequest
19+
function _lowPowerRequest(mode: LowPowerMode): void;
20+
21+
/**
22+
* Pause for a fixed interval, and request low power when idle.
23+
* @param interval The period of time to pause, in milliseconds.
24+
*/
25+
//% help=power/low-power-for
26+
//% group="micro:bit (V2)"
27+
//% weight=600
28+
//% interval.shadow=longTimePicker
29+
//% block="request low power for $interval ms"
30+
//% shim=power::_lowPowerPause
31+
function _lowPowerPause(interval: int32): void;
32+
33+
/**
34+
* Prevent or allow low power.
35+
* Prevent and allow requests should occur in pairs.
36+
* The default is to allow.
37+
*/
38+
//% help=power/low-power-enable
39+
//% weight=500
40+
//% block="low power %enable"
41+
//% shim=power::_lowPowerEnable
42+
function _lowPowerEnable(enable: LowPowerEnable): void;
43+
44+
/**
45+
* Determine if low power is enabled
46+
*/
47+
//% help=power/low-power-is-enabled
48+
//% shim=power::_lowPowerIsEnabled
49+
function _lowPowerIsEnabled(): boolean;
50+
51+
/**
52+
* Do something repeatedy with full power using a timer.
53+
* @param interval the time (in ms) for the timer.
54+
* @param code the code to execute
55+
*/
56+
//% help=power/full-power-every
57+
//% group="micro:bit (V2)"
58+
//% weight=800
59+
//% blockAllowMultiple=1
60+
//% interval.shadow=longTimePicker
61+
//% afterOnStart=true
62+
//% block="full power every $interval ms"
63+
//% shim=power::_fullPowerEvery
64+
function _fullPowerEvery(interval: int32, code: () => void): void;
65+
66+
/**
67+
* Set whether the source should trigger full power.
68+
* @param source the source to set
69+
* @param enable true to trigger full power
70+
*/
71+
//% help=power/full-power-source-enable
72+
//% shim=power::_fullPowerSourceEnable
73+
function _fullPowerSourceEnable(source: FullPowerSource, enable: boolean): void;
74+
75+
/**
76+
* Determine if the source will trigger full power.
77+
* @param source the source to check
78+
* @return true if the source will trigger full power
79+
*/
80+
//% help=power/full-power-source-is-enabled
81+
//% shim=power::_fullPowerSourceIsEnabled
82+
function _fullPowerSourceIsEnabled(source: FullPowerSource): boolean;
83+
84+
/**
85+
* Set the source to trigger full power.
86+
* @param source the source to set
87+
*/
88+
//% help=power/full-power-on
89+
//% group="micro:bit (V2)"
90+
//% weight=900
91+
//% block="full power on %source"
92+
//% shim=power::_fullPowerOn
93+
function _fullPowerOn(source: FullPowerSource): void;
94+
}
95+
96+
// Auto-generated. Do not edit. Really.

0 commit comments

Comments
 (0)