Skip to content

Commit dd3676e

Browse files
committed
Merge pull request #7 from jadonk/master
0.2.4
2 parents ecd1835 + b75e7f3 commit dd3676e

1,227 files changed

Lines changed: 172041 additions & 75756 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ applications through the use of HTML5/JavaScript web pages.
1717

1818
Installation
1919
------------
20-
Bonescript comes installed on your BeagleBone. If you are looking to update
21-
to the latest revision, use 'opkg' to perform the update:
20+
BoneScript comes installed on your BeagleBone. To update
21+
to the latest revision or install it on another distribution, use 'npm':
2222

23+
````sh
24+
TERM=none npm install -g bonescript
25+
````
26+
27+
Angstrom prerequisites:
2328
````sh
2429
opkg update
25-
opkg install bonescript
30+
opkg install python-misc python-modules
2631
````
2732

2833
Support for other distributions is a work in progress.
@@ -89,8 +94,8 @@ When a callback is provided, the functions will behave asynchronously.
8994
Without a callback provided, the functions will synchronize and complete
9095
before returning.
9196

92-
Digital I/O, Analog I/O, and Advanced I/O
93-
-----------------------------------------
97+
Digital and Analog I/O
98+
----------------------
9499
* analogRead(pin, [callback]) -> value
95100
* analogWrite(pin, value, [freq], [callback])
96101
* attachInterrupt(pin, handler, mode, [callback])
@@ -102,6 +107,23 @@ Digital I/O, Analog I/O, and Advanced I/O
102107
* getPinMode(pin, [callback]) -> pinMode
103108
* shiftOut(dataPin, clockPin, bitOrder, val, [callback])
104109

110+
Serial
111+
------
112+
Uses https://github.com/voodootikigod/node-serialport
113+
* serialOpen(port, options, [callback])
114+
* serialWrite(port, data, [callback])
115+
116+
I2C
117+
---
118+
Uses https://github.com/korevec/node-i2c
119+
* i2cOpen(port, address, options, [callback])
120+
* i2cScan(port, [callback])
121+
* i2cWriteByte(port, byte, [callback])
122+
* i2cWriteBytes(port, command, bytes, [callback])
123+
* i2cReadByte(port, [callback])
124+
* i2cReadBytes(port, command, length, [callback])
125+
* i2cStream(port, command, length, [callback])
126+
105127
Bits/Bytes, Math, Trigonometry and Random Numbers
106128
-------------------------------------------------
107129
* lowByte(value)

demo/analog.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
var b = require('bonescript');
22

3-
inputPin = "P9_36";
4-
outputPin = "P8_13";
3+
var inputPin = "P9_36";
4+
var outputPin = "P9_14";
55

6-
b.pinMode(outputPin, b.OUTPUT);
6+
b.pinMode(outputPin, b.ANALOG_OUTPUT);
77
loop();
88

99
function loop() {
1010
var value = b.analogRead(inputPin);
1111
b.analogWrite(outputPin, value);
1212
setTimeout(loop, 1);
13-
};
13+
}

demo/analog2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var b = require('bonescript');
22

3-
inputPin = "P9_36";
3+
var inputPin = "P9_36";
44

55
loop();
66

demo/blinkled.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var b = require('bonescript');
22

3-
var ledPin = "P8_13";
3+
var ledPin = "P9_14";
44
var ledPin2 = "USR3";
55

66
b.pinMode(ledPin, b.OUTPUT);

demo/fade.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ var b = require('bonescript');
33
// setup starting conditions
44
var awValue = 0.01;
55
var awDirection = 1;
6-
var awPin = "P8_13";
6+
var awPin = "P9_14";
77

88
// configure pin
9-
b.pinMode(awPin, b.OUTPUT);
9+
b.pinMode(awPin, b.ANALOG_OUTPUT);
1010

1111
// call function to update brightness every 10ms
1212
setInterval(fade, 10);

demo/input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var b = require('bonescript');
22

3-
var outputPin = "P8_13";
3+
var outputPin = "P9_14";
44
var inputPin = "P8_19";
55
var ledPin = "USR3";
66
var mydelay = 100;

