2012-12-28

Arcade Stick: Receiver


This post contains extra details on the receiver of my arcade stick.
PC receives and translates serial data from the controller using MATLAB and JAVA robot class.
I have programmed to operate my stick normally as an arcade stick, and also as a mouse.
In this post I will provide enough hints for anyone to use MATLAB for such purpose.


MATLAB Serial Communication Problem

I noticed many people including me were having problem with MATLAB's serial communication module.

DO THIS BEFORE ANYTHING ELSE!

The following code most likely will fix whatever problem you are having.
priorPorts = instrfind
delete(priorPorts)

MATLAB's serial communication apparently does not work well when there are any... 
(even the closed ports) 
previously declared ports.
The above code just finds and deletes the memory previously allocated for them.

Some useful MATLAB functions are:
serial
fopen
serial.BytesAvailable 
fread


JAVA Robot

first import the class for simplifications later on
import java.awt.Robot;
import java.awt.event.*;
import java.awt.event.KeyEvent;

make a robot class
robot = Robot;

have fun :D

key simulation:
if (sw1 ~= sw10)
if(sw1 == 1)
robot.keyPress(java.awt.event.KeyEvent.VK_H);
robot.delay(20);
else
robot.keyRelease(java.awt.event.KeyEvent.VK_H);
robot.delay(20);
end
sw10 = sw1;
end

The delay of 20 ms simulates how actual keyboard works. 
A keypress function must be released else it will be like a stuck key.

mouse simulation:
pos = get(0, 'PointerLocation');
x_pos = pos(1)+speed;
y_pos = 768-pos(2)+speed;
mouse.mouseMove(x_pos, y_pos);

Read pointer location and move the mouse. 
You can set sensitivity by changing the speed variable.
The first line is included such that you may use your real mouse as well as the joystick to simultaneously move the mouse cursor.



By Joe Kwuen

No comments:

Post a Comment