Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow example to 126 baud #23

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ board.on("ready", function() {
}.bind(this), 500);
});
```

You can configure WebJack with a profile object (see [docs](https://github.com/publiclab/webjack#individual-profile-options)) by passing it as a constructor option:

```js
var board = new Firmata(new WebJackPort({
profile: {
baud : 1225,
freqLow : 4900,
freqHigh : 7350,
echoCancellation : false,
softmodem : true
}
}));
```

Also take a look at the demo site in the example folder.

### Sketches
Expand Down
7 changes: 5 additions & 2 deletions dist/webjackport.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var WebJack = require("webjack");
var Emitter = require("events").EventEmitter;
var priv = new Map();

function WebJackPort() {
function WebJackPort(options) {
Emitter.call(this);


Expand All @@ -37,7 +37,10 @@ function WebJackPort() {
}
};

var connection = new WebJack.Connection({raw : true});
options = options || {};
options.profile = options.profile || {};
options.profile.raw = true;
var connection = new WebJack.Connection(options.profile);
state.flushTo(connection);

connection.listen(function(data) {
Expand Down
9 changes: 8 additions & 1 deletion example/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ var CAPABILITY_QUERY = 0x6B;
var ANALOG_MAPPING_QUERY = 0x69;
var SAMPLING_INTERVAL = 0x7A;

function setOptions(options) {
board = new Board(new WebJackPort(options), opts);
}

$(document).ready(function($) {
var log = $('.webjack-log');
log.appends = function(text){
Expand Down Expand Up @@ -109,5 +113,8 @@ $(document).ready(function($) {
});
});

module.exports = { board: board };
module.exports = {
board: board,
setOptions: setOptions
};

18 changes: 9 additions & 9 deletions example/bundle.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions example/jquery.min.js

Large diffs are not rendered by default.

81 changes: 81 additions & 0 deletions example/slow/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<title>WebJack</title>

<script src="../adapter.js"></script>
<script src="../jquery.min.js"></script>
<script src="../bundle.js" type="text/javascript"></script>
<script src="slow.js" type="text/javascript"></script>

<link href="../examples.css" rel="stylesheet">

</head>
<body>
<h1>WebJack-Firmata Slow Baud Rate Demo</h1>
<a href="https://github.com/publiclab/webjack-firmata" target="_blank">WebJack-Firmata</a> is a transport layer for <a href="https://github.com/firmata/firmata.js" target="_blank">Firmata.js</a> and is based on <a href="https://github.com/publiclab/webjack" target="_blank">WebJack</a>, a JavaScript library that uses an audio modem to communicate with an Arduino µC via headphone jack. Firmata is a RPC like protocol, that defines a serial interface to read from or write to a microcontroller's pins. This demo allows web browsers to control an Arduino via headphone jack.<br><br>
To run the demo, upload this modified version of the <a href="https://github.com/publiclab/webjack-firmata/blob/master/sketches/StandardFirmataWebJack/StandardFirmataWebJack.ino" target="_blank">StandardFirmata</a> sketch. You will also need additional <a href="https://github.com/arms22/SoftModem#hardware" target="_blank">hardware</a>.

<h2>Slow Baud Rate Demo</h2>
<p>In this demo, we communicate at 126 baud -- slow enough for the human ear to easily hear each bit.</p>

<h2>Commands</h2>
<button id="capab">Query Capabilities</button>
<button id="firmware">Query Firmware</button>

<div class="connected">
<button id="digital">digitalWrite</button>
<select id="pin">
<option>0</option>
<option>1</option>
<option>2</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>12</option>
<option selected>13</option>
</select>
<select id="state">
<option value="0">LOW</option>
<option value="1" selected>HIGH</option>
</select>
</div>

<div class="connected">
<button id="analog">analogRead</button>
<select id="apin">
<option value="0">A0</option>
<option value="1">A1</option>
<option value="2">A2</option>
<option value="3">A3</option>
<option value="4">A4</option>
<option value="5">A5</option>
</select>
</div>

<form class="serial" action="javascript:void(0);">
<input type="text" class="serialWrite">
<button class="serialWriteSend connected">SerialWrite</button>
</form>

<button id="reset">Reset</button>

<h2>Log</h2>
<div class="webjack-log"></div>

<p class="hint"><i>WebJack is in an early development stage. If it does not work, try to:</i>
<ul>
<li>use an other browser <i>(Safari will not work, sorry)</i></li>
<li>pump up the volume</li>
<li>reload the site several times</li>
<li>reset the Arduino<br>
</ul>
</p>
</body>
</html>
11 changes: 11 additions & 0 deletions example/slow/slow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$(document).ready(function() {

Demo.setOptions({
baud : 126,
freqLow : 4900,
freqHigh : 7350,
echoCancellation : false,
softmodem : true
});

});
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var WebJack = require("webjack");
var Emitter = require("events").EventEmitter;
var priv = new Map();

function WebJackPort() {
function WebJackPort(options) {
Emitter.call(this);


Expand All @@ -37,7 +37,10 @@ function WebJackPort() {
}
};

var connection = new WebJack.Connection({raw : true});
options = options || {};
options.profile = options.profile || {};
options.profile.raw = true;
var connection = new WebJack.Connection(options.profile);
state.flushTo(connection);

connection.listen(function(data) {
Expand Down