Monday, May 1, 2017

Still Here

Been busy with a lot, but I will be posting more soon. Maybe even this weekend if I get around to it. See you then.

Saturday, December 31, 2016

Making a Custom PC Gamepad with Arduino



What: Making a simple gamepad from an Arduino that you can use on the computer

Why: I wrote another article earlier this year about using the RXTX java library involving basic communication with a computer and finally got a free weekend to make an even better project using that same tech. Furthermore, a Twitch streamer by the handle 'Rudeism' has become well known for using a 'Makey Makey' microcontroller in video games, and it should be noted that he inspired me to finally get working on my own fun game controller.

Required: 
- Arduino, Arduino IDE
- Switches, buttons, and/or joysticks
- Computer
- Java
- RXTX Java Library
- Code available on my Github

Notes: For this tutorial, I am using an old analog computer joystick. It used a gameport adapter, but I have since cut it off so I can get at the wires directly. The important take away is that I have wired the outputs from the potentiometers of the joystick directly into the analog input pins of the Arduino. Further, the buttons from the joystick are also wired directly into the digital input pins. The program files available for this tutorial assume only two axes and two buttons. If you want to make a more complicated gamepad, I encourage you to do so; the concept is the same. 

I am using an Arduino Uno R3. The Uno does not have native HID support which is why we need the Java program on the computer. The joystick I am using an old InterAct Raider Pro Digital that I found while thrifting. This tutorial does not require flashing the Uno’s core firmware.

Brief: The basic idea is that the Arduino will receive the inputs (either digital or analog) from a button or joystick you have and send it over the serial connection to your PC. The PC will then parse that input into something actionable. Using the Java ‘Robot’ class, your Java application will move the mouse, click a button, or enter a keystroke. Here is an abstract diagram for how it should work:



Steps:

1. Connect your switches, buttons, and potentiometers to the Arduino


[x-axis potentiometer signal] -> [analogPin0]
[y-axis potentiometer signal] -> [analogPin1]
[trigger button] -> [digitalPin3]
[thumb button] -> [digitalPin4]
[GND] -> [GND]
[5v] -> [5v]

2. Upload the Arduino sketch
     View my sketch example video HERE.

3. Run the Java application
     That's it! Your potentiometer inputs now drive your mouse, the trigger button is a left click, and the thumb button is a right click.

Troubleshooting:

-If you need more help with the RXTX library specifically, please refer to my previous article on using the library HERE.

-If you have questions about the process or this project in particular, post a comment and I'll try to help you out.

More process photos:
(Testing direct connections)

(Connections soldered and labeled)

(Ready for game testing)

Making Humanistic Mouse Clicks with Java Robot Class

Preface: Java's Robot class allows you to send mouse and keyboard signals to the operating system through APIs designed for indirect interaction with the PC. By using this Java class, we can perform actions like scrolling, clicking, and typing without actually doing so.

Problem: While experimenting with the Robot class for an Arduino gamepad I was making, I discovered a problem with clicking the virtual mouse. Let's look at the code.

This is how it is explained in Java examples, and how other users have taken to using the mouse click:
Robot robot = new Robot();
    
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
The button is pressed and immediately released. Even adding a delay by way of a Thread.Sleep will still result in the same problem. What if I have a function that detects an event and presses the mouse button? This certainly works for that case, but what if I am holding the mouse button down? Instead, this code will simulate a set of rapid clicks for as long as the button is held. That's not the behavior I wanted. Furthermore, the right click code was verbatim with the mask changed to account for the different button. Right clicking did not work at all since it opened and close any context menus far too fast to be useable.

Solution: Using some extra state information, we can track whether or not the mouse button should be held down, or if it should be released. Assuming the event triggers occur often enough, the user should not notice whether the mouse is only clicked or held for any period of time.

int currentLeftClickState = 0;
...
if(trigger == 0 && currentLeftClickState == 1){
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
this.currentLeftClickState = 0;
}
else if(trigger == 1 && currentLeftClickState == 0){
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
this.currentLeftClickState = 1;
}
In my example, I declare a simple flag using an int that will represent the current state.  When I receive the literal 'trigger' my function code will validate the trigger against the current state. Only if there is a difference between them, do we need to change the mouse behavior.

This code allows you to now select windows, drag objects, open context menus correctly, and even select multiple lines. Cool stuff right?

To see the project this code was written for, please check out my GITHUB.

Saturday, December 17, 2016

The Costs of Developing Games

I've been working on a simulator/game, and decided to investigate how much it would actually cost to deploy to as many platforms as possible. The platforms I investigated were the following: Xbox One, PS4, Wii U, and iPhone. My simulator wouldn't actually be appropriate for the iPhone given the system constraints and minimal points of interaction available to the user, but I included it for completeness. The areas I have considered in my investigation are the following: development kit, developer registration, listing fees, patch fees, and perks.

You'll find that most of the tangible costs, like price of dev kits and registration, are actually undisclosed, but we can guess at these costs based on user testimonials from various threads and online forums. Where applicable, I have posted links to any sources, though due to the limited lifetime of forum threads, forum links are not provided.