demo/input2.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
var b = require('bonescript');
22

3-
var outputPin = "P8_13";
4-
var inputPin = "P9_12";
5-
var outputPin2 = "P8_15";
6-
var inputPin2 = "P8_16";
3+
var outputPin = "P9_14";
4+
var inputPin = "P8_19";
5+
var outputPin2 = "P9_16";
6+
var inputPin2 = "P9_15";
77
var ledPin = "USR3";
88
var ledPin2 = "USR2";
99
var mydelay = 100;

demo/shiftout.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// Demonstrate shiftOut with a 7 segment display
3+
//
4+
5+
// read in the BoneScript library
6+
var b = require('bonescript');
7+
8+
// define used pins
9+
var sData = "P9_18";
10+
var sClock = "P9_22";
11+
var sLatch = "P9_17";
12+
var sClear = "P9_15";
13+
14+
// define other global variables
15+
var digit = 0;
16+
var segments = [ 0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90 ];
17+
18+
// configure pins as outputs
19+
b.pinMode(sData, b.OUTPUT);
20+
b.pinMode(sClock, b.OUTPUT);
21+
b.pinMode(sLatch, b.OUTPUT);
22+
b.pinMode(sClear, b.OUTPUT);
23+
24+
// initial states
25+
b.digitalWrite(sData, b.LOW);
26+
b.digitalWrite(sClock, b.LOW);
27+
b.digitalWrite(sLatch, b.LOW);
28+
b.digitalWrite(sClear, b.HIGH);
29+
30+
// call function to start updating the LED shift register
31+
doUpdate();
32+
33+
// function to update the LED shift register
34+
function doUpdate() {
35+
// shift out the character LED pattern
36+
b.shiftOut(sData, sClock, b.MSBFIRST, segments[digit], doLatch);
37+
38+
// update the digit for next time
39+
digit = (digit + 1) % 10;
40+
}
41+
42+
function doLatch() {
43+
// latch in the value
44+
b.digitalWrite(sLatch, b.HIGH, doLatchLow);
45+
}
46+
47+
function doLatchLow() {
48+
b.digitalWrite(sLatch, b.LOW, scheduleUpdate);
49+
}
50+
51+
function scheduleUpdate() {
52+
// update again in another 25ms
53+
setTimeout(doUpdate, 25);
54+
}
577 KB
Binary file not shown.

