Skip to content

Commit

Permalink
Merge branch 'master' into aia-pr
Browse files Browse the repository at this point in the history
  • Loading branch information
ARMinARM committed Sep 28, 2014
2 parents a41e806 + b9266cd commit c1d3acd
Show file tree
Hide file tree
Showing 35 changed files with 976 additions and 145 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
1v71 : Allowed WIZnet + CC3000 to be instantiated on any pins
Fix break inside loop inside case inside function (fix 428)
Added fs.stat and File.seek (fix #429, fix #430)
Allow use of DLE (char 16) on an empty line to turn echo off for *just that line*
Add XON/XOFF flow control on Serial + USB. This is enabled by default for Serial (fix #20)

1v70 : Make pipe remove its drain/close listeners. Stops out of memory for repeated piping.
Fix parseInt for values too large to go in an int (#406)
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ ifdef WIZNET
USE_WIZNET=1
else
USE_CC3000=1
#USE_ESP8266=1
endif
endif
endif
Expand Down Expand Up @@ -611,6 +612,14 @@ libs/network/http/httpserver.c
libs/network/wiznet/Ethernet/socket.c \
libs/network/wiznet/W5500/w5500.c
endif

ifdef USE_ESP8266
DEFINES += -DUSE_ESP8266
WRAPPERSOURCES += libs/network/esp8266/jswrap_esp8266.c
INCLUDE += -I$(ROOT)/libs/network/esp8266
SOURCES += \
libs/network/esp8266/network_esp8266.c
endif
endif


Expand Down Expand Up @@ -922,7 +931,7 @@ OPTIMIZEFLAGS += -flto -fno-fat-lto-objects -Wl,--allow-multiple-definition
endif

# Limit code size growth via inlining to 8% Normally 30% it seems... This reduces code size while still being able to use -O3
OPTIMIZEFLAGS += --param inline-unit-growth=8
OPTIMIZEFLAGS += --param inline-unit-growth=6

export CCPREFIX?=arm-none-eabi-
endif # ARM
Expand Down
29 changes: 14 additions & 15 deletions boards/ESPRUINIBOARD_R1_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@
};
# left-right, or top-bottom order
board = {
'left' : [ 'GND', '3V3', 'BOOT0', 'NRST' ],
# 'left2' : [ 'GND', 'A12', 'A11', 'VCC' ],
'top' : [ '5V', 'A13', 'A14', 'A15', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9'],
'bottom' : [ 'GND','BAT_IN','B15', 'B14', 'B13', 'B10', 'B2', 'B1', 'A7', 'A6', 'A5' ],
'left' : [ 'NRST', 'BOOT0', '3V3', 'GND' ],
'bottom' : [ '5V', 'A13', 'A14', 'A15', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9'],
'top' : [ 'GND','BAT_IN','B15', 'B14', 'B13', 'B10', 'B2', 'B1', 'A7', 'A6', 'A5' ],


'right2' : ['A9','A0','A1','A3'],
'right' : ['A10','A8','A2','A4'],
'right2' : ['A3','A1','A0','A9'],
'right' : ['A4','A2','A8','A10'],
};
devices = {
'OSC' : { 'pin_in' : 'H0', # checked
Expand Down Expand Up @@ -86,35 +85,35 @@
height: 585px;
}
#left {
top: 105px;
top: 95px;
right: 560px;
}
#left2 {
top: 105px;
top: 95px;
left: -100px;
}
#top {
bottom: 320px;
left: 240px;
left: 262px;
}
#bottom {
top: 320px;
left: 240px;
left: 262px;
}
#right {
top: 105px;
left: 820px;
top: 95px;
left: 800px;
}
#right2 {
top: 105px;
top: 95px;
right: 105px;
}
.leftpin { height: 48px; }
.left2pin { height: 48px; }
.toppin { width: 48px; }
.bottompin { width: 48px; }
.toppin { width: 44px; }
.bottompin { width: 44px; }
.rightpin { height: 48px; }
.right2pin { height: 48px; }
Expand Down
Binary file modified boards/img/ESPRUINIBOARD_R1_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 19 additions & 12 deletions libs/filesystem/jswrap_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,27 +402,34 @@ JsVar *jswrap_file_read(JsVar* parent, int length) {
if (buffer)
jsvStringIteratorFree(&it);

// automatically close this file if we're at the end of it
if (bytesRead!=(size_t)length)
jswrap_file_close(parent);

return buffer;
}