Xbox One / UWP
The costs of developing for the Xbox are a little more complicated since Microsoft has been pushing a unified platform dubbed "UWP." This means that the costs for developing a game on Windows are very similar to that of a game on Xbox, but the development kit costs change. If you are developing for Windows, you need a Windows computer. If you are developing for the Xbox, you'll need an Xbox. Here is a breakdown of the costs I was able to source:

  1. Development Kit : Xbox One console = $250.00
  2. Developer Registration: One time fee  = $19.00
  3. Listing Fee:                                           = $Estimated at 'couple hundred'
  4. Patch Fees:                                            = Free as of 2013
  5. Perks:                                                     = Two free development kits (Qualified independent developers)
The listing fee probably varies based on the studio budget, but if we estimate 'couple hundred' to have a ceiling of $200 dollars, the total cost of developing a game for the Xbox One is $469.00. This doesn't account for multiple development kits, but if you are a qualified independent developer, the price could be as low as $219.00 since you would get the kits for free.

Playstation 4 
Most of the price for developing on the PS4 is going to come from the development kit since you cannot currently turn any PS4 unit into a dev system like you can with the Xbox One. Let's take a look at the breakdown.
  1. Development Kit: PS4 Dev Console               = $2,500.00
  2. Developer Registration: Online Registration   = Free
  3. Listing Fee:                                                      = Unknown
  4. Patch Fees:                                                       = $10,000.00
  5. Perks:                                                                = First two patches are free. Free ESRB ratings
Right off the bat, we see that the cost of the development kit is already $2000.00 more than the Xbox One. Unfortunately, I could not find any information on the listing fee for selling your game through their online marketplace, but based on the other numbers, it is likely to be relatively expensive. Given the numbers I could find, I am going to conclude that the total cost of developing a game for the PS4 is probably about $2,500.00 to $3,000.00. However, if you are indie developer, you may be in luck. I found multiple accounts of forum users claiming that Sony was generously lending indie developers a free PS4 dev kit for the first year.

Wii U
Nintendo's next console is actually the Switch, but since it is still very new, there was not much information I could find on the price of developing for that system. Instead I will look at the Wii U where more information on development costs was available.
  1. Development Kit: Refurbished = $1,500.00
  2. Developer Registration:            = Unknown
  3. Listing Fee                                = Unknown
  4. Patch Fees:                                = Free
  5. Perks:                                         = Unity Pro License
Unfortunately, there are quite a few unknowns when looking at developing for the Wii U, but the development kit costs were probably the easiest to find compared to the other systems. If you are not buying a refurbished kit, the price rises another 1,000.00. Overall, if we assume that the registration and listing fees are free, the total cost of developing a game for the Wii U is about $1,500.00.00 with zero patching fees.

iPhone
The iOS platform is a very different system than the other platforms since the gaming system is essentially a hand held device. With the physical limitations comes limited hardware capabilities. None the less, let's look at the numbers I was able to source for developing a game on iOS:
  1. Development Kit: iPad/ iPhone = $200.00 - $600.00
  2. Developer Registration:             = Free
  3. Listing Fee                                 = $100.00 /Year
  4. Patch Fees:                                 = Free
  5. Perks:                                         = External test users (up to 200)
Developing for the iPhone or iPad seems to carry the lowest cost, but it is also the only platform that I could identify as having a recurring cost. The listing fee for applications and games is written as $99/yr, but it was unclear if the developer was responsible for paying the annual price after original game/application submission. Even with the recurring fee, developing for iOS appears to carry the lowest cost and the total cost of developing a game for the iPhone is about $300.00 if you are using a cheaper iOS device.

Hopefully you found this as informative and interesting as I did, and that it helps fellow developers make informed decisions about the platforms they choose. For my simulator, I will likely develop for the Windows platform first, and then expand if it makes sense. 

If you have more recent information on the costs associated with developing a game for various platforms, please contact me, and I would be happy to update the information provided above.

Monday, December 12, 2016

Remapping the Special Macro Keys on an Asus Laptop (G752)


This was one of those really good puzzles that almost didn't pay off. Asus has a preinstalled macro key application for mapping the macro keys on their laptops, but as you have probably discovered, it only works for a subset of the keys, not all of them. Asus conveniently left the Stream/Record/Camera macro key out in an attempt to prevent you from changing it. The key looks like this:
(The key on the far left with the camera symbol)

I am using a G752VS, and by default, that key is bound to an application called XSplit. XSplit is great, but I favor OBS and wanted to remap the record macro key to OBS instead of XSplit. I searched plenty of Asus forums where users had found out how to remap the Steam or Shadowplay macros on older laptops, but no one had figured out how to remap the Record macro yet. Bummer for me, but I was determined so I set off to figure this out. Surely there had to be a way to change it. 

