old code cleanup

This commit is contained in:
Nephirus 2012-09-18 22:30:56 +02:00
parent 8f0ee9923c
commit 08e815464d
5 changed files with 0 additions and 764 deletions

View file

@ -1,130 +0,0 @@
#include <Stepper.h>
#include <Servo.h>
#define STEPS 300
Servo myservo;
Stepper stepperA(STEPS, 5, 3, 2, 4);
Stepper stepperB(STEPS, 9, 7, 6, 8);
Stepper stepperC(STEPS, 13, 11, 10, 12);
int SrvPos = 0;
int inByte = 0;
void setup()
{
Serial.begin(115200);
stepperA.setSpeed(50);
stepperB.setSpeed(50);
stepperC.setSpeed(50);
myservo.attach(14);
}
void loop()
{
if (Serial.available() > 0) {
inByte = Serial.read();
if (inByte == 4){
stepperA.step(1);
}
if (inByte == 5){
stepperA.step(-1);
}
if (inByte == 6){
stepperB.step(1);
}
if (inByte == 7){
stepperB.step(-1);
}
if (inByte == 8){
stepperC.step(1);
}
if (inByte == 9){
stepperC.step(-1);
}
if ((inByte >= 20) and (inByte <= 100)){
stepperA.setSpeed(inByte);
stepperB.setSpeed(inByte);
stepperC.setSpeed(inByte);
}
if (inByte == 110){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}
if (inByte == 111){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
digitalWrite(2, HIGH);
digitalWrite(6, HIGH);
digitalWrite(10, HIGH);
}
if (inByte == 112){
SrvPos = SrvPos + 1;
if (SrvPos > 180) SrvPos = 180;
myservo.write(SrvPos);
}
if (inByte == 113){
SrvPos = SrvPos - 1;
if (SrvPos < 1) SrvPos = 1;
myservo.write(SrvPos);
}
if (inByte == 114){
SrvPos = 1;
myservo.write(SrvPos);
}
if (inByte == 115){
SrvPos = 90;
myservo.write(SrvPos);
}
if (inByte == 116){
SrvPos = 180;
myservo.write(SrvPos);
}
}
}

Binary file not shown.

View file