/*JSON{
"type" : "method",
"class" : "File",
"name" : "skip",
"generate" : "jswrap_file_skip",
"generate_full" : "jswrap_file_skip_or_seek(parent,nBytes,true)",
"params" : [
["nBytes","int32","is a positive integer specifying the number of bytes to skip forwards."]
]
}
Skip the specified number of bytes forward in the file
*/
/*JSON{
"type" : "method",
"class" : "File",
"name" : "seek",
"generate_full" : "jswrap_file_skip_or_seek(parent,nBytes,false)",
"params" : [
["nBytes","int32","is an integer specifying the number of bytes to skip forwards."]
]
}
Skip the specified number of bytes forwards
Seek to a certain position in the file
*/
void jswrap_file_skip(JsVar* parent, int length) {
if (length<=0) {
jsWarn("length for skip must be greater than 0");
void jswrap_file_skip_or_seek(JsVar* parent, int nBytes, bool is_skip) {
if (nBytes<0) {
jsWarn(is_skip ? "Bytes to skip must be >=0" : "Position to seek to must be >=0");
return;
}
FRESULT res = 0;
Expand All @@ -431,15 +438,15 @@ void jswrap_file_skip(JsVar* parent, int length) {
if (fileGetFromVar(&file, parent)) {
if(file.data.mode == FM_READ || file.data.mode == FM_WRITE || file.data.mode == FM_READ_WRITE) {
#ifndef LINUX
res = (FRESULT)f_lseek(&file.data.handle, (DWORD)f_tell(&file.data.handle) + (DWORD)length);
res = (FRESULT)f_lseek(&file.data.handle, (DWORD)(is_skip ? f_tell(&file.data.handle) : 0) + (DWORD)nBytes);
#else
fseek(file.data.handle, length, SEEK_CUR);
fseek(file.data.handle, nBytes, is_skip ? SEEK_CUR : SEEK_SET);
#endif
fileSetVar(&file);
}
}
}
if (res) jsfsReportError("Unable to skip", res);
if (res) jsfsReportError(is_skip?"Unable to skip":"Unable to seek", res);
}

/*JSON{
Expand Down
2 changes: 1 addition & 1 deletion libs/filesystem/jswrap_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ void jswrap_E_unmountSD();

size_t jswrap_file_write(JsVar* parent, JsVar* buffer);
JsVar *jswrap_file_read(JsVar* parent, int length);
void jswrap_file_skip(JsVar* parent, int length);
void jswrap_file_skip_or_seek(JsVar* parent, int length, bool is_skip);
void jswrap_file_close(JsVar* parent);
67 changes: 66 additions & 1 deletion libs/filesystem/jswrap_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
#include "jsvar.h"
#include "jsparse.h"
#include "jsinteractive.h"
#include "jswrap_date.h"

#ifndef LINUX
#include "ff.h" // filesystem stuff
#else
#include <stdio.h>
#include <sys/stat.h>
#include <dirent.h> // for readdir
#endif

Expand Down Expand Up @@ -266,7 +268,7 @@ Delete the given file
NOTE: Espruino does not yet support Async file IO, so this function behaves like the 'Sync' version.
*/
/*JSON{
/*JSON{
"type" : "staticmethod",
"class" : "fs",
"name" : "unlinkSync",
Expand Down Expand Up @@ -300,3 +302,66 @@ bool jswrap_fs_unlink(JsVar *path) {
return true;
}

/*JSON{
"type" : "staticmethod",
"class" : "fs",
"name" : "statSync",
"ifndef" : "SAVE_ON_FLASH",
"generate" : "jswrap_fs_stat",
"params" : [
["path","JsVar","The path of the file to get information on"]
],
"return" : ["JsVar","An object describing the file, or undefined on failure"]
}
Return information on the given file. This returns an object with the following
fields:
size: size in bytes
dir: a boolean specifying if the file is a directory or not
mtime: A Date structure specifying the time the file was last modified
*/
JsVar *jswrap_fs_stat(JsVar *path) {
char pathStr[JS_DIR_BUF_SIZE] = "";
if (!jsvIsUndefined(path))
jsvGetString(path, pathStr, JS_DIR_BUF_SIZE);

#ifndef LINUX
FRESULT res = 0;
if (jsfsInit()) {
FILINFO info;
res = f_stat(pathStr, &info);
if (res==0 /*ok*/) {
JsVar *obj = jsvNewWithFlags(JSV_OBJECT);
if (!obj) return 0;
jsvUnLock(jsvObjectSetChild(obj, "size", jsvNewFromInteger((JsVarInt)info.fsize)));
jsvUnLock(jsvObjectSetChild(obj, "dir", jsvNewFromBool(info.fattrib & AM_DIR)));

CalendarDate date;
date.year = 1980+(int)((info.fdate>>9)&127);
date.month = (int)((info.fdate>>5)&15);
date.day = (int)((info.fdate)&31);
TimeInDay td;
td.daysSinceEpoch = fromCalenderDate(&date);
td.hour = (int)((info.ftime>>11)&31);
td.min = (int)((info.ftime>>5)&63);
td.sec = (int)((info.ftime)&63);
td.ms = 0;
td.zone = 0;
jsvUnLock(jsvObjectSetChild(obj, "mtime", jswrap_date_from_milliseconds(fromTimeInDay(&td))));
return obj;
}
}
#else
struct stat info;
if (stat(pathStr, &info)==0 /*ok*/) {
JsVar *obj = jsvNewWithFlags(JSV_OBJECT);
if (!obj) return 0;
jsvUnLock(jsvObjectSetChild(obj, "size", jsvNewFromInteger((JsVarInt)info.st_size)));
jsvUnLock(jsvObjectSetChild(obj, "dir", jsvNewFromBool(S_ISDIR(info.st_mode))));
jsvUnLock(jsvObjectSetChild(obj, "mtime", jswrap_date_from_milliseconds((JsVarFloat)info.st_mtime*1000.0)));
return obj;
}
#endif

return 0;
}
1 change: 1 addition & 0 deletions libs/filesystem/jswrap_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ JsVar *jswrap_fs_readdir(JsVar *path);
bool jswrap_fs_writeOrAppendFile(JsVar *path, JsVar *data, bool append);
JsVar *jswrap_fs_readFile(JsVar *path);
bool jswrap_fs_unlink(JsVar *path);
JsVar *jswrap_fs_stat(JsVar *path);
Loading

0 comments on commit c1d3acd

Please sign in to comment.