Merge branch 'master' into waitUntiltopauseUntil
This commit is contained in:
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include "pxtbase.h"
|
||||
|
||||
void *xmalloc(size_t sz);
|
||||
|
||||
namespace pxt {
|
||||
void raiseEvent(int id, int event);
|
||||
int allocateNotifyEvent();
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user