2017-07-05 14:06:58 +02:00
|
|
|
#include "pxt.h"
|
|
|
|
#include "ev3.h"
|
2017-07-07 11:38:20 +02:00
|
|
|
#include <pthread.h>
|
2017-07-05 14:06:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Drawing modes
|
|
|
|
*/
|
|
|
|
enum class Draw {
|
2017-07-05 14:56:13 +02:00
|
|
|
Normal = 0, // set pixels to black, no fill
|
2017-07-05 14:06:58 +02:00
|
|
|
Clear = DRAW_OPT_CLEAR_PIXELS,
|
|
|
|
Xor = DRAW_OPT_LOGICAL_XOR,
|
|
|
|
Fill = DRAW_OPT_FILL_SHAPE,
|
|
|
|
};
|
|
|
|
|
2017-07-05 14:56:13 +02:00
|
|
|
enum class ScreenFont {
|
|
|
|
Normal = FONTTYPE_NORMAL,
|
|
|
|
Small = FONTTYPE_SMALL,
|
|
|
|
Large = FONTTYPE_LARGE,
|
|
|
|
Tiny = FONTTYPE_TINY,
|
|
|
|
};
|
|
|
|
|
2017-07-05 14:06:58 +02:00
|
|
|
#define XX(v) ((uint32_t)(v)&0xffff)
|
|
|
|
#define YY(v) ((uint32_t)(v) >> 16)
|
|
|
|
|
|
|
|
// We only support up to 4 arguments for C++ functions - need to pack them on the TS side
|
|
|
|
namespace screen {
|
2017-07-05 20:17:26 +02:00
|
|
|
|
|
|
|
|
2017-07-05 14:06:58 +02:00
|
|
|
//%
|
|
|
|
void _drawLine(uint32_t p0, uint32_t p1, Draw mode) {
|
|
|
|
LineOutEx(XX(p0), YY(p0), XX(p1), YY(p1), (uint32_t)mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
//%
|
|
|
|
void _drawRect(uint32_t p0, uint32_t p1, Draw mode) {
|
|
|
|
RectOutEx(XX(p0), YY(p0), XX(p1), YY(p1), (uint32_t)mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
//%
|
|
|
|
void _drawEllipse(uint32_t p0, uint32_t p1, Draw mode) {
|
|
|
|
EllipseOutEx(XX(p0), YY(p0), XX(p1), YY(p1), (uint32_t)mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Draw text. */
|
2017-07-05 14:56:13 +02:00
|
|
|
//% mode.defl=0
|
2017-07-05 14:06:58 +02:00
|
|
|
void drawText(int x, int y, String text, Draw mode) {
|
|
|
|
LcdText((int)mode & (int)Draw::Clear ? 0 : 1, x, y, text->data);
|
|
|
|
}
|
2017-07-05 14:56:13 +02:00
|
|
|
|
|
|
|
/** Clear screen and reset font to normal. */
|
|
|
|
//%
|
|
|
|
void clear() {
|
|
|
|
LcdClearDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Scroll screen vertically. */
|
|
|
|
//%
|
|
|
|
void scroll(int v) {
|
|
|
|
LcdScroll(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set font for drawText() */
|
|
|
|
//%
|
|
|
|
void setFont(ScreenFont font) {
|
|
|
|
LcdSelectFont((uint8_t)font);
|
|
|
|
}
|
2017-07-05 14:06:58 +02:00
|
|
|
}
|
2017-07-07 11:38:20 +02:00
|
|
|
|
|
|
|
namespace pxt {
|
|
|
|
|
|
|
|
void *screenRefresh(void *dummy) {
|
|
|
|
while (true) {
|
|
|
|
sleep_core_us(30000);
|
|
|
|
LcdUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void screen_init() {
|
|
|
|
LcdInitNoAutoRefresh();
|
|
|
|
LcdClean();
|
|
|
|
|
|
|
|
pthread_t pid;
|
|
|
|
pthread_create(&pid, NULL, screenRefresh, NULL);
|
|
|
|
pthread_detach(pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|