Web edits
[beagleboard.org.git] / db / 2780.xml
blob58bd5909397ba9e67782e1fb19e579239582d563
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>&lt;script src=&quot;/static/bonescript-demo.js&quot;&gt;&lt;/script&gt;\r
14 &lt;h2&gt;BoneScript&lt;/h2&gt;\r
16     &lt;div id=&apos;side-menu&apos; class=&quot;t3_sidebar&quot;&gt;\r
17      &lt;ul class=&quot;left-menu&quot;&gt;\r
18       &lt;strong&gt;Navigation&lt;/strong&gt;\r
19       &lt;li&gt;&lt;a href=&quot;/Support/BoneScript/menu/&quot;&gt;Menu contents&lt;/a&gt;&lt;/li&gt;\r
20      &lt;/ul&gt;\r
21     &lt;/div&gt;\r
22     &lt;div class=&quot;t3_content_1&quot;&gt;\r
23      &lt;div id=&apos;connect-status&apos;&gt;&lt;/div&gt;\r
24      &lt;div id=&quot;content_child&quot;&gt;\r
25      &lt;!--- START CONTENT --&gt;\r
27 &lt;h1&gt;attachInterrupt(pin, handler, mode, [callback])&lt;/h1&gt;\r
28 &lt;p&gt;Detect changes on a digital input line&lt;/p&gt;\r
29 &lt;p&gt;&lt;i&gt;&lt;em&gt;Note:&lt;/em&gt; This function is still undergoing development and debug.&lt;/i&gt;&lt;/p&gt;\r
30 &lt;h2&gt;Arguments&lt;/h2&gt;\r
31 &lt;ul&gt;\r
32  &lt;li&gt;&lt;em&gt;pin&lt;/em&gt;: the &lt;a href=&quot;/Support/BoneScript/#pin&quot;&gt;BeagleBone pin&lt;/a&gt; identifier&lt;/li&gt;\r
33  &lt;li&gt;&lt;em&gt;handler&lt;/em&gt;: \r
34   &lt;ul&gt;\r
35    &lt;li&gt;true: always call the callback upon interrupt event&lt;/li&gt;\r
36    &lt;li&gt;string: evaluated upon interrupt, passed an object with &apos;value&apos; having\r
37     the state of the input pin and will call callback if evaluates to true&lt;/li&gt;\r
38   &lt;/ul&gt;\r
39  &lt;/li&gt;\r
40  &lt;li&gt;&lt;em&gt;mode&lt;/em&gt;: RISING, FALLING or CHANGE&lt;/li&gt;\r
41  &lt;li&gt;&lt;em&gt;callback&lt;/em&gt;: called when handler returns true or other events&lt;/li&gt;\r
42 &lt;/ul&gt;\r
43 &lt;h2&gt;Return value&lt;/h2&gt;\r
44 &lt;ul&gt;\r
45  &lt;li&gt;&lt;a href=&quot;/Support/BoneScript/#true&quot;&gt;true&lt;/a&gt; if successful&lt;/li&gt;\r
46  &lt;li&gt;&lt;a href=&quot;/Support/BoneScript/#false&quot;&gt;false&lt;/a&gt; on failure&lt;/li&gt;\r
47 &lt;/ul&gt;\r
48 &lt;h2&gt;callback(x)&lt;/h2&gt;\r
49 &lt;ul&gt;\r
50  &lt;li&gt;&lt;em&gt;x.pin&lt;/em&gt;: pin that generated event&lt;/li&gt;\r
51  &lt;li&gt;&lt;em&gt;x.output&lt;/em&gt;: result of handler function&lt;/li&gt;\r
52  &lt;li&gt;&lt;em&gt;x.value&lt;/em&gt;: input state of the pin generating the interrupt&lt;/li&gt;\r
53  &lt;li&gt;&lt;em&gt;x.attached&lt;/em&gt;: handler successfully attached&lt;/li&gt;\r
54  &lt;li&gt;&lt;em&gt;x.configured&lt;/em&gt;: interrupt handler previously configured&lt;/li&gt;\r
55 &lt;/ul&gt;\r
56 &lt;h2&gt;Example\r
57  &lt;button class=&quot;dynlink&quot; onclick=&quot;demoRun(&apos;code&apos;)&quot;&gt;run&lt;/button&gt;\r
58  &lt;button class=&quot;dynlink&quot; onclick=&quot;demoRestore(&apos;code&apos;)&quot;&gt;restore&lt;/button&gt;\r
59 &lt;/h2&gt;\r
60 &lt;pre id=&quot;code&quot; class=&quot;use-editor&quot; style=&quot;height: 240px;&quot;&gt;\r
61 var b = require(&apos;bonescript&apos;);\r
62 var inputPin = &apos;P8_19&apos;;\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
69 }\r
71 function detach() {\r
72     b.detachInterrupt(inputPin);\r
73     console.log(&apos;Interrupt detached&apos;);\r
74 }&lt;/pre&gt;\r
75 &lt;div readonly id=&apos;console-output&apos; style=&apos;height: 280px;&apos;&gt;&lt;/div&gt;\r
76 &lt;h2&gt;Build and execute instructions&lt;/h2&gt;\r
77 &lt;ul&gt;\r
78  &lt;li&gt;Toggle the state of P8_19 within 12 seconds of starting script.&lt;/li&gt;\r
79 &lt;/ul&gt;\r
80 &lt;h2&gt;See also&lt;/h2&gt;\r
81 &lt;h3&gt;Topics&lt;/h3&gt;\r
82 &lt;ul&gt;\r
83  &lt;li&gt;&lt;a href=&quot;/Support/bone101/#headers&quot;&gt;BeagleBone expansion headers&lt;/a&gt;&lt;/li&gt;\r
84  &lt;li&gt;&lt;a href=&quot;/Support/BoneScript/#digitalio&quot;&gt;Digital I/O&lt;/a&gt;&lt;/li&gt;\r
85 &lt;/ul&gt;\r
86 &lt;h3&gt;Related functions&lt;/h3&gt;\r
87 &lt;ul&gt;\r
88  &lt;li&gt;&lt;a href=&quot;/Support/BoneScript/#require&quot;&gt;require&lt;/a&gt;&lt;/li&gt;\r
89  &lt;li&gt;&lt;a href=&quot;/Support/BoneScript/pinMode/&quot;&gt;pinMode&lt;/a&gt;&lt;/li&gt;\r
90  &lt;li&gt;&lt;a href=&quot;/Support/BoneScript/detachInterrupt/&quot;&gt;detachInterrupt&lt;/a&gt;&lt;/li&gt;\r
91 &lt;/ul&gt;\r
92 &lt;h3&gt;Examples&lt;/h3&gt;\r
93 &lt;ul&gt;\r
94  &lt;li&gt;&lt;a href=&quot;/Support/BoneScript/cape_bacon/&quot;&gt;Bacon Cape&lt;/a&gt;&lt;/li&gt;\r
95 &lt;/ul&gt;\r
97      &lt;!--- START FOOTER --&gt;\r
98      &lt;/div&gt;\r
99     &lt;/div&gt;\r
100     &lt;div style=&quot;clear:both;&quot;&gt;&lt;/div&gt;</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>
104     <lang>en-us</lang>
105     <user>blog.hangerhead.com</user>
106   </hopobject>
107 </xmlroot>