Skip to content

Commit a75f2a7

Browse files
committed
add ESPR_FS_PREPEND_PATH, other compile fixes
1 parent a2f13da commit a75f2a7

File tree

6 files changed

+72
-12
lines changed

6 files changed

+72
-12
lines changed

README_BuildProcess.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ This is a partial list of definitions that can be added in a `BOARD.py` file's `
152152
* `ESPR_FS_MKFS` - Add support for require("fs").mkfs for formatting disks
153153
* `ESPR_FS_GETFREE` - Add support for require("fs").getFree in the filesystem library
154154
* `ESPR_TEST_ON_FIRST_RUN` - on Jolt.js/Puck.js, run the self-test the very first time the board boots up (this is not the default since 2v27)
155+
* `ESPR_FS_PREPEND_PATH=""` - add something to the path when accessing files using 'fs' - eg on a linux build you might add `'sdcard'` to look for files in that directory
155156

156157

157158
There are some specifically that are useful for cutting a few bytes out of the build:

boards/PIPBOY_LINUX.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
info = {
1818
'name' : "Pipboy Linux Debug Compilation",
1919
'default_console' : "EV_USBSERIAL",
20-
'variables' : 5000, # 0 = resizable variables, rather than fixed
20+
'variables' : 15000, # 0 = resizable variables, rather than fixed
2121
'binary_name' : 'espruino_pb',
2222
'build' : {
2323
'libraries' : [
@@ -29,12 +29,20 @@
2929
# 'CFLAGS+=-m32', 'LDFLAGS+=-m32', 'DEFINES+=-DUSE_CALLFUNCTION_HACK', # For testing 32 bit builds
3030
'DEFINES+=-DLINUX -DEMULATED',
3131
'DEFINES+=-DESPR_UNICODE_SUPPORT=1',
32+
'DEFINES+=-DESPR_FS_PREPEND_PATH=\'"sdcard/"\'',
3233
'DEFINES+=-DUSE_FONT_6X8 -DGRAPHICS_PALETTED_IMAGES -DGRAPHICS_ANTIALIAS -DESPR_PBF_FONTS -DESPR_GRAPHICS_INTERNAL -DESPR_GRAPHICS_SELF_INIT',
3334
'DEFINES+=-DSPIFLASH_BASE=0 -DSPIFLASH_LENGTH=FLASH_SAVED_CODE_LENGTH', # For Testing Flash Strings
3435
'LINUX=1',
3536
'INCLUDE += -I$(ROOT)/libs/pipboy',
3637
'WRAPPERSOURCES += libs/pipboy/avi.c libs/pipboy/stm32_i2s.c',
37-
'WRAPPERSOURCES += libs/pipboy/jswrap_pipboy.c'
38+
'WRAPPERSOURCES += libs/pipboy/jswrap_pipboy.c',
39+
'WRAPPERSOURCES += libs/pipboy/jswrap_font_monofonto_120.c',
40+
'WRAPPERSOURCES += libs/pipboy/jswrap_font_monofonto_96.c',
41+
'WRAPPERSOURCES += libs/pipboy/jswrap_font_monofonto_36.c',
42+
'WRAPPERSOURCES += libs/pipboy/jswrap_font_monofonto_28.c',
43+
'WRAPPERSOURCES += libs/pipboy/jswrap_font_monofonto_23.c',
44+
'WRAPPERSOURCES += libs/pipboy/jswrap_font_monofonto_18.c',
45+
'WRAPPERSOURCES += libs/pipboy/jswrap_font_monofonto_16.c'
3846
]
3947
}
4048
};

libs/filesystem/jswrap_file.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ bool jsfsGetPathString(char *pathStr, JsVar *path) {
4040
jsExceptionHere(JSET_ERROR, "File path too long");
4141
return false;
4242
}
43+
#ifdef ESPR_FS_PREPEND_PATH
44+
char buf[JS_DIR_BUF_SIZE];
45+
strcpy(buf, ESPR_FS_PREPEND_PATH);
46+
strcat(buf, pathStr);
47+
strcpy(pathStr, buf);
48+
#endif
4349
return true;
4450
}
4551

@@ -568,7 +574,7 @@ Skip the specified number of bytes forward in the file
568574
"name" : "seek",
569575
"generate_full" : "jswrap_file_skip_or_seek(parent,nBytes,false)",
570576
"params" : [
571-
["nBytes","int32","is an integer specifying the number of bytes to skip forwards."]
577+
["nBytes","int32","is an integer specifying the byte position in the file to move to."]
572578
]
573579
}
574580
Seek to a certain position in the file

