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="1373380628516">
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">09.07.2013 09:37:08 CDT</time>
12 <hopsession>127.0.0.192.91.66.1u0nc432fl6ke</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 <p>This current version tests the installation of BoneScript 0.2.2 provided in
\r
30 the 2013-06-20 Angstrom image. Installation instructions are at
\r
31 <a href="/getting-started">
\r
32 the Getting Started page
\r
35 <button class="dynlink" onclick="demoRun('code')">run</button>
\r
36 <div readonly id='console-output' style="height: 200px;"></div>
\r
37 <h2>Build and execute instructions</h2>
\r
38 <img src="/static/uploads/wired_basic_test_bb.png" align="right" width="300px" />
\r
40 <li>Connect P9_23 to P9_24 through a 1kohm resistor.</li>
\r
41 <li>Connect P9_21 to P9_35 through a 1kohm resistor.</li>
\r
42 <li>Connect a 10uF (35V) capacitor to P9_35 with the other end tied to ground.</li>
\r
43 <li>Run the code and observe '***PASS***' at the end of the log.</li>
\r
44 <li>If you do not see '***PASS***', look for exceptions in the run code.</li>
\r
46 <div style="clear:both;"></div>
\r
47 <h2>Code</h2>
\r
48 <pre style="height: 1800px;" id="code" class="use-editor">
\r
49 var b = require('bonescript');
\r
51 b.getPlatform(onGetPlatform);
\r
53 function onGetPlatform(x) {
\r
54 if(!x.name || !x.serialNumber || !x.version)
\r
55 err('getPlatform returned ' + JSON.stringify(x));
\r
56 console.log('Name = ' + x.name);
\r
57 console.log('S/N = ' + x.serialNumber);
\r
58 console.log('Version = ' + x.version);
\r
59 console.log('BoneScript version = ' + x.bonescript);
\r
60 if(x.bonescript != '0.2.2')
\r
61 err('BoneScript 0.2.2 required');
\r
62 b.setDate(Date().toString(), onSetDate);
\r
65 function onSetDate(x) {
\r
66 if(x.stdout !== null) {
\r
67 err('setDate returned ' + JSON.stringify(x));
\r
69 b.echo('test', onEcho);
\r
72 function onEcho(x) {
\r
73 if(x.data != 'test') err('doEcho returned ' + JSON.stringify(x));
\r
74 b.getPinMode('P9_20', onGetPinMode);
\r
77 function onGetPinMode(x) {
\r
78 if(x.mux != 3) err('getPinMode returned ' + JSON.stringify(x));
\r
79 b.pinMode('P9_24', b.INPUT, 7, 'disabled', 'fast', onPinModeInput);
\r
82 function onPinModeInput(x) {
\r
83 if(x.value !== true) err('pinMode(input) returned ' + JSON.stringify(x));
\r
84 b.pinMode('P9_23', b.OUTPUT, 7, 'disabled', 'fast', onPinModeOutput);
\r
87 function onPinModeOutput(x) {
\r
88 if(x.value !== true) err('pinMode(output) returned ' + JSON.stringify(x));
\r
89 b.digitalWrite('P9_23', b.LOW, onDigitalWriteLow);
\r
92 function onDigitalWriteLow(x) {
\r
93 if(x.data !== null) err('digitalWrite(low) returned ' + JSON.stringify(x));
\r
94 b.digitalRead('P9_24', onDigitalReadLow);
\r
97 function onDigitalReadLow(x) {
\r
98 if(x.value != b.LOW) err('digitalRead(low) returned ' + JSON.stringify(x));
\r
99 b.digitalWrite('P9_23', b.HIGH, onDigitalWriteHigh);
\r
102 function onDigitalWriteHigh(x) {
\r
103 if(x.data !== null) err('digitalWrite(high) returned ' + JSON.stringify(x));
\r
104 b.digitalRead('P9_24', onDigitalReadHigh);
\r
107 function onDigitalReadHigh(x) {
\r
108 if(x.value != b.HIGH) err('digitalRead(high) returned ' + JSON.stringify(x));
\r
109 b.analogWrite('P9_21', 0.27, 2000.0, onAnalogWrite);
\r
112 function onAnalogWrite(x) {
\r
113 if(x.value !== true) err('analogWrite returned ' + JSON.stringify(x));
\r
114 setTimeout(doAnalogRead, 1000);
\r
117 function doAnalogRead() {
\r
118 b.analogRead('P9_35', onAnalogRead);
\r
121 function onAnalogRead(x) {
\r
122 if(x.value > 0.55 || x.value < 0.45)
\r
123 err('analogRead returned ' + JSON.stringify(x));
\r
124 b.writeTextFile('/tmp/basic_test', 'So far so good', onWriteTextFile);
\r
127 function onWriteTextFile(x) {
\r
128 if(x.err !== null) err('writeTextFile returned ' + JSON.stringify(x));
\r
129 b.readTextFile('/tmp/basic_test', onReadTextFile);
\r
132 function onReadTextFile(x) {
\r
133 if(x.err !== null) err('readTextFile returned ' + JSON.stringify(x));
\r
134 if(x.data != 'So far so good')
\r
135 err('onReadTextFile returned ' + JSON.stringify(x));
\r
139 function complete() {
\r
140 console.log('***PASS***');
\r
145 console.log('***FAIL*** ' + x);
\r
149 function printJSON(x) {
\r
150 console.log('x = ' + JSON.stringify(x));
\r
152 </div></div><div style="clear: both;"></div></body>
153 <pseudoparent idref="2471" prototyperef="Page"/>
154 <http_referer>http://beagleboard.org/support/BoneScript/wired_basic_test/edit</http_referer>
155 <http_host>beagleboard.org</http_host>
156 <user>blog.hangerhead.com</user>