@ -1,392 +0,0 @@
' Gambas class file
PUBLIC Motor_A_Dir AS Integer
PUBLIC Motor_B_Dir AS Integer
PUBLIC Motor_C_Dir AS Integer
PUBLIC Step_IDX AS Integer
PUBLIC Step_COUNT AS Boolean
PUBLIC Step_WDT AS Boolean
PUBLIC js AS Joystick
PUBLIC joy_x AS Integer
PUBLIC joy_y AS Integer
PUBLIC joy_s AS Integer
PUBLIC joy_bt_up AS Integer
PUBLIC joy_bt_down AS Integer
PUBLIC SUB _new()
END
PUBLIC SUB js_StickMove(num AS Integer, pos AS Integer)
TextBox9.Text = num
TextBox10.Text = pos
IF num = 0 THEN joy_x = pos
IF num = 1 THEN joy_y = pos
END
PUBLIC SUB Form_Open()
Motor_A_Dir = 0
Motor_B_Dir = 0
Motor_C_Dir = 0
Button8.Enabled = FALSE
Button10.Enabled = FALSE
Button12.Enabled = FALSE
Step_IDX = 0
Step_COUNT = FALSE
Step_WDT = FALSE
js = NEW Joystick("/dev/input/js0") AS "js"
END
PUBLIC SUB Button1_Click()
SerialPort1.PortName = "/dev/ttyUSB0"
SerialPort1.Speed = 115200
SerialPort1.FlowControl = FALSE
SerialPort1.Open
END
PUBLIC SUB js_ButtonPress(num AS Integer)
' check the corresponding checkbox
IF num = 2 THEN joy_bt_up = 1
IF num = 3 THEN joy_bt_down = 1
END
PUBLIC SUB js_ButtonRelease(num AS Integer)
' uncheck the corresponding checkbox
IF num = 2 THEN joy_bt_up = 0
IF num = 3 THEN joy_bt_down = 0
END
PUBLIC SUB Button2_Click()
Timer1.Enabled = TRUE
END
PUBLIC SUB Button3_Click()
WRITE #SerialPort1, Chr$(TextBox1.Text)
Timer1.Delay = TextBox2.Text
Timer1.Enabled = FALSE
WRITE #SerialPort1, Chr$(110)
END
PUBLIC SUB Timer1_Timer()
IF CheckBox4.Value = TRUE THEN
Step_IDX = Step_IDX + 1
ELSE
Step_IDX = 0
ENDIF
IF CheckBox1.Value = TRUE THEN
IF Motor_A_Dir = 0 THEN WRITE #SerialPort1, Chr$(4)
IF Motor_A_Dir = 1 THEN WRITE #SerialPort1, Chr$(5)
ENDIF
IF CheckBox2.Value = TRUE THEN
IF Motor_B_Dir = 0 THEN WRITE #SerialPort1, Chr$(6)
IF Motor_B_Dir = 1 THEN WRITE #SerialPort1, Chr$(7)
ENDIF
IF CheckBox3.Value = TRUE THEN
IF Motor_C_Dir = 0 THEN WRITE #SerialPort1, Chr$(8)
IF Motor_C_Dir = 1 THEN WRITE #SerialPort1, Chr$(9)
ENDIF
IF Step_IDX > 0 AND Step_IDX = TextBox3.Text THEN
Timer1.Enabled = FALSE
Step_IDX = 0
CheckBox4.Value = FALSE
Step_WDT = FALSE
WRITE #SerialPort1, Chr$(110)
ENDIF
TextBox4.Text = Step_IDX
END
PUBLIC SUB Button4_Click()
WRITE #SerialPort1, Chr$(TextBox1.Text)
END
PUBLIC SUB Button5_Click()
Timer1.Delay = TextBox2.Text
END
PUBLIC SUB Button6_Click()
WRITE #SerialPort1, Chr$(110)
END
PUBLIC SUB Button7_Click()
WRITE #SerialPort1, Chr$(111)
END
PUBLIC SUB Button9_Click()
Button9.Enabled = FALSE
Button8.Enabled = TRUE
Motor_A_Dir = 1
END
PUBLIC SUB Button8_Click()
Button9.Enabled = TRUE
Button8.Enabled = FALSE
Motor_A_Dir = 0
END
PUBLIC SUB Button11_Click()
Button11.Enabled = FALSE
Button10.Enabled = TRUE
Motor_B_Dir = 1
END
PUBLIC SUB Button13_Click()
Button13.Enabled = FALSE
Button12.Enabled = TRUE
Motor_C_Dir = 1
END
PUBLIC SUB Button10_Click()
Button11.Enabled = TRUE
Button10.Enabled = FALSE
Motor_B_Dir = 0
END
PUBLIC SUB Button12_Click()
Button13.Enabled = TRUE
Button12.Enabled = FALSE
Motor_C_Dir = 0
END
PUBLIC SUB Button14_Click()
DIM linc AS Integer
DIM lin AS String
DIM arr_strings AS String[]
arr_strings = Split(File.LOAD("/home/tomsuch/set-1.cnc"), "\n")
FOR EACH lin IN arr_strings
linc = linc + 1
TextBox6.Text = linc
' lin
TextBox5.Text = lin
IF Mid(lin, 1, 1) = "*" THEN
TextBox8.Text = Mid(lin, 2, 40)
ELSE
IF lin <> "" THEN
TextBox1.Text = Val((Mid(lin, 7, 3)))
TextBox2.Text = Val((Mid(lin, 11, 3)))
TextBox7.text = Val((Mid(lin, 1, 5)))
Button4_Click
Button5_Click
TextBox3.Text = Val((Mid(lin, 22, 4)))
IF Mid(lin, 15, 1) = 1 THEN CheckBox1.Value = TRUE
IF Mid(lin, 15, 1) = 0 THEN CheckBox1.Value = FALSE
IF Mid(lin, 16, 1) = 1 THEN Button9_Click
IF Mid(lin, 16, 1) = 0 THEN Button8_Click
IF Mid(lin, 17, 1) = 1 THEN CheckBox2.Value = TRUE
IF Mid(lin, 17, 1) = 0 THEN CheckBox2.Value = FALSE
IF Mid(lin, 18, 1) = 1 THEN Button11_Click
IF Mid(lin, 18, 1) = 0 THEN Button10_Click
IF Mid(lin, 19, 1) = 1 THEN CheckBox3.Value = TRUE
IF Mid(lin, 19, 1) = 0 THEN CheckBox3.Value = FALSE
IF Mid(lin, 20, 1) = 1 THEN Button13_Click
IF Mid(lin, 20, 1) = 0 THEN Button12_Click
CheckBox4.Value = TRUE
Step_WDT = TRUE
Timer1.Enabled = TRUE
WHILE Step_WDT = TRUE
WAIT
WEND
ENDIF
ENDIF
NEXT
END
PUBLIC SUB TextBox5_KeyPress()
END
PUBLIC SUB Timer2_Timer()
TextBox13.Text = joy_bt_up
TextBox14.Text = joy_bt_down
TextBox11.Text = joy_x
TextBox12.Text = joy_y
IF joy_y < 0 THEN
Button12_Click
CheckBox3.Value = TRUE
TextBox3.text = 1
'' CheckBox4.Value = TRUE
''Timer1.Enabled = TRUE
ENDIF
IF joy_y > 0 THEN
Button13_Click
CheckBox3.Value = TRUE
TextBox3.text = 1
'' CheckBox4.Value = TRUE
''Timer1.Enabled = TRUE
ENDIF
IF joy_x < 0 THEN
Button10_Click
CheckBox2.Value = TRUE
TextBox3.text = 1
'' CheckBox4.Value = TRUE
''Timer1.Enabled = TRUE
ENDIF
IF joy_x > 0 THEN
Button11_Click
CheckBox2.Value = TRUE
TextBox3.text = 1
'' CheckBox4.Value = TRUE
''Timer1.Enabled = TRUE
ENDIF
IF joy_bt_up = 1 THEN
Button8_Click
CheckBox1.Value = TRUE
TextBox3.text = 1
'' CheckBox4.Value = TRUE
''Timer1.Enabled = TRUE
ENDIF
IF joy_bt_down = 1 THEN
Button9_Click
CheckBox1.Value = TRUE
TextBox3.text = 1
'' CheckBox4.Value = TRUE
''Timer1.Enabled = TRUE
ENDIF
IF joy_bt_up = 0 AND IF joy_bt_down = 0 THEN CheckBox1.Value = FALSE
IF joy_x = 0 THEN CheckBox2.Value = FALSE
IF joy_y = 0 THEN CheckBox3.Value = FALSE
IF joy_x = 0 AND joy_y = 0 AND joy_bt_down = 0 AND joy_bt_up = 0 THEN Button6_Click
' joy_x = 0
'joy_y = 0
END
PUBLIC SUB Button15_Click()
Timer2.Enabled = TRUE
END
PUBLIC SUB Button16_Click()
Timer2.Enabled = FALSE
END
PUBLIC SUB Button17_Click()
WRITE #SerialPort1, Chr$(112)
END
PUBLIC SUB Button18_Click()
WRITE #SerialPort1, Chr$(113)
END
PUBLIC SUB Button19_Click()
WRITE #SerialPort1, Chr$(114)
END
PUBLIC SUB Button20_Click()
WRITE #SerialPort1, Chr$(115)
END
PUBLIC SUB Button21_Click()
WRITE #SerialPort1, Chr$(116)
END

