Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

old code cleanup

  • Loading branch information...
commit 08e815464df555ade0bdb3e05d788b62ad1c1af4 1 parent 8f0ee99
Nephirus authored September 18, 2012
130  ARDUINO/CNCDUINO.pde
... ...
@@ -1,130 +0,0 @@
1  
-#include <Stepper.h>
2  
-#include <Servo.h>
3  
-
4  
-
5  
-#define STEPS 300
6  
-
7  
-Servo myservo;
8  
-
9  
-Stepper stepperA(STEPS, 5, 3, 2, 4);
10  
-Stepper stepperB(STEPS, 9, 7, 6, 8);
11  
-Stepper stepperC(STEPS, 13, 11, 10, 12);
12  
-
13  
-
14  
-int SrvPos = 0;
15  
-int inByte = 0;
16  
-
17  
-void setup()
18  
-
19  
-{
20  
-  Serial.begin(115200);
21  
-  stepperA.setSpeed(50);
22  
-  stepperB.setSpeed(50);
23  
-  stepperC.setSpeed(50);
24  
-  myservo.attach(14);
25  
-}
26  
-
27  
-void loop()
28  
-{
29  
-  if (Serial.available() > 0) {
30  
-     inByte = Serial.read();
31  
-
32  
-if (inByte == 4){
33  
-  stepperA.step(1);
34  
-}
35  
-
36  
-if (inByte == 5){
37  
-  stepperA.step(-1);
38  
-}
39  
-
40  
-if (inByte == 6){
41  
-  stepperB.step(1);
42  
-}
43  
-
44  
-if (inByte == 7){
45  
-  stepperB.step(-1);
46  
-}
47  
-
48  
-if (inByte == 8){
49  
-  stepperC.step(1);
50  
-}
51  
-
52  
-if (inByte == 9){
53  
-  stepperC.step(-1);
54  
-}
55  
-
56  
-if ((inByte >= 20) and (inByte <= 100)){
57  
-  stepperA.setSpeed(inByte);
58  
-  stepperB.setSpeed(inByte);
59  
-  stepperC.setSpeed(inByte);
60  
-}
61  
-
62  
-if (inByte == 110){
63  
- digitalWrite(2, LOW);
64  
- digitalWrite(3, LOW);
65  
- digitalWrite(4, LOW);
66  
- digitalWrite(5, LOW);
67  
- digitalWrite(6, LOW);
68  
- digitalWrite(7, LOW);
69  
- digitalWrite(8, LOW);
70  
- digitalWrite(9, LOW);
71  
- digitalWrite(10, LOW);
72  
- digitalWrite(11, LOW);
73  
- digitalWrite(12, LOW);
74  
- digitalWrite(13, LOW);
75  
-
76  
-}
77  
-
78  
-if (inByte == 111){
79  
-
80  
-  digitalWrite(2, LOW);
81  
- digitalWrite(3, LOW);
82  
- digitalWrite(4, LOW);
83  
- digitalWrite(5, LOW);
84  
- digitalWrite(6, LOW);
85  
- digitalWrite(7, LOW);
86  
- digitalWrite(8, LOW);
87  
- digitalWrite(9, LOW);
88  
- digitalWrite(10, LOW);
89  
- digitalWrite(11, LOW);
90  
- digitalWrite(12, LOW);
91  
- digitalWrite(13, LOW);
92  
- 
93  
-  digitalWrite(2, HIGH);
94  
- digitalWrite(6, HIGH);
95  
- digitalWrite(10, HIGH);
96  
-
97  
-}
98  
-
99  
-if (inByte == 112){
100  
-  SrvPos = SrvPos + 1;
101  
-  if (SrvPos > 180) SrvPos = 180;
102  
-  myservo.write(SrvPos); 
103  
-}
104  
-
105  
-
106  
-if (inByte == 113){
107  
-  SrvPos = SrvPos - 1;
108  
-  if (SrvPos < 1) SrvPos = 1;
109  
-  myservo.write(SrvPos); 
110  
-}
111  
-
112  
-if (inByte == 114){
113  
-  SrvPos = 1;
114  
-  myservo.write(SrvPos); 
115  
-}
116  
-
117  
-if (inByte == 115){
118  
-  SrvPos = 90;
119  
-  myservo.write(SrvPos); 
120  
-}
121  
-
122  
-if (inByte == 116){
123  
-  SrvPos = 180;
124  
-  myservo.write(SrvPos); 
125  
-}
126  
-
127  
-
128  
-  }
129  
-}
130  
-
BIN  DUINOCNC.gambas
Binary file not shown
392  FMain.class
... ...
@@ -1,392 +0,0 @@
1  
-' Gambas class file
2  
-PUBLIC Motor_A_Dir AS Integer
3  
-PUBLIC Motor_B_Dir AS Integer
4  
-PUBLIC Motor_C_Dir AS Integer
5  
-PUBLIC Step_IDX AS Integer
6  
-PUBLIC Step_COUNT AS Boolean
7  
-PUBLIC Step_WDT AS Boolean
8  
-
9  
-PUBLIC js AS Joystick
10  
-
11  
-PUBLIC joy_x AS Integer
12  
-PUBLIC joy_y AS Integer
13  
-PUBLIC joy_s AS Integer
14  
-
15  
-PUBLIC joy_bt_up AS Integer
16  
-PUBLIC joy_bt_down AS Integer
17  
-
18  
-
19  
-PUBLIC SUB _new()
20  
-
21  
-END
22  
-
23  
-PUBLIC SUB js_StickMove(num AS Integer, pos AS Integer)
24  
-  TextBox9.Text = num
25  
-  TextBox10.Text = pos
26  
-
27  
-IF num = 0 THEN joy_x = pos
28  
-IF num = 1 THEN joy_y = pos
29  
-
30  
-  
31  
-END
32  
-
33  
-PUBLIC SUB Form_Open()
34  
-
35  
-Motor_A_Dir = 0
36  
-Motor_B_Dir = 0
37  
-Motor_C_Dir = 0
38  
-
39  
-Button8.Enabled = FALSE
40  
-Button10.Enabled = FALSE
41  
-Button12.Enabled = FALSE
42  
-
43  
-Step_IDX = 0
44  
-Step_COUNT = FALSE
45  
-Step_WDT = FALSE
46  
-  js = NEW Joystick("/dev/input/js0") AS "js"
47  
-END
48  
-
49  
-PUBLIC SUB Button1_Click()
50  
-
51  
- SerialPort1.PortName = "/dev/ttyUSB0" 
52  
-SerialPort1.Speed = 115200
53  
-SerialPort1.FlowControl = FALSE
54  
-SerialPort1.Open
55  
-
56  
-END
57  
-
58  
-
59  
-PUBLIC SUB js_ButtonPress(num AS Integer)
60  
-  
61  
-  ' check the corresponding checkbox
62  
-  IF num = 2 THEN joy_bt_up = 1
63  
-  IF num = 3 THEN joy_bt_down = 1
64  
-  
65  
-END
66  
-
67  
-PUBLIC SUB js_ButtonRelease(num AS Integer)
68  
-  
69  
-  ' uncheck the corresponding checkbox
70  
-  IF num = 2 THEN joy_bt_up = 0
71  
-  IF num = 3 THEN joy_bt_down = 0
72  
-  
73  
-END
74  
-
75  
-
76  
-PUBLIC SUB Button2_Click()
77  
-
78  
-
79  
-
80  
-  Timer1.Enabled = TRUE
81  
-
82  
-END
83  
-
84  
-PUBLIC SUB Button3_Click()
85  
-WRITE #SerialPort1, Chr$(TextBox1.Text)
86  
-Timer1.Delay = TextBox2.Text
87  
-  Timer1.Enabled = FALSE
88  
- WRITE #SerialPort1, Chr$(110)
89  
-END
90  
-
91  
-PUBLIC SUB Timer1_Timer()
92  
-
93  
-IF CheckBox4.Value = TRUE THEN
94  
- Step_IDX = Step_IDX + 1
95  
-ELSE 
96  
-Step_IDX = 0
97  
-ENDIF 
98  
-
99  
-
100  
-
101  
-IF CheckBox1.Value = TRUE THEN 
102  
-IF Motor_A_Dir = 0 THEN WRITE #SerialPort1, Chr$(4)
103  
-IF Motor_A_Dir = 1 THEN WRITE #SerialPort1, Chr$(5)
104  
-ENDIF 
105  
-
106  
-IF CheckBox2.Value = TRUE THEN 
107  
-IF Motor_B_Dir = 0 THEN WRITE #SerialPort1, Chr$(6)
108  
-IF Motor_B_Dir = 1 THEN WRITE #SerialPort1, Chr$(7)
109  
-ENDIF 
110  
-
111  
-IF CheckBox3.Value = TRUE THEN 
112  
-IF Motor_C_Dir = 0 THEN WRITE #SerialPort1, Chr$(8)
113  
-IF Motor_C_Dir = 1 THEN WRITE #SerialPort1, Chr$(9)
114  
-ENDIF 
115  
-
116  
-IF Step_IDX > 0 AND Step_IDX = TextBox3.Text THEN
117  
-Timer1.Enabled = FALSE
118  
-Step_IDX = 0
119  
-CheckBox4.Value = FALSE
120  
-Step_WDT = FALSE
121  
- WRITE #SerialPort1, Chr$(110)
122  
-ENDIF 
123  
-
124  
-TextBox4.Text = Step_IDX
125  
-
126  
-END
127  
-
128  
-PUBLIC SUB Button4_Click()
129  
-
130  
-WRITE #SerialPort1, Chr$(TextBox1.Text)
131  
-
132  
-END
133  
-
134  
-PUBLIC SUB Button5_Click()
135  
-
136  
-  Timer1.Delay = TextBox2.Text
137  
-
138  
-END
139  
-
140  
-PUBLIC SUB Button6_Click()
141  
-
142  
-  WRITE #SerialPort1, Chr$(110)
143  
-
144  
-END
145  
-
146  
-PUBLIC SUB Button7_Click()
147  
-
148  
-  WRITE #SerialPort1, Chr$(111)
149  
-
150  
-
151  
-END
152  
-
153  
-PUBLIC SUB Button9_Click()
154  
-
155  
-  Button9.Enabled = FALSE
156  
-  Button8.Enabled = TRUE
157  
-  Motor_A_Dir = 1
158  
-
159  
-END
160  
-
161  
-PUBLIC SUB Button8_Click()
162  
-
163  
-  Button9.Enabled = TRUE
164  
-  Button8.Enabled = FALSE
165  
-  Motor_A_Dir = 0
166  
-
167  
-END
168  
-
169  
-PUBLIC SUB Button11_Click()
170  
-
171  
-    Button11.Enabled = FALSE
172  
-  Button10.Enabled = TRUE
173  
-  Motor_B_Dir = 1
174  
-
175  
-
176  
-END
177  
-
178  
-PUBLIC SUB Button13_Click()
179  
-
180  
-    Button13.Enabled = FALSE
181  
-  Button12.Enabled = TRUE
182  
-  Motor_C_Dir = 1
183  
-
184  
-
185  
-END
186  
-
187  
-PUBLIC SUB Button10_Click()
188  
-
189  
-    Button11.Enabled = TRUE
190  
-  Button10.Enabled = FALSE
191  
-  Motor_B_Dir = 0
192  
-
193  
-
194  
-END
195  
-
196  
-PUBLIC SUB Button12_Click()
197  
-
198  
-    Button13.Enabled = TRUE
199  
-  Button12.Enabled = FALSE
200  
-  Motor_C_Dir = 0
201  
-
202  
-
203  
-END
204  
-
205  
-PUBLIC SUB Button14_Click()
206  
-   DIM linc AS Integer
207  
-   DIM lin AS String
208  
-
209  
-  DIM arr_strings AS String[]
210  
-
211  
-arr_strings = Split(File.LOAD("/home/tomsuch/set-1.cnc"), "\n")
212  
-
213  
-FOR EACH lin IN arr_strings
214  
-linc = linc + 1
215  
-
216  
-
217  
-
218  
-TextBox6.Text = linc
219  
-'            lin
220  
-TextBox5.Text = lin
221  
-
222  
-
223  
-IF Mid(lin, 1, 1) = "*" THEN 
224  
-TextBox8.Text = Mid(lin, 2, 40)
225  
-ELSE 
226  
-
227  
-IF lin <> "" THEN
228  
-
229  
-TextBox1.Text = Val((Mid(lin, 7, 3)))
230  
-TextBox2.Text = Val((Mid(lin, 11, 3)))
231  
-TextBox7.text = Val((Mid(lin, 1, 5)))
232  
-
233  
-Button4_Click
234  
-Button5_Click
235  
-
236  
-
237  
-TextBox3.Text = Val((Mid(lin, 22, 4)))
238  
-
239  
-IF Mid(lin, 15, 1) = 1 THEN CheckBox1.Value = TRUE
240  
-IF Mid(lin, 15, 1) = 0 THEN CheckBox1.Value = FALSE
241  
-
242  
-IF Mid(lin, 16, 1) = 1 THEN Button9_Click
243  
-IF Mid(lin, 16, 1) = 0 THEN Button8_Click
244  
-
245  
-
246  
-
247  
-IF Mid(lin, 17, 1) = 1 THEN CheckBox2.Value = TRUE
248  
-IF Mid(lin, 17, 1) = 0 THEN CheckBox2.Value = FALSE
249  
-
250  
-IF Mid(lin, 18, 1) = 1 THEN Button11_Click
251  
-IF Mid(lin, 18, 1) = 0 THEN Button10_Click
252  
-
253  
-
254  
-IF Mid(lin, 19, 1) = 1 THEN CheckBox3.Value = TRUE
255  
-IF Mid(lin, 19, 1) = 0 THEN CheckBox3.Value = FALSE
256  
-
257  
-IF Mid(lin, 20, 1) = 1 THEN Button13_Click
258  
-IF Mid(lin, 20, 1) = 0 THEN Button12_Click
259  
-
260  
- 
261  
-CheckBox4.Value = TRUE
262  
-Step_WDT = TRUE
263  
-Timer1.Enabled = TRUE
264  
-WHILE Step_WDT = TRUE
265  
-WAIT 
266  
-WEND  
267  
-ENDIF 
268  
-ENDIF 
269  
-        NEXT
270  
-
271  
-END
272  
-
273  
-PUBLIC SUB TextBox5_KeyPress()
274  
-
275  
-  
276  
-
277  
-END
278  
-
279  
-PUBLIC SUB Timer2_Timer()
280  
-
281  
-TextBox13.Text = joy_bt_up
282  
-TextBox14.Text = joy_bt_down
283  
-
284  
-
285  
-
286  
-  TextBox11.Text = joy_x
287  
-  TextBox12.Text = joy_y
288  
-  
289  
-IF joy_y < 0 THEN 
290  
- Button12_Click
291  
- CheckBox3.Value = TRUE
292  
-  TextBox3.text = 1
293  
-''  CheckBox4.Value = TRUE
294  
-''Timer1.Enabled = TRUE
295  
-ENDIF 
296  
-
297  
-IF joy_y > 0 THEN 
298  
- Button13_Click 
299  
- CheckBox3.Value = TRUE
300  
-  TextBox3.text = 1
301  
-''  CheckBox4.Value = TRUE
302  
-''Timer1.Enabled = TRUE
303  
-ENDIF 
304  
-  
305  
-IF joy_x < 0 THEN 
306  
- Button10_Click
307  
- CheckBox2.Value = TRUE
308  
-  TextBox3.text = 1
309  
-''  CheckBox4.Value = TRUE
310  
-''Timer1.Enabled = TRUE
311  
-ENDIF 
312  
-
313  
-IF joy_x > 0 THEN 
314  
- Button11_Click 
315  
- CheckBox2.Value = TRUE
316  
-  TextBox3.text = 1
317  
-''  CheckBox4.Value = TRUE
318  
-''Timer1.Enabled = TRUE
319  
-ENDIF 
320  
-
321  
-IF joy_bt_up = 1 THEN 
322  
- Button8_Click
323  
- CheckBox1.Value = TRUE
324  
-  TextBox3.text = 1
325  
-''  CheckBox4.Value = TRUE
326  
-''Timer1.Enabled = TRUE
327  
-ENDIF 
328  
-
329  
-IF joy_bt_down = 1 THEN 
330  
- Button9_Click
331  
- CheckBox1.Value = TRUE
332  
-  TextBox3.text = 1
333  
-''  CheckBox4.Value = TRUE
334  
-''Timer1.Enabled = TRUE
335  
-ENDIF 
336  
-
337  
-IF joy_bt_up = 0 AND IF joy_bt_down = 0 THEN CheckBox1.Value = FALSE
338  
-
339  
-
340  
-
341  
-IF joy_x = 0 THEN CheckBox2.Value = FALSE
342  
-IF joy_y = 0 THEN CheckBox3.Value = FALSE
343  
-
344  
-IF joy_x = 0 AND joy_y = 0 AND joy_bt_down = 0 AND joy_bt_up = 0 THEN Button6_Click
345  
-
346  
-' joy_x = 0
347  
-'joy_y = 0
348  
-
349  
-
350  
-END
351  
-
352  
-PUBLIC SUB Button15_Click()
353  
-
354  
-  Timer2.Enabled = TRUE
355  
-
356  
-END
357  
-
358  
-PUBLIC SUB Button16_Click()
359  
-
360  
-  Timer2.Enabled = FALSE
361  
-
362  
-END
363  
-
364  
-PUBLIC SUB Button17_Click()
365  
-
366  
-  WRITE #SerialPort1, Chr$(112)
367  
-
368  
-END
369  
-
370  
-PUBLIC SUB Button18_Click()
371  
-
372  
-  WRITE #SerialPort1, Chr$(113)
373  
-
374  
-END
375  
-
376  
-PUBLIC SUB Button19_Click()
377  
-
378  
-  WRITE #SerialPort1, Chr$(114)
379  
-
380  
-END
381  
-
382  
-PUBLIC SUB Button20_Click()
383  
-
384  
-  WRITE #SerialPort1, Chr$(115)
385  
-
386  
-END
387  
-
388  
-PUBLIC SUB Button21_Click()
389  
-
390  
-  WRITE #SerialPort1, Chr$(116)
391  
-
392  
-END
180  FMain.form
... ...
@@ -1,180 +0,0 @@
1  
-# Gambas Form File 2.0
2  
-
3  
-{ Form Form
4  
-  MoveScaled(0,0,114,47)
5  
-  Text = ("")
6  
-  { Button1 Button
7  
-    MoveScaled(3,4,25,7)
8  
-    Text = ("CONNECT")
9  
-  }
10  
-  { SerialPort1 #SerialPort
11  
-    #X = 686
12  
-    #Y = 161
13  
-  }
14  
-  { Timer1 #Timer
15  
-    #X = 728
16  
-    #Y = 161
17  
-    Delay = 100
18  
-  }
19  
-  { Button2 Button
20  
-    MoveScaled(95,4,17,3)
21  
-    Text = ("START")
22  
-  }
23  
-  { Button3 Button
24  
-    MoveScaled(95,8,17,3)
25  
-    Text = ("STOP")
26  
-  }
27  
-  { TextBox1 TextBox
28  
-    MoveScaled(34,4,24,3)
29  
-    Text = ("30")
30  
-  }
31  
-  { Button4 Button
32  
-    MoveScaled(60,4,34,3)
33  
-    Text = ("CAS KROKU (20-100)")
34  
-  }
35  
-  { TextBox2 TextBox
36  
-    MoveScaled(34,8,24,3)
37  
-    Text = ("15")
38  
-  }
39  
-  { Button5 Button
40  
-    MoveScaled(60,8,34,3)
41  
-    Text = ("CAS CIKLU (1-200) ")
42  
-  }
43  
-  { Button6 Button
44  
-    MoveScaled(95,12,17,2)
45  
-    Text = ("ODBRZDIT")
46  
-  }
47  
-  { Button7 Button
48  
-    MoveScaled(95,16,17,3)
49  
-    Text = ("ZABRZDIT")
50  
-  }
51  
-  { CheckBox1 CheckBox
52  
-    MoveScaled(70,17,14,3)
53  
-    Text = ("MOTOR  A")
54  
-  }
55  
-  { CheckBox2 CheckBox
56  
-    MoveScaled(70,21,14,3)
57  
-    Text = ("MOTOR B")
58  
-  }
59  
-  { CheckBox3 CheckBox
60  
-    MoveScaled(70,25,14,3)
61  
-    Text = ("MOTOR C")
62  
-  }
63  
-  { Button8 Button
64  
-    MoveScaled(60,16,8,3)
65  
-    Text = ("<<<")
66  
-  }
67  
-  { Button9 Button
68  
-    MoveScaled(85,16,9,2)
69  
-    Text = (">>>")
70  
-  }
71  
-  { Button10 Button
72  
-    MoveScaled(60,21,8,3)
73  
-    Text = ("<<<")
74  
-  }
75  
-  { Button11 Button
76  
-    MoveScaled(85,21,9,3)
77  
-    Text = (">>>")
78  
-  }
79  
-  { Button12 Button
80  
-    MoveScaled(60,26,8,3)
81  
-    Text = ("<<<")
82  
-  }
83  
-  { Button13 Button
84  
-    MoveScaled(85,26,9,3)
85  
-    Text = (">>>")
86  
-  }
87  
-  { TextBox3 TextBox
88  
-    MoveScaled(3,21,15,3)
89  
-    Text = ("500")
90  
-  }
91  
-  { TextBox4 TextBox
92  
-    MoveScaled(19,21,15,3)
93  
-    Text = ("")
94  
-  }
95  
-  { CheckBox4 CheckBox
96  
-    MoveScaled(43,22,14,2)
97  
-    Text = ("STEP COUNT")
98  
-  }
99  
-  { Button14 Button
100  
-    MoveScaled(3,26,55,3)
101  
-    Text = ("OPEN + START SET")
102  
-  }
103  
-  { TextBox5 TextBox
104  
-    MoveScaled(26,17,32,3)
105  
-    Text = ("SET COMMANDS")
106  
-    Alignment = Align.Center
107  
-  }
108  
-  { TextBox6 TextBox
109  
-    MoveScaled(3,17,10,3)
110  
-    Text = ("SET LINES")
111  
-    Alignment = Align.Center
112  
-  }
113  
-  { TextBox7 TextBox
114  
-    MoveScaled(14,17,11,3)
115  
-    Text = ("SET STEPS")
116  
-    Alignment = Align.Center
117  
-  }
118  
-  { TextBox8 TextBox
119  
-    MoveScaled(3,13,55,3)
120  
-    Text = (" -- SET INFO --")
121  
-    Alignment = Align.Center
122  
-  }
123  
-  { TextBox9 TextBox
124  
-    MoveScaled(3,30,11,3)
125  
-    Text = ("TextBox9")
126  
-  }
127  
-  { TextBox10 TextBox
128  
-    MoveScaled(15,30,11,3)
129  
-    Text = ("TextBox10")
130  
-  }
131  
-  { TextBox11 TextBox
132  
-    MoveScaled(27,30,11,3)
133  
-    Text = ("TextBox11")
134  
-  }
135  
-  { TextBox12 TextBox
136  
-    MoveScaled(39,30,11,3)
137  
-    Text = ("TextBox12")
138  
-  }
139  
-  { Timer2 #Timer
140  
-    #X = 728
141  
-    #Y = 203
142  
-    Delay = 30
143  
-  }
144  
-  { Button15 Button
145  
-    MoveScaled(60,30,16,3)
146  
-    Text = ("JOY START")
147  
-  }
148  
-  { Button16 Button
149  
-    MoveScaled(78,30,16,3)
150  
-    Text = ("JOY STOP")
151  
-  }
152  
-  { TextBox13 TextBox
153  
-    MoveScaled(3,34,23,3)
154  
-    Text = ("TextBox13")
155  
-  }
156  
-  { TextBox14 TextBox
157  
-    MoveScaled(27,34,23,3)
158  
-    Text = ("TextBox14")
159  
-  }
160  
-  { Button17 Button
161  
-    MoveScaled(60,35,16,3)
162  
-    Text = ("SERVO +")
163  
-  }
164  
-  { Button18 Button
165  
-    MoveScaled(78,35,16,3)
166  
-    Text = ("SERVO -")
167  
-  }
168  
-  { Button19 Button
169  
-    MoveScaled(60,40,9,3)
170  
-    Text = ("Servo 0")
171  
-  }
172  
-  { Button20 Button
173  
-    MoveScaled(71,40,11,3)
174  
-    Text = ("Servo 90")
175  
-  }
176  
-  { Button21 Button
177  
-    MoveScaled(84,40,10,3)
178  
-    Text = ("Servo 180")
179  
-  }
180  
-}
62  Joystick.class
... ...
@@ -1,62 +0,0 @@
1  
-' Gambas class file
2  
-
3  
-' Joystick.class - represents a HID game device containing 
4  
-'                  one or more joysticks and buttons
5  
-'
6  
-' Copyright 2008 Rob Kudla, Binara, Inc. <rpm@kudla.org>
7  
-'
8  
-' This program is free software; you can redistribute it and/or modify
9  
-' it under the terms of the GNU General Public License version 2 as
10  
-' published by the Free Software Foundation.
11  
-
12  
-PRIVATE jsdev AS Process
13  
-
14  
-PUBLIC SUB _new(OPTIONAL device AS String)
15  
-  
16  
-  IF device = "" THEN device = "/dev/input/js0"
17  
-  ' the interpreter dies when we try to read from /dev/input/js0 as a file
18  
-  ' saying "invalid argument", so we have to run cat
19  
-  jsdev = EXEC ["cat", device] FOR READ AS "Device"
20  
-  
21  
-END
22  
-
23  
-PUBLIC SUB Close()
24  
-  
25  
-  ' kill the cat process if it's still going
26  
-  TRY jsdev.Kill
27  
-  
28  
-END
29  
-
30  
-PUBLIC SUB Device_Read()
31  
-  
32  
-    DIM stamp AS Integer
33  
-    DIM value AS Short
34  
-    DIM myevent AS Byte
35  
-    DIM number AS Byte
36  
-    DIM test AS String
37  
-    
38  
-    ' each joystick event produces 8 bytes
39  
-    READ #jsdev, stamp, 4 ' 4 bytes
40  
-    READ #jsdev, value, 2 ' 2 bytes
41  
-    READ #jsdev, myevent, 1 ' 1 byte
42  
-    READ #jsdev, number, 1 ' 1 byte
43  
-    
44  
-    IF myevent AND 1 THEN ' button
45  
-      IF value THEN ' pressed
46  
-        PRINT "Got button press"
47  
-        RAISE ButtonPress(number)
48  
-      ELSE ' released
49  
-        PRINT "Got button release"
50  
-        RAISE ButtonRelease(number)
51  
-      ENDIF 
52  
-    ELSE IF myevent AND 2 THEN ' joystick axis
53  
-      RAISE StickMove(number, value)
54  
-    ELSE 
55  
-      PRINT "Unhandled event: myevent is " & myevent
56  
-    ENDIF 
57  
-    
58  
-END
59  
-
60  
-EVENT ButtonPress(ButtonNum AS Integer)
61  
-EVENT ButtonRelease(ButtonNum AS Integer)
62  
-EVENT StickMove(Axis AS Integer, Position AS Integer)

0 notes on commit 08e8154

Please sign in to comment.
Something went wrong with that request. Please try again.