summaryrefslogtreecommitdiffstats
path: root/examples/scripts/macros/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'examples/scripts/macros/index.html')
-rw-r--r--examples/scripts/macros/index.html120
1 files changed, 120 insertions, 0 deletions
diff --git a/examples/scripts/macros/index.html b/examples/scripts/macros/index.html
new file mode 100644
index 0000000..2dc118e
--- /dev/null
+++ b/examples/scripts/macros/index.html
@@ -0,0 +1,120 @@
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" />
6 <title>WebIOPi | Demo</title>
7 <script type="text/javascript" src="/webiopi.js"></script>
8 <script type="text/javascript">
9 webiopi().ready(function() {
10 var content, button;
11 content = $("#content");
12
13 // create a "SWITCH" labeled button for GPIO 21
14 button = webiopi().createGPIOButton(21, "SWITCH");
15 content.append(button); // append button to content div
16
17 // create a "LED" labeled button for GPIO 25
18 button = webiopi().createGPIOButton(25, "LED1");
19 content.append(button); // append button to content div
20
21 // create a button that output a single pulse
22 button = webiopi().createPulseButton("pulse", "Pulse", 25);
23 content.append(button); // append button to content div
24
25 // create a button which output a bit sequence on GPIO 25 with a 100ms period
26 button = webiopi().createSequenceButton("sos", "S.O.S 1", 25, 100, "01010100110011001100101010");
27 content.append(button); // append button to content div
28
29 // the previous button will always output the same sequence
30 // you can also create a simple button with your own function
31 button = webiopi().createButton("sos2", "S.O.S 2", outputSequence);
32 content.append(button); // append button to content div
33
34 // create a button which call PrintTime
35 button = webiopi().createMacroButton("macro", "Print Time", "PrintTime");
36 content.append(button); // append button to content div
37
38 // create a button which call HelloWorld with "User,Name" argument
39 button = webiopi().createMacroButton("macro", "Hello ?", "HelloWorld", ["User", "Name"]);
40 content.append(button); // append button to content div
41
42 // the previous button will always call HelloWorld with "User,Name" argument
43 // you can also create a simple button with your own function
44 button = webiopi().createButton("macro2", "Hello !", callMacro);
45 content.append(button); // append button to content div
46
47 // you can also create a button which calls a different function for mouse down and up events
48 button = webiopi().createButton("hold", "Hold", mousedown, mouseup);
49 content.append(button);
50
51 // Only for Chrome and Safari, create a slider that pulse out a -45 to +45° angle on GPIO 23
52 button = webiopi().createAngleSlider(23);
53 content.append(button);
54
55 // Only for Chrome and Safari, create a slider that pulse out a 0-100% duty cycle ratio on GPIO 24
56 button = webiopi().createRatioSlider(24);
57 content.append(button);
58
59 webiopi().refreshGPIO(true);
60 });
61
62 function mousedown() {
63 webiopi().digitalWrite(25, 1);
64 }
65
66 function mouseup() {
67 webiopi().digitalWrite(25, 0);
68 }
69
70 function outputSequence() {
71 var sequence = "01010100110011001100101010" // S.O.S. morse code or whatever you want
72 // output sequence on gpio 25 with a 100ms period
73 webiopi().outputSequence(25, 100, sequence, sequenceCallback);
74 }
75
76 function sequenceCallback(gpio, data) {
77 alert("sequence on " + gpio + " finished with " + data);
78 }
79
80 function callMacro() {
81 var args = ["User","Name"] // or whatever you want
82 // call HelloWorld(args)
83 webiopi().callMacro("HelloWorld", args, macroCallback);
84 }
85
86 function macroCallback(macro, args, data) {
87 alert(data);
88 }
89
90 </script>
91 <style type="text/css">
92 button {
93 display: block;
94 margin: 5px 5px 5px 5px;
95 width: 160px;
96 height: 45px;
97 font-size: 24pt;
98 font-weight: bold;
99 color: black;
100 }
101
102 input[type="range"] {
103 display: block;
104 width: 160px;
105 height: 45px;
106 }
107
108 .LOW {
109 background-color: White;
110 }
111
112 .HIGH {
113 background-color: Red;
114 }
115 </style>
116</head>
117<body>
118 <div id="content" align="center"></div>
119</body>
120</html>