You've probably looked around and seen plenty of 3rd party programs that individuals have written, and though I am sure they do the job well, I didn't want such a heavy solution to the problem. The two that I considered work by intercepting the key event and redirecting it. This is a great work-around, but I wanted to deal with the root cause, and not just the symptom. (BTW, if you call Asus Support, they'll tell you it cannot be changed)

Thanks to 'RARES95' in this thread I used the HControl.exe binary as my starting point. Just as they did, I examined it in a hex editor to see what sort of clues I could dig up:


I did a search for 'XSplit' and found only a single instance of the string. Here is a more focused image of just the interesting stuff:

(XSplit.ControlMessage.XGC)

Surprisingly, the XSplit clue I was looking for was right next to the old 'Steam/Shadowplay' strings. Unfortunately, this time around the engineers didn't just place the application path into the executable which would have made remapping the key very similar to the Steam macro trick posted in the forum. I wrote down the surrounding clues, pretty much everything I highlighted, and went looking, starting with the registry. I do most of my work on Linux, and have very little technical prowess on the Windows platform, but I had a good feeling the registry editor might be a good place to start looking for more clues. 

Turns out I was wrong. One of the strings I wrote down was 'InstallPath', which as it happens, is actually a registry key under the SplitMediaLabs/XSplit registry group. The value was the launch executable for 'XSplit' so I changed it to point to my test application and restarted explorer. Didn't work, hitting the record macro key still opened XSplit. So I changed that back. Next I spent a few minutes Googling for the string 'XSplit.ControlMessage.XGC.' Nothing. Seems like it had to be something internal to the Asus application, not something you would find on the web. Then I started doing the equivalent of 'grepping' through every file related to the ATK package (Asus' macro key management software) and the XSplit program files. That string wasn't there, but I got a metric ton of results for things like 'XSplit' or 'ControlMessage' or especially the 'XGC', just not in the same string like I found in the hex editor. I was getting nowhere.

Just when I was about to give up, I looked again at some of the less obvious clues I had originally overlooked:
(schtasks & ATK Package)

Then I looked up ATK Package A22126881260 and found an XML file under the Asus ATK Package directory in program files. The XML file didn't give anything away though. It mentions an executable which is used for simulating apps run in the Windows' store, but it's a red herring. 


Like I previously stated, I am a not a Windows guru, but if I was, 'schtasks' probably would have stood out more to me earlier. I looked it up and it's actually a Windows cli tool for scheduling tasks or running programs; essentially a cron. So I opened the Windows' Task Scheduler program and looked through the list. Lo and behold, there it was:

(ATK Package A22126881260)

If you click the 'Actions' tab, you'll see this scheduled task makes a call to C:\Program Files\SplitMediaLabs\XSplit\...XSplit.Gamecaster. Found it! 

Since you've come this far, I'll make the last part short for you. If you edit this scheduled task, you can replace the action of calling XSplit with any other script of program you want. Once you've edited the task, close Task Scheduler and press the Stream/Camera/Recorder macro key. It doesn't open XSplit anymore does it? Congrats, your computer belongs to you again.

This was fun wasn't it?
Thanks for reading!

Update: I made a Youtube video on how to do this since that might be easier than a wall of text. Enjoy!


Saturday, December 10, 2016

Long Term Test Result Analysis with TUSK

This is Tusk. Tusk was made to remember your test result and do analysis for you.

I came up with Tusk to solve a problem frequently associated with testing. Automation allows us to generate testing results more quickly, but more often we are looking at the one off results and discarding the historical data. What about that test that seems to fail every other week? It may have been mentioned between coworkers, but no one really knows its failure pattern, how it coordinates to product versions, etc. Tusk was designed to parse test results, store them in a database, and perform analysis on the database while improving debugging and testing workflow.


(Tusk Rest API)

I've since been drawn away, interested to work on other projects, but I did make enough progress that it is very close to a minimum viable product and can be functionally tested. Further, Tusk is a really good example of JSON serialization/deserialization using Go/Golang. Check it out at my GitHub.


Keeping Track of Skill Practice Hours (A JSON, JAVA Project)


I've been wanting to write program that allowed me to keep track of my practice hours for various computer related skills. Some years ago, I read a book by Malcom Gladwell that examined experts of various fields from athletics to music. Each of these experts had practiced their craft for at least an estimated10,000 hours. Eventually, I will surely reach this number with crafts like programming, but it would be hard to say when if I wasn't actually keeping track. So I wrote an interactive program to do just that.

I called it 'Keeper', and it's freely available to download on my GitHub if you want to check it out. 

How it Works: Keeper uses what I called 'trackers' to record events for specified skills. In the source, you'll notice that I used mostly computer languages as the skills you could track. This is a limitation of the example code, but in practice, you would not be limited to the number of trackable skills currently available. Once you've entered data, you could perform analysis and get the following data:
  1. What year did I practice X the most/least
  2. What time of day did I practice X the most/least
  3. Which skill did I practice the most/least
  4. etc
I really enjoyed this project, but when I showed it to a friend, they asked why I wouldn't just use Excel to do the same thing. I didn't have a good answer, so I have since switched over to using Excel. The project still serves as a couple good examples of using JSON to serialize, deserialize data.