From c96552da207ede53a09eff641c98147a7f801037 Mon Sep 17 00:00:00 2001 From: duart38 Date: Sun, 20 Mar 2022 14:51:43 +0100 Subject: [PATCH] add readNBits method --- .gitignore | 1 + mod.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 337b8ef..0b1882b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ x.ts +x.sh sandbox.ts dump.ts test diff --git a/mod.ts b/mod.ts index 7f16cc9..834d4a9 100644 --- a/mod.ts +++ b/mod.ts @@ -240,5 +240,15 @@ export class Pin { ); } - // TODO: read 'n' bits and pipe to file for + /** + * queues up an instruction to request a number of bits while sleeping in between each fetch. + * @param n number of bits to read + * @param toFile file to pipe the bits to + * @param sleep how much to sleep in between each bit fetch. + */ + readNBits(n: number, toFile: string, sleep = 0){ + instructionsQueue.getInstance().add( + `for ((i = 0 ; i < ${n} ; i++)); do head -n 1 /sys/class/gpio/gpio${this.number}/value >> ${toFile}; sleep ${sleep}; done` + ); + } }