extras/bacon_cape/demo_flot.html

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<html>
2+
<head>
3+
<title>Flot Demo</title>
4+
<script src="flot/jquery.min.js"></script>
5+
<script src="flot/jquery.flot.min.js"></script>
6+
<script src="http://192.168.7.2/static/bonescript.js"></script>
7+
</head>
8+
<body>
9+
<h1>Flot Demo</h1>
10+
<div id="myplot" style="
11+
width:850px;
12+
height:425px;
13+
padding:10px 5px 0 0;
14+
margin: 15px auto 30px auto;
15+
border: 1px solid #ddd;
16+
background: #fff;
17+
background: linear-gradient(#f6f6f6 0, #fff 50px);
18+
background: -o-linear-gradient(#f6f6f6 0, #fff 50px);
19+
background: -ms-linear-gradient(#f6f6f6 0, #fff 50px);
20+
background: -moz-linear-gradient(#f6f6f6 0, #fff 50px);
21+
background: -webkit-linear-gradient(#f6f6f6 0, #fff 50px);
22+
box-shadow: 0 3px 10px rgba(0,0,0,0.15);
23+
-o-box-shadow: 0 3px 10px rgba(0,0,0,0.1);
24+
-ms-box-shadow: 0 3px 10px rgba(0,0,0,0.1);
25+
-moz-box-shadow: 0 3px 10px rgba(0,0,0,0.1);
26+
-webkit-box-shadow: 0 3px 10px rgba(0,0,0,0.1);
27+
"></div>
28+
<div style="clear:both;"></div>
29+
<script>
30+
$(document).ready( function() {
31+
// Get the BoneScript library and begin app
32+
setTargetAddress('192.168.7.2', {initialized: run});
33+
function run() {
34+
var b = require('bonescript');
35+
var buttonStatus = 0;
36+
var sliderStatus = 0;
37+
var sliderReadIdle = true;
38+
39+
var BUTTON = 'P8_19';
40+
var POT = 'P9_36';
41+
42+
var container = $("#myplot");
43+
var maximum = container.outerWidth() / 2 || 300;
44+
var data = [];
45+
var plotOptions = {
46+
grid: {
47+
borderWidth: 1,
48+
minBorderMargin: 20,
49+
labelMargin: 10,
50+
backgroundColor: {
51+
colors: ["#fff", "#e4f4f4"]
52+
},
53+
margin: {
54+
top: 8,
55+
bottom: 20,
56+
left: 20
57+
},
58+
markings: function(axes) {
59+
var markings = [];
60+
var xaxis = axes.xaxis;
61+
for (var x = Math.floor(xaxis.min); x < xaxis.max; x += xaxis.tickSize * 2) {
62+
markings.push({ xaxis: { from: x, to: x + xaxis.tickSize }, color: "rgba(232, 232, 255, 0.2)" });
63+
}
64+
return markings;
65+
}
66+
},
67+
xaxis: {
68+
tickFormatter: function() {
69+
return "";
70+
},
71+
min: 0,
72+
max: maximum
73+
},
74+
yaxis: {
75+
min: 0,
76+
max: 1.1
77+
},
78+
legend: {
79+
show: true
80+
}
81+
};
82+
var plot = $.plot(container, getData(), plotOptions);
83+
var yaxisLabel = $('<div></div>')
84+
.text("Analog in (%)")
85+
.appendTo(container);
86+
yaxisLabel.css("position", "absolute");
87+
yaxisLabel.css("text-align", "center");
88+
yaxisLabel.css("font-size", "12px");
89+
yaxisLabel.css("top", "50%");
90+
yaxisLabel.css("left", "2px");
91+
yaxisLabel.css("transform", "rotate(-90deg)");
92+
yaxisLabel.css("transform-origin", "0 0");
93+
yaxisLabel.css("margin-top", yaxisLabel.width() / 2 - 20);
94+
95+
function pushData(y) {
96+
if (data.length && (data.length+1) > maximum) {
97+
data = data.slice(1);
98+
}
99+
100+
if (data.length < maximum) {
101+
data.push(y);
102+
}
103+
}
104+
105+
function getData() {
106+
var res = [];
107+
for (var i = 0; i < data.length; ++i) {
108+
res.push([i, data[i]]);
109+
}
110+
var series = [{
111+
data: res,
112+
lines: {
113+
fill: true
114+
}
115+
}];
116+
117+
return series;
118+
}
119+
120+
b.pinMode(BUTTON, b.INPUT);
121+
122+
setInterval(drawGraph, 20);
123+
124+
function drawGraph() {
125+
if(sliderReadIdle) {
126+
sliderReadIdle = false;
127+
b.analogRead(POT, onAnalogRead);
128+
} else {
129+
setTimeout(doSliderRead, 1);
130+
}
131+
pushData(sliderStatus);
132+
plot.setData(getData());
133+
plot.draw();
134+
}
135+
136+
function doSliderRead() {
137+
if(sliderReadIdle) {
138+
sliderReadIdle = false;
139+
b.analogRead(POT, onAnalogRead);
140+
} else {
141+
setTimeout(doSliderRead, 1);
142+
}
143+
}
144+
145+
// Handle data back from potentiometer
146+
function onAnalogRead(x) {
147+
if(!x.err && typeof x.value == 'number') {
148+
sliderReadIdle = true;
149+
sliderStatus = x.value.toFixed(3);
150+
}
151+
}
152+
153+
// Handle data back from button
154+
function onDigitalRead(x) {
155+
buttonStatus = (x.value == b.LOW) ? 1 : 0;
156+
$('#buttonStatus').html(buttonStatus);
157+
}
158+
}
159+
});
160+
</script>
161+
</body>
162+
</html>

0 commit comments

Comments
 (0)