libs/graphics/lcd_sdl.c

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ void lcdIdle_SDL() {
100100
static bool down;
101101
extern void nativeQuit();
102102
SDL_Event event;
103-
bool sendEvent = false;
103+
bool sendTouchEvent = false;
104+
char *sendKeyEvent = NULL;
104105

105106
if (needsFlip) {
106107
needsFlip = false;
@@ -113,19 +114,29 @@ void lcdIdle_SDL() {
113114
nativeQuit();
114115
break;
115116
case SDL_MOUSEMOTION:
116-
if (down) {
117-
sendEvent = true;
118-
}
117+
if (down) {
118+
sendTouchEvent = true;
119+
}
119120
break;
120121
case SDL_MOUSEBUTTONDOWN:
121122
case SDL_MOUSEBUTTONUP:
122123
down = event.type == SDL_MOUSEBUTTONDOWN;
123-
sendEvent = true;
124-
break;
124+
sendTouchEvent = true;
125+
break;
126+
case SDL_KEYDOWN:
127+
sendKeyEvent = JS_EVENT_PREFIX"keydown";
128+
switch (event.key.keysym.sym) {
129+
case SDLK_ESCAPE: nativeQuit(); break;
130+
default:break;
131+
}
132+
break;
133+
case SDL_KEYUP:
134+
sendKeyEvent = JS_EVENT_PREFIX"keyup";
135+
break;
125136
}
126137
}
127138

128-
if (sendEvent) {
139+
if (sendTouchEvent) {
129140
JsVar *E = jsvObjectGetChildIfExists(execInfo.root, "E");
130141
if (E) {
131142
JsVar *o = jsvNewObject();
@@ -136,6 +147,33 @@ void lcdIdle_SDL() {
136147
jsvUnLock2(E,o);
137148
}
138149
}
150+
if (sendKeyEvent) {
151+
JsVar *E = jsvObjectGetChildIfExists(execInfo.root, "E");
152+
if (E) {
153+
JsVar *o = jsvNewObject();
154+
jsvObjectSetChildAndUnLock(o,"keyCode", jsvNewFromInteger(event.key.keysym.scancode));
155+
const char *name = NULL;
156+
switch (event.key.keysym.sym) {
157+
case SDLK_UP: name = "ArrowUp"; break;
158+
case SDLK_DOWN: name = "ArrowDown"; break;
159+
case SDLK_LEFT: name = "ArrowLeft"; break;
160+
case SDLK_RIGHT: name = "ArrowRight"; break;
161+
case SDLK_RETURN: name = "Enter"; break;
162+
case SDLK_BACKSPACE: name = "Backspace"; break;
163+
case SDLK_TAB: name = "Tab"; break;
164+
case SDLK_DELETE: name = "Delete"; break;
165+
case SDLK_HOME: name = "Home"; break;
166+
case SDLK_END: name = "End"; break;
167+
case SDLK_PAGEUP: name = "PageUp"; break;
168+
case SDLK_PAGEDOWN: name = "PageDown"; break;
169+
case SDLK_INSERT: name = "Insert"; break;
170+
default:break;
171+
}
172+
if (name) jsvObjectSetChildAndUnLock(o,"key", jsvNewFromString(name));
173+
jsiQueueObjectCallbacks(E, sendKeyEvent, &o, 1);
174+
jsvUnLock2(E,o);
175+
}
176+
}
139177
}
140178

141179
void lcdSetCallbacks_SDL(JsGraphics *gfx) {

libs/pipboy/avi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ typedef struct {
3131
int audioBufferSize;
3232
} AviInfo;
3333

34-
const uint16_t WAVFMT_RAW = 1;
35-
const uint16_t WAVFMT_IMA_ADPCM = 0x11; // https://wiki.multimedia.cx/index.php/Microsoft_IMA_ADPCM
34+
#define WAVFMT_RAW 1
35+
#define WAVFMT_IMA_ADPCM 0x11 // https://wiki.multimedia.cx/index.php/Microsoft_IMA_ADPCM
3636

3737
#define AVI_STREAM_AUDIO 0x6277
3838
#define AVI_STREAM_VIDEO 0x6364

targets/linux/main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,13 @@ int handleErrors() {
392392
if (hasException) {
393393
jsiConsolePrintf("Uncaught %v\n", exception);
394394
e = 1;
395+
if (jsvIsObject(exception)) {
396+
JsVar *stackTrace = jsvObjectGetChildIfExists(exception, "stack");
397+
if (stackTrace) {
398+
jsiConsolePrintStringVar(stackTrace);
399+
jsvUnLock(stackTrace);
400+
}
401+
}
395402
}
396403
jsvUnLock(exception);
397404

0 commit comments

Comments
 (0)