-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stdlib) sd libary, separate the SD lib wrapper
- Loading branch information
1 parent
6a9573a
commit 34c7929
Showing
7 changed files
with
372 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"authors": [ | ||
"XOD" | ||
], | ||
"description": "Nodes to work with SDcards", | ||
"license": "AGPL-3.0", | ||
"name": "sd", | ||
"version": "0.33.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
{{#global}} | ||
#include <SPI.h> | ||
#include <SD.h> | ||
{{/global}} | ||
|
||
struct State { | ||
uint8_t mem[sizeof(SDClass)]; | ||
SDClass* sd; | ||
}; | ||
|
||
using Type = SDClass*; | ||
|
||
{{ GENERATED_CODE }} | ||
|
||
void evaluate(Context ctx) { | ||
|
||
auto state = getState(ctx); | ||
|
||
if (isSettingUp()) { | ||
state->sd = new (state->mem) SDClass(); | ||
} | ||
|
||
auto csPin = getValue<input_CS>(ctx); | ||
|
||
if (!state->sd->begin(csPin)) { | ||
raiseError(ctx); | ||
return; | ||
} | ||
emitValue<output_DEV>(ctx, state->sd); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"description": "Constructs an SDcard device.", | ||
"nodes": [ | ||
{ | ||
"description": "CS (chip select) pin the SD card reader is connected to. Also known as SS (slave select).", | ||
"id": "ByHVa_XtL", | ||
"label": "CS", | ||
"position": { | ||
"units": "slots", | ||
"x": -12, | ||
"y": -2 | ||
}, | ||
"type": "xod/patch-nodes/input-port" | ||
}, | ||
{ | ||
"id": "HklSN6uQYU", | ||
"position": { | ||
"units": "slots", | ||
"x": -12, | ||
"y": -1 | ||
}, | ||
"type": "xod/patch-nodes/not-implemented-in-xod" | ||
}, | ||
{ | ||
"description": "SDcard device.", | ||
"id": "Sy6VT_7tL", | ||
"label": "DEV", | ||
"position": { | ||
"units": "slots", | ||
"x": -12, | ||
"y": 0 | ||
}, | ||
"type": "xod/patch-nodes/output-self" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
{ | ||
"description": "Quickstart node. Appends lines of text to a file on SD card. Possible errors: — Can't open a file — Initialization failed or no SD card — Can't write data to SD card.", | ||
"links": [ | ||
{ | ||
"id": "ByDS8YQt8", | ||
"input": { | ||
"nodeId": "rkrMUKmtU", | ||
"pinKey": "S1lM0JKmFL" | ||
}, | ||
"output": { | ||
"nodeId": "HJSB8FQY8", | ||
"pinKey": "rksccsp-W" | ||
} | ||
}, | ||
{ | ||
"id": "H1OSIKmFU", | ||
"input": { | ||
"nodeId": "HJSB8FQY8", | ||
"pinKey": "Hkqu9oaWb" | ||
}, | ||
"output": { | ||
"nodeId": "r1xHXUtmF8", | ||
"pinKey": "__out__" | ||
} | ||
}, | ||
{ | ||
"id": "S18z8FmYL", | ||
"input": { | ||
"nodeId": "rkrMUKmtU", | ||
"pinKey": "SkMTJY7YU" | ||
}, | ||
"output": { | ||
"nodeId": "BJIk8KmFL", | ||
"pinKey": "Sy6VT_7tL" | ||
} | ||
}, | ||
{ | ||
"id": "S1FQLY7F8", | ||
"input": { | ||
"nodeId": "rkrMUKmtU", | ||
"pinKey": "B1bfAJY7FL" | ||
}, | ||
"output": { | ||
"nodeId": "B1bBXIYQYI", | ||
"pinKey": "__out__" | ||
} | ||
}, | ||
{ | ||
"id": "SkgcmUK7KL", | ||
"input": { | ||
"nodeId": "rkrMUKmtU", | ||
"pinKey": "S1MCJFXt8" | ||
}, | ||
"output": { | ||
"nodeId": "rkrm8KmKL", | ||
"pinKey": "__out__" | ||
} | ||
}, | ||
{ | ||
"id": "SydNLY7YI", | ||
"input": { | ||
"nodeId": "BJIk8KmFL", | ||
"pinKey": "ByHVa_XtL" | ||
}, | ||
"output": { | ||
"nodeId": "By4E8K7K8", | ||
"pinKey": "__out__" | ||
} | ||
}, | ||
{ | ||
"id": "ryPo8t7YI", | ||
"input": { | ||
"nodeId": "H14i8t7YL", | ||
"pinKey": "__in__" | ||
}, | ||
"output": { | ||
"nodeId": "rkrMUKmtU", | ||
"pinKey": "ryl1xK7KI" | ||
} | ||
} | ||
], | ||
"nodes": [ | ||
{ | ||
"description": "File name to append to.", | ||
"id": "B1bBXIYQYI", | ||
"label": "FILE", | ||
"position": { | ||
"units": "slots", | ||
"x": 3, | ||
"y": 0 | ||
}, | ||
"type": "xod/patch-nodes/input-string" | ||
}, | ||
{ | ||
"id": "BJIk8KmFL", | ||
"position": { | ||
"units": "slots", | ||
"x": 0, | ||
"y": 1 | ||
}, | ||
"type": "@/sd-device" | ||
}, | ||
{ | ||
"description": "CS (chip select) pin the SD card reader is connected to. Also known as SS (slave select).", | ||
"id": "By4E8K7K8", | ||
"label": "CS", | ||
"position": { | ||
"units": "slots", | ||
"x": 0, | ||
"y": 0 | ||
}, | ||
"type": "xod/patch-nodes/input-port" | ||
}, | ||
{ | ||
"description": "Fires when write is done.", | ||
"id": "H14i8t7YL", | ||
"label": "DONE", | ||
"position": { | ||
"units": "slots", | ||
"x": 3, | ||
"y": 2 | ||
}, | ||
"type": "xod/patch-nodes/output-pulse" | ||
}, | ||
{ | ||
"boundLiterals": { | ||
"BkeKcj6ZZ": "\"\\n\"" | ||
}, | ||
"id": "HJSB8FQY8", | ||
"position": { | ||
"units": "slots", | ||
"x": 4, | ||
"y": -1 | ||
}, | ||
"type": "xod/core/concat" | ||
}, | ||
{ | ||
"description": "Line to append.", | ||
"id": "r1xHXUtmF8", | ||
"label": "LINE", | ||
"position": { | ||
"units": "slots", | ||
"x": 4, | ||
"y": -2 | ||
}, | ||
"type": "xod/patch-nodes/input-string" | ||
}, | ||
{ | ||
"id": "rkrMUKmtU", | ||
"position": { | ||
"units": "slots", | ||
"x": 2, | ||
"y": 1 | ||
}, | ||
"type": "@/write-file" | ||
}, | ||
{ | ||
"description": "Perform file open, write, flush, close cycle.", | ||
"id": "rkrm8KmKL", | ||
"label": "W", | ||
"position": { | ||
"units": "slots", | ||
"x": 5, | ||
"y": 0 | ||
}, | ||
"type": "xod/patch-nodes/input-pulse" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
struct State {}; | ||
|
||
{{ GENERATED_CODE }} | ||
|
||
void evaluate(Context ctx) { | ||
|
||
auto sd = getValue<input_DEV>(ctx); | ||
emitValue<output_DEVU0027>(ctx, sd); | ||
|
||
if (!isInputDirty<input_DO>(ctx)) | ||
return; | ||
|
||
char filename[24] = { 0 }; | ||
dump(getValue<input_FILE>(ctx), filename); | ||
|
||
File file = sd->open(filename, O_WRITE | O_CREAT | O_APPEND); | ||
|
||
if (!file) { | ||
// Failed to open the file. Maybe, SD card gone, try to reinit next time | ||
raiseError(ctx); // Can't open file | ||
return; | ||
} | ||
|
||
XString line = getValue<input_DATA>(ctx); | ||
size_t lastWriteSize; | ||
for (auto it = line.iterate(); it; ++it) { | ||
lastWriteSize = file.print(*it); | ||
if (lastWriteSize == 0) { | ||
raiseError(ctx); // No bytes written | ||
return; | ||
} | ||
} | ||
|
||
file.flush(); | ||
file.close(); | ||
emitValue<output_DONE>(ctx, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"description": "Writes a text data to a file on SD card. Possible errors: — Can't open a file — Initialization failed or no SD card — Can't write data to SD card.", | ||
"nodes": [ | ||
{ | ||
"description": "File name to write to.", | ||
"id": "B1bfAJY7FL", | ||
"label": "FILE", | ||
"position": { | ||
"units": "slots", | ||
"x": 2, | ||
"y": 1 | ||
}, | ||
"type": "xod/patch-nodes/input-string" | ||
}, | ||
{ | ||
"id": "HJuTkYQYU", | ||
"position": { | ||
"units": "slots", | ||
"x": 1, | ||
"y": 2 | ||
}, | ||
"type": "xod/patch-nodes/not-implemented-in-xod" | ||
}, | ||
{ | ||
"description": "Perform file open, write, flush, close cycle.", | ||
"id": "S1MCJFXt8", | ||
"label": "DO", | ||
"position": { | ||
"units": "slots", | ||
"x": 4, | ||
"y": 1 | ||
}, | ||
"type": "xod/patch-nodes/input-pulse" | ||
}, | ||
{ | ||
"description": "Data to write.", | ||
"id": "S1lM0JKmFL", | ||
"label": "DATA", | ||
"position": { | ||
"units": "slots", | ||
"x": 3, | ||
"y": 1 | ||
}, | ||
"type": "xod/patch-nodes/input-string" | ||
}, | ||
{ | ||
"description": "SDcard device.", | ||
"id": "SkMTJY7YU", | ||
"label": "DEV", | ||
"position": { | ||
"units": "slots", | ||
"x": 1, | ||
"y": 1 | ||
}, | ||
"type": "@/input-sd-device" | ||
}, | ||
{ | ||
"description": "Fires when write is done.", | ||
"id": "ryl1xK7KI", | ||
"label": "DONE", | ||
"position": { | ||
"units": "slots", | ||
"x": 2, | ||
"y": 3 | ||
}, | ||
"type": "xod/patch-nodes/output-pulse" | ||
}, | ||
{ | ||
"description": "SDcard device.", | ||
"id": "ryqyZKXFI", | ||
"label": "DEV'", | ||
"position": { | ||
"units": "slots", | ||
"x": 1, | ||
"y": 3 | ||
}, | ||
"type": "@/output-sd-device" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters