Add music

This commit is contained in:
Michal Moskal
2017-07-07 11:44:34 +01:00
parent 43b167957b
commit 97b6c7dc4b
13 changed files with 166 additions and 5 deletions

25
libs/core/control.cpp Normal file
View File

@ -0,0 +1,25 @@
#include "pxt.h"
namespace control {
/**
* Announce that an event happened to registered handlers.
* @param src ID of the Component that generated the event
* @param value Component specific code indicating the cause of the event.
* @param mode optional definition of how the event should be processed after construction.
*/
//% weight=21 blockGap=12 blockId="control_raise_event"
//% block="raise event|from %src|with value value" blockExternalInputs=1
void raiseEvent(int src, int value) {
pxt::raiseEvent(src, value);
}
/**
* Allocates the next user notification event
*/
//% help=control/allocate-notify-event
int allocateNotifyEvent() {
return pxt::allocateNotifyEvent();
}
}

3
libs/core/dal.d.ts vendored
View File

@ -647,6 +647,9 @@ declare const enum DAL {
// built/dockermake/node_modules/ev3api-bin/include/uart.h
// built/dockermake/pxtapp/pxt.h
ID_BUTTON_BASE = 100,
DEVICE_EVT_ANY = 0,
DEVICE_ID_NOTIFY = 10000,
DEVICE_ID_NOTIFY_ONE = 10001,
// built/dockermake/pxtapp/pxtbase.h
PXT_REF_TAG_STRING = 1,
PXT_REF_TAG_BUFFER = 2,

View File

@ -9,8 +9,6 @@
#include <assert.h>
#include <unistd.h>
#define DEVICE_EVT_ANY 0
void *operator new(size_t size) {
return malloc(size);
}
@ -237,6 +235,14 @@ static void *evtDispatcher(void *dummy) {
}
}
int allocateNotifyEvent() {
static volatile int notifyId;
pthread_mutex_lock(&eventMutex);
int res = ++notifyId;
pthread_mutex_unlock(&eventMutex);
return res;
}
void raiseEvent(int id, int event) {
auto e = mkEvent(id, event);
pthread_mutex_lock(&eventMutex);
@ -293,5 +299,4 @@ void dmesg(const char *format, ...) {
fflush(dmesgFile);
fdatasync(fileno(dmesgFile));
}
}

View File

@ -7,6 +7,7 @@
namespace pxt {
void raiseEvent(int id, int event);
int allocateNotifyEvent();
void sleep_core_us(uint64_t us);
class Button;
@ -15,4 +16,8 @@ typedef Button *Button_;
extern "C" void target_init();
}
#define DEVICE_EVT_ANY 0
#define DEVICE_ID_NOTIFY 10000
#define DEVICE_ID_NOTIFY_ONE 10001
#endif

View File

@ -7,6 +7,7 @@
"pxt.h",
"pxtcore.h",
"linux.cpp",
"control.cpp",
"buttons.cpp",
"screen.cpp",
"screen.ts",

18
libs/core/shims.d.ts vendored
View File

@ -1,4 +1,22 @@
// Auto-generated. Do not edit.
declare namespace control {
/**
* Announce that an event happened to registered handlers.
* @param src ID of the Component that generated the event
* @param value Component specific code indicating the cause of the event.
* @param mode optional definition of how the event should be processed after construction.
*/
//% weight=21 blockGap=12 blockId="control_raise_event"
//% block="raise event|from %src|with value value" blockExternalInputs=1 shim=control::raiseEvent
function raiseEvent(src: int32, value: int32): void;
/**
* Allocates the next user notification event
*/
//% help=control/allocate-notify-event shim=control::allocateNotifyEvent
function allocateNotifyEvent(): int32;
}
declare namespace input {
/**