Merge branch 'master' into on_color_fix

This commit is contained in:
Peli de Halleux
2017-12-13 15:48:24 -08:00
11 changed files with 49 additions and 332 deletions

View File

@ -54,7 +54,6 @@
"motors.Motor.count": "Gets motor step count.",
"motors.Motor.move": "Moves the motor by a number of degrees",
"motors.Motor.move|param|angle": "the degrees to rotate, eg: 360",
"motors.Motor.move|param|power": "the power from ``100`` full forward to ``-100`` full backward, eg: 50",
"motors.Motor.reset": "Resets the motor.",
"motors.Motor.setBrake": "Sets the automatic brake on or off when the motor is off",
"motors.Motor.setBrake|param|brake": "a value indicating if the motor should break when off",

View File

@ -36,7 +36,7 @@
"control.raiseEvent|block": "raise event|from %src|with value %value",
"control|block": "control",
"motors.Motor.count|block": "`icons.motorLarge` %motor|count",
"motors.Motor.move|block": "move `icons.motorLarge` %motor|by %angle|degrees at %power|%",
"motors.Motor.move|block": "move `icons.motorLarge` %motor|by %angle|degrees at %speed|%",
"motors.Motor.setBrake|block": "set `icons.motorLarge` %motor|brake %brake",
"motors.Motor.setReversed|block": "set `icons.motorLarge` %motor|reversed %reversed",
"motors.Motor.setSpeed|block": "set speed `icons.motorLarge` %motor|to %speed|%",

View File

@ -13,14 +13,35 @@
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <malloc.h>
#define THREAD_DBG(...)
#define MALLOC_LIMIT (8 * 1024 * 1024)
#define MALLOC_CHECK_PERIOD (1024 * 1024)
void *xmalloc(size_t sz) {
static size_t allocBytes = 0;
allocBytes += sz;
if (allocBytes >= MALLOC_CHECK_PERIOD) {
allocBytes = 0;
auto info = mallinfo();
DMESG("malloc used: %d kb", info.uordblks / 1024);
if (info.uordblks > MALLOC_LIMIT) {
target_panic(904);
}
}
auto r = malloc(sz);
if (r == NULL)
target_panic(905); // shouldn't happen
return r;
}
void *operator new(size_t size) {
return malloc(size);
return xmalloc(size);
}
void *operator new[](size_t size) {
return malloc(size);
return xmalloc(size);
}
void operator delete(void *p) {

View File

@ -93,7 +93,7 @@ namespace motors {
*/
//% blockId=motorSetSpeed block="set speed `icons.motorLarge` %motor|to %speed|%"
//% weight=99 group="Motors" blockGap=8
//% power.min=-100 power.max=100
//% speed.min=-100 speed.max=100
setSpeed(speed: number) {
speed = Math.clamp(-100, 100, speed >> 0);
@ -113,11 +113,11 @@ namespace motors {
* Moves the motor by a number of degrees
* @param degrees the angle to turn the motor
* @param angle the degrees to rotate, eg: 360
* @param power the power from ``100`` full forward to ``-100`` full backward, eg: 50
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
*/
//% blockId=motorMove block="move `icons.motorLarge` %motor|by %angle|degrees at %power|%"
//% blockId=motorMove block="move `icons.motorLarge` %motor|by %angle|degrees at %speed|%"
//% weight=98 group="Motors" blockGap=8
//% power.min=-100 power.max=100
//% speed.min=-100 speed.max=100
move(angle: number, power: number) {
angle = angle >> 0;
power = Math.clamp(-100, 100, power >> 0);

View File

@ -88,7 +88,7 @@ Image unpackPNG(Buffer png) {
uint32_t byteW = (hd.width + 7) >> 3;
uint32_t expSize = (byteW + 1) * hd.height;
unsigned long sz = expSize;
uint8_t *tmp = (uint8_t *)malloc(sz);
uint8_t *tmp = (uint8_t *)xmalloc(sz);
int code = uncompress(tmp, &sz, png->data + sizeof(hd), hd.lenIDAT);
if (code != 0) {
DMESG("PNG: zlib failed: %d", code);

View File

@ -3,6 +3,8 @@
#include "pxtbase.h"
void *xmalloc(size_t sz);
namespace pxt {
void raiseEvent(int id, int event);
int allocateNotifyEvent();

View File

@ -1,51 +1,36 @@
screen.clear()
screen.print("PXT!", 10, 30, Draw.Quad)
brick.print("PXT!", 10, 30, Draw.Quad)
screen.drawRect(40, 40, 20, 10, Draw.Fill)
motors.setStatusLight(LightsPattern.Orange)
brick.drawRect(40, 40, 20, 10, Draw.Fill)
brick.setStatusLight(LightsPattern.Orange)
screen.heart.doubled().draw(100, 50, Draw.Double | Draw.Transparent)
brick.heart.doubled().draw(100, 50, Draw.Double | Draw.Transparent)
sensors.buttonEnter.onEvent(ButtonEvent.Click, () => {
brick.buttonEnter.onEvent(ButtonEvent.Click, () => {
screen.clear()
})
sensors.buttonLeft.onEvent(ButtonEvent.Click, () => {
screen.drawRect(10, 70, 20, 10, Draw.Fill)
motors.setStatusLight(LightsPattern.Red)
screen.setFont(screen.microbitFont())
brick.buttonLeft.onEvent(ButtonEvent.Click, () => {
brick.drawRect(10, 70, 20, 10, Draw.Fill)
brick.setStatusLight(LightsPattern.Red)
brick.setFont(brick.microbitFont())
})
sensors.buttonRight.onEvent(ButtonEvent.Click, () => {
screen.print("Right!", 10, 60)
brick.buttonRight.onEvent(ButtonEvent.Click, () => {
brick.print("Right!", 10, 60)
})
sensors.buttonDown.onEvent(ButtonEvent.Click, () => {
screen.print("Down! ", 10, 60)
brick.buttonDown.onEvent(ButtonEvent.Click, () => {
brick.print("Down! ", 10, 60)
})
sensors.buttonUp.onEvent(ButtonEvent.Click, () => {
screen.print("Up! ", 10, 60)
brick.buttonUp.onEvent(ButtonEvent.Click, () => {
brick.print("Up! ", 10, 60)
})
let num = 0
sensors.touchSensor1.onEvent(TouchSensorEvent.Bumped, () => {
screen.print("Click! " + num, 10, 60)
num++
})
sensors.remoteButtonTopLeft.onEvent(ButtonEvent.Click, () => {
screen.print("TOPLEFT " + num, 10, 60)
num++
})
sensors.remoteButtonTopRight.onEvent(ButtonEvent.Down, () => {
screen.print("TOPRIGH " + num, 10, 60)
num++
})
loops.forever(() => {
serial.writeDmesg()
loops.pause(100)