From 60cf6d6b5a535f7bf70e5f6e173bb36ad3bb8233 Mon Sep 17 00:00:00 2001 From: Terence Boldt Date: Sat, 5 Dec 2020 00:46:33 +0000 Subject: [PATCH] Change server to test writing 4 KiB to II --- RaspberryPi/server.js | 22 ------------- RaspberryPi/test.js | 74 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 22 deletions(-) delete mode 100644 RaspberryPi/server.js create mode 100644 RaspberryPi/test.js diff --git a/RaspberryPi/server.js b/RaspberryPi/server.js deleted file mode 100644 index b1a8b77..0000000 --- a/RaspberryPi/server.js +++ /dev/null @@ -1,22 +0,0 @@ -var fs = require('fs'); -var gpio = require('onoff').Gpio; - -var output = new gpio(4, 'high', {activeLow: true}); -var input = new gpio(6, 'in', 'both'); - -function onCleanUp() { - output.unwatchAll(); - output.unexport(); - input.unexport(); -} - -function onStatusChanged(err, value) { - if (err) { - } - else { - } -} - -input.watch(onStatusChanged); - -process.on('SIGINT', onCleanUp); diff --git a/RaspberryPi/test.js b/RaspberryPi/test.js new file mode 100644 index 0000000..3deb7f9 --- /dev/null +++ b/RaspberryPi/test.js @@ -0,0 +1,74 @@ +var fs = require('fs'); +var gpio = require('onoff').Gpio; + +var out_write = new gpio(5, 'high', {activeLow: true}); +var out_read = new gpio(11, 'high', {activeLow: true}); +var out_command1 = new gpio(9, 'low', {activeLow: false}); +var out_command2 = new gpio(10, 'low', {activeLow: false}); +var out_bit3 = new gpio(22, 'low', {activeLow: false}); +var out_bit2 = new gpio(27, 'low', {activeLow: false}); +var out_bit1 = new gpio(17, 'low', {activeLow: false}); +var out_bit0 = new gpio(4, 'low', {activeLow: false}); +var in_write = new gpio(12, 'in', 'both'); +var in_read = new gpio(16, 'in', 'both'); +var in_command1 = new gpio(20, 'in'); +var in_command2 = new gpio(21, 'in'); +var in_bit3 = new gpio(26, 'in'); +var in_bit2 = new gpio(19, 'in'); +var in_bit1 = new gpio(13, 'in'); +var in_bit0 = new gpio(6, 'in'); + +function onCleanUp() { + in_write.unwatchAll(); + in_write.unexport(); +} + +function onWriteChanged(err, value) { + if (err) { + } + else { + //console.log(`value: ${value}`); + } +} + +number = 0; +startTime = Date.now(); + +function onReadChanged(err, value) { + if (err) { + } + else { + if (value == 1) { + //console.log("Nibble has been read"); + out_write.writeSync(0); + } + else { + writeNibble(number++); + if(number >= 4096) { + seconds = Date.now() - startTime; + console.log(`Sent 2 KiB in ${seconds} milliseconds.`); + process.exit() + } + } + } +} + +in_write.watch(onWriteChanged); +in_read.watch(onReadChanged); + +function writeNibble(nibble) { + out_bit3.writeSync((nibble&8)>>3); + out_bit2.writeSync((nibble&4)>>2); + out_bit1.writeSync((nibble&2)>>1); + out_bit0.writeSync(nibble&1); + out_command1.writeSync(0); + out_command2.writeSync(0); + out_read.writeSync(0); + out_write.writeSync(1); +} + +writeNibble(0); + +process.on('SIGINT', onCleanUp); + +