diff --git a/emulator/README.txt b/emulator/README.txt new file mode 100644 index 0000000..d1687c9 --- /dev/null +++ b/emulator/README.txt @@ -0,0 +1,43 @@ +Tecla Emulator version 1.1 +---------------------------------------------------------------------------------------------------------------------------------------------------- +Written and Submitted by Akhil Rao aka akdroid + +Tecla Emulator is built for emulation of Tecla Shield a device by Komodo Open Lab used for remote access.More details on http://komodoopenlab.com/ +---------------------------------------------------------------------------------------------------------------------------------------------------- +The emulator is basically a python script and requires Pybluez for accessing bluetooth. + +****Important****** +In order to use Tecla Emulator name your bluetooth device with TeclaShield prefix in order that TeclaAccess App can connect to the emulator. + +How to run: + +1)Download teclaemu.py +2)Open Terminal and cd to the directory where you downloaded the python script. +3)type the following command "python teclaemu.py" + +List of Commands: + +Keys => Function +------------------------------------------------------------------------ +w/W => Generate Event on Jumper 1 +s/S => Generate Event on Jumper 2 +a/A => Generate Event on Jumper 3 +d/D => Generate Event on Jumper 4 +1 => Generate Event on Switch Port 1 +2 => Generate Event on Switch Port 2 +h/H => View possible commands +r/R => Generate Switch Release Event +t/T => Toggle Auto Switch Release Mode +q/Q => Quit + +Notes: + +1)Developers can adapt this script by changing the values of keys:bytevalue in the python dictionary - keyvalue as per their requirement +2)The current set of values works as per the Tecla Access App available in the andorid market. +3)The Keyboard may not function properly as of now. +4)Auto Switch Release Mode is a mode in which switch release events are also generated after a switch event is triggered. +When turned off,release event will have to be inserted manually by command r/R.Default value is true(on).When true(on) +release event cannot be sent using r/R command. + + + diff --git a/emulator/Tecla-Emulator-Win/Readme.txt b/emulator/Tecla-Emulator-Win/Readme.txt new file mode 100644 index 0000000..8b5dd49 --- /dev/null +++ b/emulator/Tecla-Emulator-Win/Readme.txt @@ -0,0 +1,25 @@ +Tecla Emulator GUI for Windows. + +Tecla Emulator GUI is a GUI application for windows using bluecove Libraries and java swing that will emulate TeclaShield device completely.This application is available as a jar file ad can be used by developers to send eventsto Tecla Access Application on android. + +All features of Tecla Access works including the keyboard. + +For more information on Bluecove Libraries. + +Bluecove : http://bluecove.org/ + +For more information on TeclaShield platform: + +http://komodoopenlab.com/tecla/developers/tecla-for-device-manufacturers/ + +***Imortant*** + +In order to use,copy the dlls into your Java Runtime Environment folder. +Typically on Windows 7 +C://Program Files/Java/jre/. + +You will be able to see the gui only when you start the Tecla Access App and bluetooth on on your android phone. + +***Download Link*** + +https://github.com/AKdroid/Tecla-emu/downloads diff --git a/emulator/Tecla-Emulator-Win/com/akdroid/btoothgui/BTserver.java b/emulator/Tecla-Emulator-Win/com/akdroid/btoothgui/BTserver.java new file mode 100644 index 0000000..a0335bd --- /dev/null +++ b/emulator/Tecla-Emulator-Win/com/akdroid/btoothgui/BTserver.java @@ -0,0 +1,73 @@ +package com.akdroid.btoothgui; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import javax.bluetooth.*; +import javax.microedition.io.*; +public class BTserver extends Thread implements Runnable { + + public UUID uuid; //it can be generated randomly + public String name ; //the name of the service + public String url ; + LocalDevice local ; + StreamConnectionNotifier server ; + StreamConnection conn ; + DataInputStream datain; + DataOutputStream dataout; + public BTserver(){ + uuid = new UUID( //the uid of the service, it has to be unique, + "0000110100001000800000805F9B34FB", false); + name = "SPP"; //the name of the service + url = "btspp://localhost:" + uuid //the service url + + ";name=" + name + + ";authenticate=false;encrypt=false;"; + + System.out.println("Starting bluetooth device and making it discoverable"); + try { + local = LocalDevice.getLocalDevice(); + local.setDiscoverable(DiscoveryAgent.GIAC); + try { + server = (StreamConnectionNotifier)Connector.open(url); + conn = server.acceptAndOpen(); + System.out.println("Client Connected..."); + datain=new DataInputStream(conn.openDataInputStream()); + dataout=new DataOutputStream(conn.openDataOutputStream()); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } catch (BluetoothStateException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + public void ping(){ + Byte c; + while(true){ + try { + if((c = datain.readByte()) > 0){ + dataout.writeByte(c); + //System.out.println(c); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + public void run(){ + ping(); + } + public void send(Byte b){ + try { + dataout.writeByte(b); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} + diff --git a/emulator/Tecla-Emulator-Win/com/akdroid/btoothgui/GUinterface.java b/emulator/Tecla-Emulator-Win/com/akdroid/btoothgui/GUinterface.java new file mode 100644 index 0000000..6bea82d --- /dev/null +++ b/emulator/Tecla-Emulator-Win/com/akdroid/btoothgui/GUinterface.java @@ -0,0 +1,141 @@ +package com.akdroid.btoothgui; +import java.awt.*; +import javax.swing.JFrame; +import javax.swing.JLabel; +import java.awt.event.MouseEvent; + +import java.awt.event.MouseListener; + +import java.awt.image.BufferedImage; + + +public class GUinterface { + + Window w; + Button ecu1,ecu2,ecu3,ecu4,e1,e2,e3; + JLabel status,switchstate,dummy; + BufferedImage im; + JFrame f; + JFrame d; + Byte state; + BTserver bt;//=new BTserver(); + //bt.start(); +GUinterface(){ + w=null; + d=new JFrame("TeclaEmulator"); + d.setBounds(100, 100, 600, 400); + state=0x3F; + gui_init(); + bt=new BTserver(); + bt.start(); +} +public void gui_init() +{ + f=new JFrame(); + ecu1=new Button(); + ecu2=new Button(); + ecu3=new Button(); + ecu4=new Button(); + e1=new Button(); + e2=new Button(); + e3=new Button(); + status=new JLabel(); + switchstate=new JLabel(); + dummy=new JLabel(); + switchstate.setAlignmentX(JLabel.CENTER_ALIGNMENT); + status.setAlignmentX(JLabel.CENTER_ALIGNMENT); + ecu1.setLabel("ECU1"); + ecu2.setLabel("ECU2"); + ecu3.setLabel("ECU3"); + ecu4.setLabel("ECU4"); + e1.setLabel(" E1 "); + e2.setLabel(" E2 "); + + d.add(ecu1); + d.add(ecu2); + d.add(ecu3); + d.add(ecu4); + d.add(e1); + d.add(e2); + d.add(status); + d.add(switchstate); + d.add(dummy); + int xoffset=50,yoffset=150; + ecu1.setBounds(125+xoffset, 40+yoffset, 100, 60); + ecu2.setBounds(125+xoffset, 120+yoffset, 100, 60); + ecu3.setBounds(5+xoffset, 120+yoffset, 100, 60); + ecu4.setBounds(245+xoffset, 120+yoffset, 100, 60); + e1.setBounds(365+xoffset, 40+yoffset, 100, 60); + //System.out.println("e2 bounds"); + e2.setBounds(365+xoffset, 120+yoffset, 100, 60); + status.setBounds(xoffset-25, yoffset-50, 350, 60); + status.setForeground(new Color(0x0000FF)); + status.setBackground(new Color(0xFFFFFF)); + switchstate.setForeground(new Color(0x0000FF)); + switchstate.setBackground(new Color(0xFF0000)); + status.setText("Welcome to TeclaEmulator"); + switchstate.setBounds(410 ,yoffset-50, 150, 60); + switchstate.setText("SwitchState = 0x3F"); + ecu1.addMouseListener(new TeclaListener((byte)0x01,"ECU1")); + ecu2.addMouseListener(new TeclaListener((byte)0x02,"ECU2")); + ecu3.addMouseListener(new TeclaListener((byte)0x04,"ECU3")); + ecu4.addMouseListener(new TeclaListener((byte)0x08,"ECU4")); + e1.addMouseListener(new TeclaListener((byte)0x10,"E1")); + e2.addMouseListener(new TeclaListener((byte)0x20,"E2")); + //ecu1.setBounds(720, 220, 100, 80); + //d= new Dialog(w,"TeclaEmulator"); +} +@SuppressWarnings("deprecation") +public void show(){ + System.out.println("gui show"); + d.show(); + +} +@SuppressWarnings("deprecation") +public void hide(){ + d.hide(); +} + + +class TeclaListener implements MouseListener { + Byte mask; + String name; + TeclaListener(byte st,String nm){ + mask=st; + name=nm; + } + + public void mouseClicked(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + @Override + public void mouseEntered(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + @Override + public void mouseExited(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + @Override + public void mousePressed(MouseEvent arg0) { + // TODO Auto-generated method stub + state=(byte) (state & ~mask); + switchstate.setText("switchstate = "+Integer.toHexString(state)); + status.setText(name + " Pressed "); + bt.send(state); + } + @Override + public void mouseReleased(MouseEvent arg0) { + // TODO Auto-generated method stub + state=(byte) (state | mask); + switchstate.setText("switchstate = "+Integer.toHexString(state)); + status.setText(name + " Released "); + bt.send(state); + } +} + + +} diff --git a/emulator/Tecla-Emulator-Win/com/akdroid/btoothgui/btooth.java b/emulator/Tecla-Emulator-Win/com/akdroid/btoothgui/btooth.java new file mode 100644 index 0000000..ecdde4e --- /dev/null +++ b/emulator/Tecla-Emulator-Win/com/akdroid/btoothgui/btooth.java @@ -0,0 +1,20 @@ +package com.akdroid.btoothgui; + +public class btooth { + + /** + * @param args + */ + + //@SuppressWarnings("deprecation") + public static void main(String[] args) { + GUinterface g1=new GUinterface(); + + g1.show(); + + //r.delay(10000); + //g1.hide(); + //bt.ping(); + } + +} diff --git a/emulator/Tecla-Emulator-Win/javabtoothgui/.classpath b/emulator/Tecla-Emulator-Win/javabtoothgui/.classpath new file mode 100644 index 0000000..a0cf91f --- /dev/null +++ b/emulator/Tecla-Emulator-Win/javabtoothgui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/emulator/Tecla-Emulator-Win/javabtoothgui/.project b/emulator/Tecla-Emulator-Win/javabtoothgui/.project new file mode 100644 index 0000000..27c8847 --- /dev/null +++ b/emulator/Tecla-Emulator-Win/javabtoothgui/.project @@ -0,0 +1,17 @@ + + + javabtoothgui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/emulator/Tecla-Emulator-Win/javabtoothgui/.settings/org.eclipse.jdt.core.prefs b/emulator/Tecla-Emulator-Win/javabtoothgui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..42093f1 --- /dev/null +++ b/emulator/Tecla-Emulator-Win/javabtoothgui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Sat Apr 14 13:01:32 IST 2012 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/emulator/Tecla-Emulator-Win/javabtoothgui/bin/com/akdroid/btoothgui/BTserver.class b/emulator/Tecla-Emulator-Win/javabtoothgui/bin/com/akdroid/btoothgui/BTserver.class new file mode 100644 index 0000000..9649d01 Binary files /dev/null and b/emulator/Tecla-Emulator-Win/javabtoothgui/bin/com/akdroid/btoothgui/BTserver.class differ diff --git a/emulator/Tecla-Emulator-Win/javabtoothgui/bin/com/akdroid/btoothgui/GUinterface$TeclaListener.class b/emulator/Tecla-Emulator-Win/javabtoothgui/bin/com/akdroid/btoothgui/GUinterface$TeclaListener.class new file mode 100644 index 0000000..26b294e Binary files /dev/null and b/emulator/Tecla-Emulator-Win/javabtoothgui/bin/com/akdroid/btoothgui/GUinterface$TeclaListener.class differ diff --git a/emulator/Tecla-Emulator-Win/javabtoothgui/bin/com/akdroid/btoothgui/GUinterface.class b/emulator/Tecla-Emulator-Win/javabtoothgui/bin/com/akdroid/btoothgui/GUinterface.class new file mode 100644 index 0000000..1c1fe26 Binary files /dev/null and b/emulator/Tecla-Emulator-Win/javabtoothgui/bin/com/akdroid/btoothgui/GUinterface.class differ diff --git a/emulator/Tecla-Emulator-Win/javabtoothgui/bin/com/akdroid/btoothgui/btooth.class b/emulator/Tecla-Emulator-Win/javabtoothgui/bin/com/akdroid/btoothgui/btooth.class new file mode 100644 index 0000000..c675e4e Binary files /dev/null and b/emulator/Tecla-Emulator-Win/javabtoothgui/bin/com/akdroid/btoothgui/btooth.class differ diff --git a/emulator/Tecla-Emulator-Win/javabtoothgui/bin/shield.png b/emulator/Tecla-Emulator-Win/javabtoothgui/bin/shield.png new file mode 100644 index 0000000..1eb32a2 Binary files /dev/null and b/emulator/Tecla-Emulator-Win/javabtoothgui/bin/shield.png differ diff --git a/emulator/Tecla-Emulator-Win/javabtoothgui/src/com/akdroid/btoothgui/BTserver.java b/emulator/Tecla-Emulator-Win/javabtoothgui/src/com/akdroid/btoothgui/BTserver.java new file mode 100644 index 0000000..a0335bd --- /dev/null +++ b/emulator/Tecla-Emulator-Win/javabtoothgui/src/com/akdroid/btoothgui/BTserver.java @@ -0,0 +1,73 @@ +package com.akdroid.btoothgui; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import javax.bluetooth.*; +import javax.microedition.io.*; +public class BTserver extends Thread implements Runnable { + + public UUID uuid; //it can be generated randomly + public String name ; //the name of the service + public String url ; + LocalDevice local ; + StreamConnectionNotifier server ; + StreamConnection conn ; + DataInputStream datain; + DataOutputStream dataout; + public BTserver(){ + uuid = new UUID( //the uid of the service, it has to be unique, + "0000110100001000800000805F9B34FB", false); + name = "SPP"; //the name of the service + url = "btspp://localhost:" + uuid //the service url + + ";name=" + name + + ";authenticate=false;encrypt=false;"; + + System.out.println("Starting bluetooth device and making it discoverable"); + try { + local = LocalDevice.getLocalDevice(); + local.setDiscoverable(DiscoveryAgent.GIAC); + try { + server = (StreamConnectionNotifier)Connector.open(url); + conn = server.acceptAndOpen(); + System.out.println("Client Connected..."); + datain=new DataInputStream(conn.openDataInputStream()); + dataout=new DataOutputStream(conn.openDataOutputStream()); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } catch (BluetoothStateException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + public void ping(){ + Byte c; + while(true){ + try { + if((c = datain.readByte()) > 0){ + dataout.writeByte(c); + //System.out.println(c); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + public void run(){ + ping(); + } + public void send(Byte b){ + try { + dataout.writeByte(b); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} + diff --git a/emulator/Tecla-Emulator-Win/javabtoothgui/src/com/akdroid/btoothgui/GUinterface.java b/emulator/Tecla-Emulator-Win/javabtoothgui/src/com/akdroid/btoothgui/GUinterface.java new file mode 100644 index 0000000..6bea82d --- /dev/null +++ b/emulator/Tecla-Emulator-Win/javabtoothgui/src/com/akdroid/btoothgui/GUinterface.java @@ -0,0 +1,141 @@ +package com.akdroid.btoothgui; +import java.awt.*; +import javax.swing.JFrame; +import javax.swing.JLabel; +import java.awt.event.MouseEvent; + +import java.awt.event.MouseListener; + +import java.awt.image.BufferedImage; + + +public class GUinterface { + + Window w; + Button ecu1,ecu2,ecu3,ecu4,e1,e2,e3; + JLabel status,switchstate,dummy; + BufferedImage im; + JFrame f; + JFrame d; + Byte state; + BTserver bt;//=new BTserver(); + //bt.start(); +GUinterface(){ + w=null; + d=new JFrame("TeclaEmulator"); + d.setBounds(100, 100, 600, 400); + state=0x3F; + gui_init(); + bt=new BTserver(); + bt.start(); +} +public void gui_init() +{ + f=new JFrame(); + ecu1=new Button(); + ecu2=new Button(); + ecu3=new Button(); + ecu4=new Button(); + e1=new Button(); + e2=new Button(); + e3=new Button(); + status=new JLabel(); + switchstate=new JLabel(); + dummy=new JLabel(); + switchstate.setAlignmentX(JLabel.CENTER_ALIGNMENT); + status.setAlignmentX(JLabel.CENTER_ALIGNMENT); + ecu1.setLabel("ECU1"); + ecu2.setLabel("ECU2"); + ecu3.setLabel("ECU3"); + ecu4.setLabel("ECU4"); + e1.setLabel(" E1 "); + e2.setLabel(" E2 "); + + d.add(ecu1); + d.add(ecu2); + d.add(ecu3); + d.add(ecu4); + d.add(e1); + d.add(e2); + d.add(status); + d.add(switchstate); + d.add(dummy); + int xoffset=50,yoffset=150; + ecu1.setBounds(125+xoffset, 40+yoffset, 100, 60); + ecu2.setBounds(125+xoffset, 120+yoffset, 100, 60); + ecu3.setBounds(5+xoffset, 120+yoffset, 100, 60); + ecu4.setBounds(245+xoffset, 120+yoffset, 100, 60); + e1.setBounds(365+xoffset, 40+yoffset, 100, 60); + //System.out.println("e2 bounds"); + e2.setBounds(365+xoffset, 120+yoffset, 100, 60); + status.setBounds(xoffset-25, yoffset-50, 350, 60); + status.setForeground(new Color(0x0000FF)); + status.setBackground(new Color(0xFFFFFF)); + switchstate.setForeground(new Color(0x0000FF)); + switchstate.setBackground(new Color(0xFF0000)); + status.setText("Welcome to TeclaEmulator"); + switchstate.setBounds(410 ,yoffset-50, 150, 60); + switchstate.setText("SwitchState = 0x3F"); + ecu1.addMouseListener(new TeclaListener((byte)0x01,"ECU1")); + ecu2.addMouseListener(new TeclaListener((byte)0x02,"ECU2")); + ecu3.addMouseListener(new TeclaListener((byte)0x04,"ECU3")); + ecu4.addMouseListener(new TeclaListener((byte)0x08,"ECU4")); + e1.addMouseListener(new TeclaListener((byte)0x10,"E1")); + e2.addMouseListener(new TeclaListener((byte)0x20,"E2")); + //ecu1.setBounds(720, 220, 100, 80); + //d= new Dialog(w,"TeclaEmulator"); +} +@SuppressWarnings("deprecation") +public void show(){ + System.out.println("gui show"); + d.show(); + +} +@SuppressWarnings("deprecation") +public void hide(){ + d.hide(); +} + + +class TeclaListener implements MouseListener { + Byte mask; + String name; + TeclaListener(byte st,String nm){ + mask=st; + name=nm; + } + + public void mouseClicked(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + @Override + public void mouseEntered(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + @Override + public void mouseExited(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + @Override + public void mousePressed(MouseEvent arg0) { + // TODO Auto-generated method stub + state=(byte) (state & ~mask); + switchstate.setText("switchstate = "+Integer.toHexString(state)); + status.setText(name + " Pressed "); + bt.send(state); + } + @Override + public void mouseReleased(MouseEvent arg0) { + // TODO Auto-generated method stub + state=(byte) (state | mask); + switchstate.setText("switchstate = "+Integer.toHexString(state)); + status.setText(name + " Released "); + bt.send(state); + } +} + + +} diff --git a/emulator/Tecla-Emulator-Win/javabtoothgui/src/com/akdroid/btoothgui/btooth.java b/emulator/Tecla-Emulator-Win/javabtoothgui/src/com/akdroid/btoothgui/btooth.java new file mode 100644 index 0000000..ecdde4e --- /dev/null +++ b/emulator/Tecla-Emulator-Win/javabtoothgui/src/com/akdroid/btoothgui/btooth.java @@ -0,0 +1,20 @@ +package com.akdroid.btoothgui; + +public class btooth { + + /** + * @param args + */ + + //@SuppressWarnings("deprecation") + public static void main(String[] args) { + GUinterface g1=new GUinterface(); + + g1.show(); + + //r.delay(10000); + //g1.hide(); + //bt.ping(); + } + +} diff --git a/emulator/Tecla-Emulator-Win/javabtoothgui/src/shield.png b/emulator/Tecla-Emulator-Win/javabtoothgui/src/shield.png new file mode 100644 index 0000000..1eb32a2 Binary files /dev/null and b/emulator/Tecla-Emulator-Win/javabtoothgui/src/shield.png differ diff --git a/emulator/Tecla-Emulator-Win/libs/bluecove-2.1.1-SNAPSHOT.jar b/emulator/Tecla-Emulator-Win/libs/bluecove-2.1.1-SNAPSHOT.jar new file mode 100644 index 0000000..ce9ca6c Binary files /dev/null and b/emulator/Tecla-Emulator-Win/libs/bluecove-2.1.1-SNAPSHOT.jar differ diff --git a/emulator/teclaemu.py b/emulator/teclaemu.py index 8ff30b5..4676ff3 100644 --- a/emulator/teclaemu.py +++ b/emulator/teclaemu.py @@ -3,147 +3,85 @@ from bluetooth import * from threading import Thread # -# Tecla Emulator v0.2 +# Tecla Emulator v1.1 # written by Akhil Rao # +#Keyboard +#J1 -> Highlight next +#J2 -> Highlight prev +#J3 -> Cancel +#J4 -> select highlighted +# +#SW1 ->Select highlighted +#SW2 ->Cancel +version = "v1.1" -## {{{ http://code.activestate.com/recipes/134892/ (r2) -class _Getch: - """Gets a single character from standard input. Does not echo to the -screen.""" - def __init__(self): - try: - self.impl = _GetchWindows() - except ImportError: - self.impl = _GetchUnix() - - def __call__(self): return self.impl() - - -class _GetchUnix: - def __init__(self): - import tty, sys - - def __call__(self): - import sys, tty, termios - fd = sys.stdin.fileno() - old_settings = termios.tcgetattr(fd) - try: - tty.setraw(sys.stdin.fileno()) - ch = sys.stdin.read(1) - finally: - termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) - return ch - - -class _GetchWindows: - def __init__(self): - import msvcrt - - def __call__(self): - import msvcrt - return msvcrt.getch() - - -getch = _Getch() -## end of http://code.activestate.com/recipes/134892/ }}} - -def sendEvent(event): - client_socket.send(chr(keyvalue[event])) - -def listenkeys(): - auto_release = True; - exitflag=False; - while not exitflag : - print ("Your switch action w/s/a/d/1/2/r?"); - c = getch(); - c = c.upper(); - if(c in "WSAD12QHRT"): - #Valid key pressed - if(c in "HTQ"): - #Command key pressed - if c == "H": #Help - print helpstring - if c == "T": #Help - auto_release = not auto_release; - if auto_release: - print "Auto-release ON" - else: - print "Auto-release OFF" - if c == "Q": #Help - exitflag= True; - print keymessage[c] - - if(c in "WSAD12R"): - #Switch key pressed - sendEvent(c) - print keymessage[c]; - if auto_release: - time.sleep(0.1) #Connection seems to have long latency - sendEvent('R') - else: - #Invalid key pressed - print "Invalid value" - -version = "v0.2" print 'Tecla - Emulator ' , version ; print 'press h/H for list of possible commands' print 'press q/Q to quit' print 'Auto switch release mode set to True' #setup the bluetooth RFComm socket i.e bind and start listening -server_socket = BluetoothSocket( RFCOMM ) + +server_socket=BluetoothSocket( RFCOMM ) + +# server_socket is the socket for bluetooth set to RFCOMM + server_socket.bind(('', 1)) + server_socket.listen(1) +#uuid = "00001101-0000-1000-8000-00805F9B34FB" +uuid="00001101-0000-1000-8000-00000000ABCD" #uuid can be used if bluetooth client side program is written to minimize discovery and filtering time -uuid = "00001101-0000-1000-8000-00805F9B34FB" -advertise_service( - server_socket, - "SPP", - uuid, - service_classes=[SERIAL_PORT_CLASS], - profiles=[SERIAL_PORT_PROFILE] - ) + +advertise_service(server_socket, "TeclaShield",uuid, service_classes=[SERIAL_PORT_CLASS], profiles=[SERIAL_PORT_PROFILE]) print 'Waiting for a device ........' + client_socket, addr = server_socket.accept() -print 'Accepted connection from ', addr -#Keyboard -#ECU1 -> Highlight next -#ECU2 -> Highlight prev -#ECU3 -> Cancel -#ECU4 -> select highlighted -# -#SP1 -> Select highlighted -#SP2 -> Cancel +print 'Accepted connection from ', addr #keyvalue is the dictionary used for holding character input from keyboard and corresponding value of the byte to be sent.... -keyvalue={ - "R":0x3F, #Released all switches - "W":0x3E, #ECU1 pressed - "S":0x3D, #ECU2 pressed - "A":0x3B, #ECU3 pressed - "D":0x37, #ECU4 pressed - "1":0x2F, #Switch Port 1 pressed - "2":0x1F, #Switch Port 2 pressed - "Q":0x88, #Quit the emulator - "H":0x77, #Show commands list - "T":0x99, #Toggle release event mode - } -keymessage= { - "R":"All Switches Released ", - "W":"ECU1 pressed", - "S":"ECU2 pressed", - "A":"ECU3 pressed", - "D":"ECU4 pressed", - "1":"Switch Port 1 pressed", - "2":"Switch Port 2 pressed", - "Q":"Quitting the emulator" - } +keyvalue={ "w":0x01, #Joystick 1 asserted + "W":0x3E, + "s":0x02, #Joystick 2 asserted + "S":0x3D, + "a":0x04, #Joystick 4 asserted + "A":0x0B, + "d":0x08, #Joystick 3 asserted + "D":0x07, + "1":0x10, #Switch 1 asserted + "2":0x20, #Switch 2 asserted + "q":0x88, + "Q":0x88, #Quit the emulator + "h":0x77, + "H":0x77, #Show command lists + "r":160, + "R":160, #Release switch event + "t":0x99, + "T":0x99, #Toggle release event mode + } +keymessage= { + "w":"Event on Joystick 1 generated", #Joystick 1 asserted + "W":"Event on Joystick 1 generated", + "s":"Event on Joystick 2 generated", #Joystick 2 asserted + "S":"Event on Joystick 2 generated", + "d":"Event on Joystick 4 generated", #Joystick 4 asserted + "D":"Event on Joystick 4 generated", + "a":"Event on Joystick 3 generated", #Joystick 3 asserted + "A":"Event on Joystick 3 generated", + "2":"Event on Switch Port 2 generated", #Switch 2 asserted + "1":"Event on Switch Port 1 generated", #Switch 1 asserted + "q":"Quitting the emulator", + "Q":"Quitting the emulator", + "r":"Switch Released ", + "R":"Switch Released " #Switch Released + } + helpstring = "\nw/W => Generate Event on Joystick 1" helpstring=helpstring + "\ns/S => Generate Event on Joystick 2 " helpstring=helpstring + "\na/A => Generate Event on Joystick 3 " @@ -155,15 +93,47 @@ def listenkeys(): helpstring=helpstring + "\nt/T => Toggle auto switch release event" helpstring=helpstring + "\nq/Q => Quit " helpstring=helpstring + "\n\n\n#####Auto switch release mode is a mode in which switch release events are inserted after every switch event \nDefault set to true.\nCan be turned on or off by command t/T" - -main_thread= Thread(target=listenkeys); -main_thread.start(); -while main_thread.isAlive(): - time.sleep(0.1) - data_in=client_socket.recv(128) - if(len(data_in) > 0): - client_socket.send(data_in) +def listenkeys(): + exitflag=False; + auto_release_mode=True; + switchstate=0x3F; + while not exitflag : + c=raw_input("\n Your switch action w/s/a/d/1/2 ?"); + #if(c== "w" or c=="a" or c=="s" or c=="d" or c=="1" or c=="2" or c=="q" or c=="h" or c== "W" or c=="A" or c=="S" or c=="D" or c=="Q" or c=="H"): + if(len(c) == 1 and c in "wWsSaAdDqQhHrRtT12"): + if(not c in "qQhHtTrR"): + + client_socket.send(chr(~keyvalue[c]&switchstate)) + time.sleep(0.1) + client_socket.send(chr(switchstate|keyvalue[c])); + # client_socket.send(chr(0xFF - keyvalue[c])) + # time.sleep(0.5) + print "\n", keymessage[c]; + time.sleep(0.5) + if (not auto_release_mode) and keyvalue[c]== 0xC0: + client_socket.send(chr(keyvalue[c])) + print "\n", keymessage[c]; + time.sleep(1) + if keyvalue[c]== 0x77: + print "\n ",helpstring ; + if keyvalue[c] == 0x88: + exitflag= True; + print "\n",keymessage[c]; + else: + exitflag = False + if(keyvalue[c]== 0x99): + auto_release_mode=not auto_release_mode; + print "\n auto release mode set to ", auto_release_mode; + else: + print("\ninvalid value"); + + +thr= Thread(target=listenkeys); +thr.start(); +while thr.isAlive(): + a=client_socket.recv(1000) + if(len(a) == 1): + client_socket.send(a) + time.sleep(0.1) client_socket.close() -server_socket.close() -print "Disconnected"