Implementing dmesg and serial store
This commit is contained in:
parent
dfb3f9fbeb
commit
7ccdabb4d4
@ -7,20 +7,10 @@
|
||||
#include <cstdarg>
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define DEVICE_EVT_ANY 0
|
||||
|
||||
void dmesg(const char *format, ...) {
|
||||
char buf[500];
|
||||
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
vsnprintf(buf, sizeof(buf), format, arg);
|
||||
va_end(arg);
|
||||
|
||||
fprintf(stderr, "DMESG: %s\n", buf);
|
||||
}
|
||||
|
||||
void *operator new(size_t size) {
|
||||
return malloc(size);
|
||||
}
|
||||
@ -41,6 +31,8 @@ static int startTime;
|
||||
static pthread_mutex_t execMutex;
|
||||
static pthread_mutex_t eventMutex;
|
||||
static pthread_cond_t newEventBroadcast;
|
||||
static FILE *dmesgFile;
|
||||
static FILE *serialFile;
|
||||
|
||||
struct Thread {
|
||||
struct Thread *next;
|
||||
@ -72,7 +64,15 @@ Event *mkEvent(int source, int value) {
|
||||
}
|
||||
|
||||
void sendSerial(const char *data, int len) {
|
||||
fwrite(data, 1, len, stderr);
|
||||
if (!serialFile) {
|
||||
serialFile = fopen("/tmp/serial.txt", "w");
|
||||
if (!serialFile)
|
||||
serialFile = stderr;
|
||||
}
|
||||
|
||||
fwrite(data, 1, len, serialFile);
|
||||
fflush(serialFile);
|
||||
fdatasync(fileno(serialFile));
|
||||
}
|
||||
|
||||
extern "C" void target_panic(int error_code) {
|
||||
@ -266,10 +266,32 @@ extern "C" void InitEV3();
|
||||
|
||||
void initRuntime() {
|
||||
startTime = currTime();
|
||||
DMESG("runtime starting...");
|
||||
pthread_t disp;
|
||||
pthread_create(&disp, NULL, evtDispatcher, NULL);
|
||||
pthread_detach(disp);
|
||||
InitEV3();
|
||||
startUser();
|
||||
DMESG("runtime started");
|
||||
}
|
||||
|
||||
void dmesg(const char *format, ...) {
|
||||
char buf[500];
|
||||
|
||||
if (!dmesgFile) {
|
||||
dmesgFile = fopen("/tmp/dmesg.txt", "w");
|
||||
if (!dmesgFile)
|
||||
dmesgFile = stderr;
|
||||
}
|
||||
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
vsnprintf(buf, sizeof(buf), format, arg);
|
||||
va_end(arg);
|
||||
|
||||
fprintf(dmesgFile, "[%8d] %s\n", current_time_ms(), buf);
|
||||
fflush(dmesgFile);
|
||||
fdatasync(fileno(dmesgFile));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
#define __PXT_H
|
||||
|
||||
#include "pxtbase.h"
|
||||
#undef DMESG
|
||||
|
||||
#define ID_BUTTON_BASE 100
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
#ifndef __PXTCORE_H
|
||||
#define __PXTCORE_H
|
||||
|
||||
namespace pxt {
|
||||
void dmesg(const char *fmt, ...);
|
||||
#define DMESG dmesg
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -25,16 +25,19 @@ enum class ScreenFont {
|
||||
namespace screen {
|
||||
//%
|
||||
void _drawLine(uint32_t p0, uint32_t p1, Draw mode) {
|
||||
DMESG("line %x %x %x", p0, p1, mode);
|
||||
LineOutEx(XX(p0), YY(p0), XX(p1), YY(p1), (uint32_t)mode);
|
||||
}
|
||||
|
||||
//%
|
||||
void _drawRect(uint32_t p0, uint32_t p1, Draw mode) {
|
||||
DMESG("rect %x %x %x", p0, p1, mode);
|
||||
RectOutEx(XX(p0), YY(p0), XX(p1), YY(p1), (uint32_t)mode);
|
||||
}
|
||||
|
||||
//%
|
||||
void _drawEllipse(uint32_t p0, uint32_t p1, Draw mode) {
|
||||
DMESG("ellip %x %x %x", p0, p1, mode);
|
||||
EllipseOutEx(XX(p0), YY(p0), XX(p1), YY(p1), (uint32_t)mode);
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ namespace screen {
|
||||
function _drawEllipse(p0: uint32, p1: uint32, mode: Draw): void { }
|
||||
|
||||
function pack(x: number, y: number) {
|
||||
return Math.clamp(0, x, 512) | (Math.clamp(0, y, 512) << 16)
|
||||
return Math.clamp(0, 512, x) | (Math.clamp(0, 512, y) << 16)
|
||||
}
|
||||
|
||||
export function drawLine(x0: number, y0: number, x1: number, y1: number, mode?: Draw) {
|
||||
|
@ -1,6 +1,9 @@
|
||||
screen.clear()
|
||||
screen.drawRect(10, 10, 20, 10)
|
||||
screen.drawText(10, 30, "Hello PXT!")
|
||||
screen.setFont(ScreenFont.Large)
|
||||
//screen.drawText(10, 30, "Hello PXT!")
|
||||
for (let i = 0; i < 10; ++i)
|
||||
screen.drawRect(10, 70, 20, 10, Draw.Fill)
|
||||
//screen.drawEllipse(40, 40, 20, 10)
|
||||
|
||||
output.setLights(LightsPattern.GreenFlash)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user