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="2780" name="attachInterrupt" prototype="Page" created="1371825331945" lastModified="1371825383493">
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>attachInterrupt</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.110 Safari/537.36</http_browser>
11 <time type="date">21.06.2013 09:36:23 CDT</time>
12 <hopsession>127.0.0.192.94.94.z5cudt01kfu3</hopsession>
13 <body><script src="/static/bonescript-demo.js"></script>
\r
14 <h2>BoneScript</h2>
\r
16 <div id='side-menu' class="t3_sidebar">
\r
17 <ul class="left-menu">
\r
18 <strong>Navigation</strong>
\r
19 <li><a href="/Support/BoneScript/menu/">Menu contents</a></li>
\r
22 <div class="t3_content_1">
\r
23 <div id='connect-status'></div>
\r
24 <div id="content_child">
\r
25 <!--- START CONTENT -->
\r
27 <h1>attachInterrupt(pin, handler, mode, [callback])</h1>
\r
28 <p>Detect changes on a digital input line</p>
\r
29 <p><i><em>Note:</em> This function is still undergoing development and debug.</i></p>
\r
30 <h2>Arguments</h2>
\r
32 <li><em>pin</em>: the <a href="/Support/BoneScript/#pin">BeagleBone pin</a> identifier</li>
\r
33 <li><em>handler</em>:
\r
35 <li>true: always call the callback upon interrupt event</li>
\r
36 <li>string: evaluated upon interrupt, passed an object with 'value' having
\r
37 the state of the input pin and will call callback if evaluates to true</li>
\r
40 <li><em>mode</em>: RISING, FALLING or CHANGE</li>
\r
41 <li><em>callback</em>: called when handler returns true or other events</li>
\r
43 <h2>Return value</h2>
\r
45 <li><a href="/Support/BoneScript/#true">true</a> if successful</li>
\r
46 <li><a href="/Support/BoneScript/#false">false</a> on failure</li>
\r
48 <h2>callback(x)</h2>
\r
50 <li><em>x.pin</em>: pin that generated event</li>
\r
51 <li><em>x.output</em>: result of handler function</li>
\r
52 <li><em>x.value</em>: input state of the pin generating the interrupt</li>
\r
53 <li><em>x.attached</em>: handler successfully attached</li>
\r
54 <li><em>x.configured</em>: interrupt handler previously configured</li>
\r
57 <button class="dynlink" onclick="demoRun('code')">run</button>
\r
58 <button class="dynlink" onclick="demoRestore('code')">restore</button>
\r
60 <pre id="code" class="use-editor" style="height: 240px;">
\r
61 var b = require('bonescript');
\r
62 var inputPin = 'P8_19';
\r
63 b.pinMode(inputPin, b.INPUT);
\r
64 b.attachInterrupt(inputPin, true, b.CHANGE, interruptCallback);
\r
65 setTimeout(detach, 12000);
\r
67 function interruptCallback(x) {
\r
68 console.log(JSON.stringify(x));
\r
72 b.detachInterrupt(inputPin);
\r
73 console.log('Interrupt detached');
\r
75 <div readonly id='console-output' style='height: 280px;'></div>
\r
76 <h2>Build and execute instructions</h2>
\r
78 <li>Toggle the state of P8_19 within 12 seconds of starting script.</li>
\r
80 <h2>See also</h2>
\r
81 <h3>Topics</h3>
\r
83 <li><a href="/Support/bone101/#headers">BeagleBone expansion headers</a></li>
\r
84 <li><a href="/Support/BoneScript/#digitalio">Digital I/O</a></li>
\r
86 <h3>Related functions</h3>
\r
88 <li><a href="/Support/BoneScript/#require">require</a></li>
\r
89 <li><a href="/Support/BoneScript/pinMode/">pinMode</a></li>
\r
90 <li><a href="/Support/BoneScript/detachInterrupt/">detachInterrupt</a></li>
\r
92 <h3>Examples</h3>
\r
94 <li><a href="/Support/BoneScript/cape_bacon/">Bacon Cape</a></li>
\r
97 <!--- START FOOTER -->
\r
100 <div style="clear:both;"></div></body>
101 <pseudoparent idref="2471" prototyperef="Page"/>
102 <http_referer>http://beagleboard.org/support/BoneScript/attachInterrupt/edit</http_referer>
103 <http_host>beagleboard.org</http_host>
105 <user>blog.hangerhead.com</user>