Skip to content

Commit 9c3c192

Browse files
authored
Merge pull request #20 from CleoQc/master
Fix radio blocks due to Makecode V2.0.9
2 parents 2d23706 + d48e44d commit 9c3c192

3 files changed

Lines changed: 17 additions & 29 deletions

File tree

_locales/fr/giggle-strings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"gigglebotEyeAction.Close|block": "ouvrir",
3-
"gigglebotEyeAction.Open|block": "fermer",
2+
"gigglebotEyeAction.Close|block": "fermer",
3+
"gigglebotEyeAction.Open|block": "ouvrir",
44
"gigglebotWhichEye.Both|block": "les deux yeux",
55
"gigglebotWhichEye.Left|block": "l'œil gauche",
66
"gigglebotWhichEye.Right|block": "l'œil droit",

giggle.ts

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace lights {
5050
stripNeopixel.setPixelColor(_i, neopixel.colors(NeoPixelColors.Black))
5151
}
5252
stripNeopixel.show()
53-
if (gigglebot.voltageBattery() < 3400) {
53+
if (gigglebot.voltageBattery() < 3600) {
5454
eyeColorLeft = neopixel.colors(NeoPixelColors.Red)
5555
eyeColorRight = neopixel.colors(NeoPixelColors.Red)
5656
}
@@ -150,7 +150,7 @@ namespace remote {
150150
/**
151151
* In order to have a remote micro:bit control the GiggleBot, both of them
152152
* must be in the same radio group - or remote group. You can use either this
153-
* block or the "radio set group" block found under Radio.
153+
* block or the "radio set group" block found under Radio.
154154
* The two blocks are the same thing.
155155
* Make sure your set of remote microbit and gigglebot is assigned a unique
156156
* group, especially if there are many gigglebot pairs around you.
@@ -181,7 +181,7 @@ namespace remote {
181181
powerLeft = Math.idiv((powerLeft * -1 * input.acceleration(Dimension.Y)), 512) + Math.idiv((50 * input.acceleration(Dimension.X)), 512)
182182
powerRight = Math.idiv((powerRight * -1 * input.acceleration(Dimension.Y)), 512) - Math.idiv((50 * input.acceleration(Dimension.X)), 512)
183183
// limit those values from -100 to 100
184-
powerLeft = Math.min(Math.max(powerLeft, -100), 100)
184+
powerLeft = Math.min(Math.max(powerLeft, -100), 100)
185185
powerRight = Math.min(Math.max(powerRight, -100), 100)
186186

187187
// Buffer is 8 bytes
@@ -191,20 +191,6 @@ namespace remote {
191191
radio.sendBuffer(buf)
192192
}
193193

194-
export let lastPacket: radio.RadioPacket;
195-
let initialized = false;
196-
197-
function remote_init() {
198-
if (initialized) return;
199-
initialized = true;
200-
201-
radio.onDataReceived(() => {
202-
lastPacket = radio.RadioPacket.getPacket(radio.readRawPacket());
203-
control.raiseEvent(DAL.MICROBIT_ID_RADIO, radio.MAKECODE_RADIO_EVT_BUFFER);
204-
})
205-
}
206-
207-
208194
/**
209195
* Use this block on the GiggleBot to control it with a second micro:bit
210196
* @param radioBlock eg:1
@@ -215,11 +201,8 @@ namespace remote {
215201
//% useLoc="radio.onDataPacketReceived" draggableParameters=reporter
216202
//% group="GiggleBot:"
217203
export function onRemoteControl(cb: () => void) {
218-
remote_init();
219-
control.onEvent(DAL.MICROBIT_ID_RADIO, radio.MAKECODE_RADIO_EVT_BUFFER, () => {
220-
cb();
221-
});
222-
}
204+
radio.onReceivedBuffer(cb)
205+
};
223206

224207
/**
225208
* Put this block inside of the 'remotely controlled gigglebot' to follow all comands received via remote control.
@@ -229,12 +212,17 @@ namespace remote {
229212
//% weight=97
230213
//% group="GiggleBot:"
231214
export function remoteControlAction(): void {
232-
let powerLeft = lastPacket.bufferPayload.getNumber(NumberFormat.Float32BE, 0);
233-
let powerRight = lastPacket.bufferPayload.getNumber(NumberFormat.Float32BE, 4);
234215

216+
if (radio.lastPacket == null) {
217+
return;
218+
}
219+
220+
let powerLeft = radio.lastPacket.bufferPayload.getNumber(NumberFormat.Float32BE, 0);
221+
let powerRight = radio.lastPacket.bufferPayload.getNumber(NumberFormat.Float32BE, 4);
235222
gigglebot.setLeftPower(powerLeft)
236-
gigglebot.setRightPower(powerRight)
223+
gigglebot.setRightPower(powerRight);
237224
gigglebot.motorPowerAssignBoth(gigglebot.leftPower(), gigglebot.rightPower())
225+
basic.pause(25)
238226
}
239227

240228
}

pxt.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "giggle",
3-
"version": "1.3.1",
3+
"version": "1.4.0",
44
"dependencies": {
55
"core": "*",
66
"radio": "*",
77
"neopixel": "github:microsoft/pxt-neopixel#v0.6.7",
8-
"gigglebot": "github:dexterind/pxt-gigglebot#v1.2.2",
8+
"gigglebot": "github:dexterind/pxt-gigglebot#v1.3.0",
99
"radio-broadcast": "*"
1010
},
1111
"description": "GiggleBot is a microbit rover by Dexter Industries, it offers a total of 9 neopixels, 2 line sensors, 2 light sensors, and 2 servos",

0 commit comments

Comments
 (0)