View file

@ -1,180 +0,0 @@
# Gambas Form File 2.0
{ Form Form
MoveScaled(0,0,114,47)
Text = ("")
{ Button1 Button
MoveScaled(3,4,25,7)
Text = ("CONNECT")
}
{ SerialPort1 #SerialPort
#X = 686
#Y = 161
}
{ Timer1 #Timer
#X = 728
#Y = 161
Delay = 100
}
{ Button2 Button
MoveScaled(95,4,17,3)
Text = ("START")
}
{ Button3 Button
MoveScaled(95,8,17,3)
Text = ("STOP")
}
{ TextBox1 TextBox
MoveScaled(34,4,24,3)
Text = ("30")
}
{ Button4 Button
MoveScaled(60,4,34,3)
Text = ("CAS KROKU (20-100)")
}
{ TextBox2 TextBox
MoveScaled(34,8,24,3)
Text = ("15")
}
{ Button5 Button
MoveScaled(60,8,34,3)
Text = ("CAS CIKLU (1-200) ")
}
{ Button6 Button
MoveScaled(95,12,17,2)
Text = ("ODBRZDIT")
}
{ Button7 Button
MoveScaled(95,16,17,3)
Text = ("ZABRZDIT")
}
{ CheckBox1 CheckBox
MoveScaled(70,17,14,3)
Text = ("MOTOR A")
}
{ CheckBox2 CheckBox
MoveScaled(70,21,14,3)
Text = ("MOTOR B")
}
{ CheckBox3 CheckBox
MoveScaled(70,25,14,3)
Text = ("MOTOR C")
}
{ Button8 Button
MoveScaled(60,16,8,3)
Text = ("<<<")
}
{ Button9 Button
MoveScaled(85,16,9,2)
Text = (">>>")
}
{ Button10 Button
MoveScaled(60,21,8,3)
Text = ("<<<")
}
{ Button11 Button
MoveScaled(85,21,9,3)
Text = (">>>")
}
{ Button12 Button
MoveScaled(60,26,8,3)
Text = ("<<<")
}
{ Button13 Button
MoveScaled(85,26,9,3)
Text = (">>>")
}
{ TextBox3 TextBox
MoveScaled(3,21,15,3)
Text = ("500")
}
{ TextBox4 TextBox
MoveScaled(19,21,15,3)
Text = ("")
}
{ CheckBox4 CheckBox
MoveScaled(43,22,14,2)
Text = ("STEP COUNT")
}
{ Button14 Button
MoveScaled(3,26,55,3)
Text = ("OPEN + START SET")
}
{ TextBox5 TextBox
MoveScaled(26,17,32,3)
Text = ("SET COMMANDS")
Alignment = Align.Center
}
{ TextBox6 TextBox
MoveScaled(3,17,10,3)
Text = ("SET LINES")
Alignment = Align.Center
}
{ TextBox7 TextBox
MoveScaled(14,17,11,3)
Text = ("SET STEPS")
Alignment = Align.Center
}
{ TextBox8 TextBox
MoveScaled(3,13,55,3)
Text = (" -- SET INFO --")
Alignment = Align.Center
}
{ TextBox9 TextBox
MoveScaled(3,30,11,3)
Text = ("TextBox9")
}
{ TextBox10 TextBox
MoveScaled(15,30,11,3)
Text = ("TextBox10")
}
{ TextBox11 TextBox
MoveScaled(27,30,11,3)
Text = ("TextBox11")
}
{ TextBox12 TextBox
MoveScaled(39,30,11,3)
Text = ("TextBox12")
}
{ Timer2 #Timer
#X = 728
#Y = 203
Delay = 30
}
{ Button15 Button
MoveScaled(60,30,16,3)
Text = ("JOY START")
}
{ Button16 Button
MoveScaled(78,30,16,3)
Text = ("JOY STOP")
}
{ TextBox13 TextBox
MoveScaled(3,34,23,3)
Text = ("TextBox13")
}
{ TextBox14 TextBox
MoveScaled(27,34,23,3)
Text = ("TextBox14")
}
{ Button17 Button
MoveScaled(60,35,16,3)
Text = ("SERVO +")
}
{ Button18 Button
MoveScaled(78,35,16,3)
Text = ("SERVO -")
}
{ Button19 Button
MoveScaled(60,40,9,3)
Text = ("Servo 0")
}
{ Button20 Button
MoveScaled(71,40,11,3)
Text = ("Servo 90")
}
{ Button21 Button
MoveScaled(84,40,10,3)
Text = ("Servo 180")
}
}

