1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <?xml-stylesheet type="text/xsl" href="helma.xsl"?>
3 <xmlroot xmlns:hop="http://www.helma.org/docs/guide/features/database">
4 <hopobject id="2737" name="wired_basic_test" prototype="Page" created="1370881904612" lastModified="1372265022864">
5 <hop:parent idref="2471" prototyperef="Page"/>
6 <is_xhtml type="boolean">true</is_xhtml>
7 <http_remotehost>127.0.0.1</http_remotehost>
8 <http_language>en-US,en;q=0.8</http_language>
9 <uri>wired_basic_test</uri>
10 <http_browser>Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36</http_browser>
11 <time type="date">26.06.2013 11:43:42 CDT</time>
12 <hopsession>127.0.0.192.94.94.16y4dhn3hk151</hopsession>
13 <body><script src="/static/bonescript-demo.js"></script>
\r
14 <div id='side-menu' class="t3_sidebar">
\r
15 <ul class="left-menu"><strong>Navigation</strong>
\r
16 <li><a href="/static/side-menu.html">Menu contents</a></li>
\r
19 <div class="t3_content_1"><div id='connect-status'></div><div id="content_child">
\r
20 <h1>Demo: Wired basic test</h1>
\r
21 <p>This is a test to verify the basic functionality of BoneScript. It requires
\r
22 that you perform a small bit of external wiring to make sure output is valid
\r
23 at the expansion header pins. If this test does not pass, it is recommended
\r
24 that you update BoneScript. If after updating BoneScript this test still
\r
25 does not pass, please report the issue on the <a href="/discuss">mailing
\r
29 <button class="dynlink" onclick="demoRun('code')">run</button>
\r
30 <div readonly id='console-output' style="height: 200px;"></div>
\r
31 <h2>Build and execute instructions</h2>
\r
32 <img src="/static/uploads/wired_basic_test_bb.png" align="right" width="300px" />
\r
34 <li>Connect P9_23 to P9_24 through a 1kohm resistor.</li>
\r
35 <li>Connect P9_21 to P9_35 through a 1kohm resistor.</li>
\r
36 <li>Connect a 10uF (35V) capacitor to P9_35 with the other end tied to ground.</li>
\r
37 <li>Run the code and observe '***PASS***' at the end of the log.</li>
\r
38 <li>If you do not see '***PASS***', look for exceptions in the run code.</li>
\r
40 <div style="clear:both;"></div>
\r
41 <h2>Code</h2>
\r
42 <pre style="height: 1800px;" id="code" class="use-editor">
\r
43 var b = require('bonescript');
\r
45 b.getPlatform(onGetPlatform);
\r
47 function onGetPlatform(x) {
\r
48 if(!x.name || !x.serialNumber || !x.version)
\r
49 err('getPlatform returned ' + JSON.stringify(x));
\r
50 console.log('Name = ' + x.name);
\r
51 console.log('S/N = ' + x.serialNumber);
\r
52 console.log('Version = ' + x.version);
\r
53 console.log('BoneScript version = ' + x.bonescript);
\r
54 if(x.bonescript != '0.2.2')
\r
55 err('BoneScript 0.2.2 required');
\r
56 b.setDate(Date().toString(), onSetDate);
\r
59 function onSetDate(x) {
\r
60 if(x.stdout !== null) {
\r
61 err('setDate returned ' + JSON.stringify(x));
\r
63 b.echo('test', onEcho);
\r
66 function onEcho(x) {
\r
67 if(x.data != 'test') err('doEcho returned ' + JSON.stringify(x));
\r
68 b.getPinMode('P9_20', onGetPinMode);
\r
71 function onGetPinMode(x) {
\r
72 if(x.mux != 3) err('getPinMode returned ' + JSON.stringify(x));
\r
73 b.pinMode('P9_24', b.INPUT, 7, 'disabled', 'fast', onPinModeInput);
\r
76 function onPinModeInput(x) {
\r
77 if(x.value !== true) err('pinMode(input) returned ' + JSON.stringify(x));
\r
78 b.pinMode('P9_23', b.OUTPUT, 7, 'disabled', 'fast', onPinModeOutput);
\r
81 function onPinModeOutput(x) {
\r
82 if(x.value !== true) err('pinMode(output) returned ' + JSON.stringify(x));
\r
83 b.digitalWrite('P9_23', b.LOW, onDigitalWriteLow);
\r
86 function onDigitalWriteLow(x) {
\r
87 if(x.data !== null) err('digitalWrite(low) returned ' + JSON.stringify(x));
\r
88 b.digitalRead('P9_24', onDigitalReadLow);
\r
91 function onDigitalReadLow(x) {
\r
92 if(x.value != b.LOW) err('digitalRead(low) returned ' + JSON.stringify(x));
\r
93 b.digitalWrite('P9_23', b.HIGH, onDigitalWriteHigh);
\r
96 function onDigitalWriteHigh(x) {
\r
97 if(x.data !== null) err('digitalWrite(high) returned ' + JSON.stringify(x));
\r
98 b.digitalRead('P9_24', onDigitalReadHigh);
\r
101 function onDigitalReadHigh(x) {
\r
102 if(x.value != b.HIGH) err('digitalRead(high) returned ' + JSON.stringify(x));
\r
103 b.analogWrite('P9_21', 0.27, 2000.0, onAnalogWrite);
\r
106 function onAnalogWrite(x) {
\r
107 if(x.value !== true) err('analogWrite returned ' + JSON.stringify(x));
\r
108 setTimeout(doAnalogRead, 1000);
\r
111 function doAnalogRead() {
\r
112 b.analogRead('P9_35', onAnalogRead);
\r
115 function onAnalogRead(x) {
\r
116 if(x.value > 0.55 || x.value < 0.45)
\r
117 err('analogRead returned ' + JSON.stringify(x));
\r
118 b.writeTextFile('/tmp/basic_test', 'So far so good', onWriteTextFile);
\r
121 function onWriteTextFile(x) {
\r
122 if(x.err !== null) err('writeTextFile returned ' + JSON.stringify(x));
\r
123 b.readTextFile('/tmp/basic_test', onReadTextFile);
\r
126 function onReadTextFile(x) {
\r
127 if(x.err !== null) err('readTextFile returned ' + JSON.stringify(x));
\r
128 if(x.data != 'So far so good')
\r
129 err('onReadTextFile returned ' + JSON.stringify(x));
\r
133 function complete() {
\r
134 console.log('***PASS***');
\r
139 console.log('***FAIL*** ' + x);
\r
143 function printJSON(x) {
\r
144 console.log('x = ' + JSON.stringify(x));
\r
146 </div></div><div style="clear: both;"></div></body>
147 <pseudoparent idref="2471" prototyperef="Page"/>
148 <http_referer>http://beagleboard.org/support/BoneScript/wired_basic_test/edit</http_referer>
149 <http_host>beagleboard.org</http_host>
150 <user>jkridner@gmail.com</user>