View file

@ -1,62 +0,0 @@
' Gambas class file
' Joystick.class - represents a HID game device containing
' one or more joysticks and buttons
'
' Copyright 2008 Rob Kudla, Binara, Inc. <rpm@kudla.org>
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License version 2 as
' published by the Free Software Foundation.
PRIVATE jsdev AS Process
PUBLIC SUB _new(OPTIONAL device AS String)
IF device = "" THEN device = "/dev/input/js0"
' the interpreter dies when we try to read from /dev/input/js0 as a file
' saying "invalid argument", so we have to run cat
jsdev = EXEC ["cat", device] FOR READ AS "Device"
END
PUBLIC SUB Close()
' kill the cat process if it's still going
TRY jsdev.Kill
END
PUBLIC SUB Device_Read()
DIM stamp AS Integer
DIM value AS Short
DIM myevent AS Byte
DIM number AS Byte
DIM test AS String
' each joystick event produces 8 bytes
READ #jsdev, stamp, 4 ' 4 bytes
READ #jsdev, value, 2 ' 2 bytes
READ #jsdev, myevent, 1 ' 1 byte
READ #jsdev, number, 1 ' 1 byte
IF myevent AND 1 THEN ' button
IF value THEN ' pressed
PRINT "Got button press"
RAISE ButtonPress(number)
ELSE ' released
PRINT "Got button release"
RAISE ButtonRelease(number)
ENDIF
ELSE IF myevent AND 2 THEN ' joystick axis
RAISE StickMove(number, value)
ELSE
PRINT "Unhandled event: myevent is " & myevent
ENDIF
END
EVENT ButtonPress(ButtonNum AS Integer)
EVENT ButtonRelease(ButtonNum AS Integer)
EVENT StickMove(Axis AS Integer, Position AS Integer)