Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Automatic layout rotation with USB sensor  (Read 2878 times)

0 Members and 1 Guest are viewing this topic.

Stormrider

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 318
  • Last login:September 28, 2014, 11:01:54 am
Automatic layout rotation with USB sensor
« on: October 10, 2009, 03:56:07 am »
Thumbnails




Enlarge images:
http://www.alvarezeninternet.com/adesktop/sensor1.jpg
http://www.alvarezeninternet.com/adesktop/sensor2.jpg


This project involves both hardware and software. The goal is that MaLa is automatically set up before it starts according to the actual orientation of your TVset or monitor. The way to achieve this is a little crazy (and possibly stupid), but it's easy, cheap and it works flawlessly.

Let us start with the software. The included file sensor.exe must be run before MaLa. If yout frontend is replacing userinit.exe (read the chapter named LOAD ON START), you can add it to the same line, separated by a comma: d:\mala\sensor.exe,d:\mala\mala.exe You may have to edit the .ahk file (scripts source folder) and recompile to fit your folder settings. The script code perform this simple task: check if any of the drives in the computer has the label named SENSOR. If so, it modifies mala.ini setting the value of vertical= and flip= to 1. Otherwise, the setting will be 0.

Hardware. You need a pendrive (the cheapest you can find). Plug it to a USB extension cable (a decent cable with shielding). Make a longitudinal cut near the female end and extract the red wire (power). Cut it. Lengthen each end using two cables. Now, buy a mercury switch and solder its pins to the red cables. Fit the switch inside a little box with the appropriate inclination (tests are necessary). So, when the box is in horizontal position, the circuit is opened and the pendrive is off. When the box is vertical, the mercury inside the switch falls, closes the circuit and the pendrive is powered on. Fit the pendrive and some cable inside the box, and attach it to the top of your monitor. You can see a photo of the result here: http://www.alvarezeninternet.com/arcadedesktop/sensor.jpg)

Voila! Now we have a digital tilt sensor acting as a switch with a pendrive, which works as a variable for a script that tells MaLa whether the monitor is in vertical or horizontal position. You will never have to manually rotate your layout again.

Possible improvements: make the script load even before the Windows boot screen, so that it can also set the orientation of this image. However, as far as I know, it is impossible to run the program at that point. Anyway, I already have the rotary boot screen script which reads MaLa orientation on exit and sets the boot screen to the next time you restart you system. It is the only solution.

As usually, the binary files and all you need is included in the zip file of my Low Res Mala Layout: http://www.alvarezeninternet.com/malalayout/

This is the code:

#NoTrayIcon
Drives=DEFGHIJKLMNOPQRSTUVWXYZ
Loop, Parse, Drives
{
  DriveGet, Var, Label, % A_LoopField ":"
  res .= Var "`n"
}
if res contains SENSOR
{
IniWrite, 1, d:\mala\mala.ini, GUI, vertical
IniWrite, 1, d:\mala\mala.ini, GUI, flip
}
else
{
IniWrite, 0, d:\mala\mala.ini, GUI, vertical
IniWrite, 0, d:\mala\mala.ini, GUI, flip
}
exitapp
« Last Edit: October 10, 2009, 10:55:39 am by Stormrider »

SGT

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1146
  • Last login:May 31, 2025, 10:10:32 pm
Re: Automatic layout rotation with USB sensor
« Reply #1 on: October 10, 2009, 08:17:43 pm »
Very nice work, Stormrider!   :applaud: :notworthy:

Stormrider

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 318
  • Last login:September 28, 2014, 11:01:54 am
Re: Automatic layout rotation with USB sensor
« Reply #2 on: October 11, 2009, 03:00:19 am »
I've made in improvement over the previous script for cases in which the user decides to rotate the screen once MaLa is already running. After the initial check and modification before MaLa is launched, the code watches the drives every few seconds. If the pendrive is plugged into the computer or removed, the script sends the INSERT keystroke to rotate the layout and modify the ini.
« Last Edit: October 11, 2009, 01:25:27 pm by Stormrider »

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5158
  • Last login:May 24, 2025, 09:57:44 pm
  • Wheres my coffee?
    • Skenny's Outpost
Re: Automatic layout rotation with USB sensor
« Reply #3 on: October 11, 2009, 04:14:04 pm »
Sweet!!!!!!!!!

Howard_Casto

  • Idiot Police
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19427
  • Last login:Today at 02:45:49 am
  • Your Post's Soul is MINE!!! .......Again??
    • The Dragon King
Re: Automatic layout rotation with USB sensor
« Reply #4 on: October 12, 2009, 06:00:16 am »
Nice idea, but lets simplify the hardware to something less rube-goldberg shall we?

Ditch all the usb stuff, all of it.  Keep the mercury switch, that's a good idea.  Wire it directly to a spare input on either your ipac/keywhiz/ect or a junked joystick.  Exact same concept but now we check to see if that key is pressed instead of ruining a perfectly good pendrive.  Also using a pendrive is a bad idea because the mounting/unmounting of a drive is a resource hog in windows.

SGT

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1146
  • Last login:May 31, 2025, 10:10:32 pm
Re: Automatic layout rotation with USB sensor
« Reply #5 on: October 12, 2009, 01:50:22 pm »
Nice idea, but lets simplify the hardware to something less rube-goldberg shall we?

Ditch all the usb stuff, all of it.  Keep the mercury switch, that's a good idea.  Wire it directly to a spare input on either your ipac/keywhiz/ect or a junked joystick.  Exact same concept but now we check to see if that key is pressed instead of ruining a perfectly good pendrive.  Also using a pendrive is a bad idea because the mounting/unmounting of a drive is a resource hog in windows.


Ruining a perfectly good pen drive?  There's a gazillion of old ones out there no longer being used because of limited capacity.  Resource hog?  With the capacities of today's computers it has ZERO impact on performance.  Rube Goldberg?  It wasn't that complex.   Personally I don't want a key/input staying down in the "pressed" position until the monitor is rotated to the other position, but that's just me.


Stormrider:
Have you seen DaOld Man's utility for monitoring the rotation via the parallel port?:
http://forum.arcadecontrols.com/index.php?topic=97107.0
« Last Edit: October 12, 2009, 02:07:08 pm by SGT »

u_rebelscum

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 3633
  • Last login:April 21, 2010, 03:06:26 pm
  • You rebel scum
    • Mame:Analog+
Re: Automatic layout rotation with USB sensor
« Reply #6 on: October 12, 2009, 02:48:23 pm »
Total overkill, but ... U-HID-G.  Just in case you turn the monitor face up or face down, you know. ;)
Robin
Knowledge is Power

Howard_Casto

  • Idiot Police
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19427
  • Last login:Today at 02:45:49 am
  • Your Post's Soul is MINE!!! .......Again??
    • The Dragon King
Re: Automatic layout rotation with USB sensor
« Reply #7 on: October 13, 2009, 01:58:36 am »
Nice idea, but lets simplify the hardware to something less rube-goldberg shall we?

Ditch all the usb stuff, all of it.  Keep the mercury switch, that's a good idea.  Wire it directly to a spare input on either your ipac/keywhiz/ect or a junked joystick.  Exact same concept but now we check to see if that key is pressed instead of ruining a perfectly good pendrive.  Also using a pendrive is a bad idea because the mounting/unmounting of a drive is a resource hog in windows.


Ruining a perfectly good pen drive?  There's a gazillion of old ones out there no longer being used because of limited capacity.  Resource hog?  With the capacities of today's computers it has ZERO impact on performance.  Rube Goldberg?  It wasn't that complex.   Personally I don't want a key/input staying down in the "pressed" position until the monitor is rotated to the other position, but that's just me.


Stormrider:
Have you seen DaOld Man's utility for monitoring the rotation via the parallel port?:
http://forum.arcadecontrols.com/index.php?topic=97107.0

Even the smallest of pen drives can be useful.  There newest use of them is that you can get a very inexpensive bluray player and upgrade it to bluray live by adding a usb drive.  Also upgrading firmware on televisions and other newer appliances often require a drive with special formatting. Older usb drives are perfect for this.  Your dead wrong on the second point.  Because of the way usb and harddrive mounting works in windows, explorer literally "locks up" while the drive is mounted.  Now it might be a split second, but you don't want to put that kind of strain on your machine when you don't need to.  Also if you have multiple usb hubs the stacks sometimes get confused.  In theory you are supposed to easily plug/unplug usb devices multiple times on the fly, but in practice it freaks windows the hell out, particularly when mounting drives.  If you aren't having problems with this method then consider yourself lucky.   You can hook a mercury switch up to ANY sort of input, I mentioned a usb joystick, which wouldn't require a key to be held down and has zero impact on anything. (Usb input methods are passive, they have to be actively polled to get status.)  There are other, methods in which a "real" input wouldn't be used, but you seemed to want to keep costs down so I didn't mention them.  No it isn't rube goldberg in the respect that you are using too MUCH hardware, it's rube goldberg in the fact that you are using improper hardware when a more direct method is available.  There's absolutely no reason to get defensive.  I'm just trying to make this thing practical to everyone and not just your particular setup. 


(Sigh) This is why I don't visit the boards anymore.  I see somebody posting something with promise and I add to it to improve the design and I get flamed for daring to question their "infinate wisdom".  Don't worry, I won't chime in again.

SGT

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1146
  • Last login:May 31, 2025, 10:10:32 pm
Re: Automatic layout rotation with USB sensor
« Reply #8 on: October 13, 2009, 10:33:51 am »
(Sigh) This is why I don't visit the boards anymore.  I see somebody posting something with promise and I add to it to improve the design and I get flamed for daring to question their "infinate wisdom".  Don't worry, I won't chime in again.

I was debating your points as I don't agree with them.  Never dreamed you would take disagreement as a flame.  If you think I flamed you, what did you do to the OP by calling his project rube-goldberg like and sarcastically saying he had "infinite wisdom"?   You could have offered suggestions without being condescending.

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5158
  • Last login:May 24, 2025, 09:57:44 pm
  • Wheres my coffee?
    • Skenny's Outpost
Re: Automatic layout rotation with USB sensor
« Reply #9 on: October 13, 2009, 09:02:59 pm »
I like Stormriders idea. it is extremely simple, and most newbie arcaders (is "arcaders" a word, or am i trying to start a new one?) lack the experience to get into a lot of electronics on their first project.
Simple is always better, I think. (As long as it works, that is.)

Stormrider

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 318
  • Last login:September 28, 2014, 11:01:54 am
Re: Automatic layout rotation with USB sensor
« Reply #10 on: October 14, 2009, 06:05:23 am »
First I must say that the USB extension cable itself was more expensive than the pendrive (7 €). Actually, I told a friend: give me your 256 mb pendrive and I'll give you a 2 gb new one, but finally I didn't do so, because the case of my pendrive was really small and fitted perfectly inside the black box and I didn't have the chance to pay a visit to him.

I knew this was a farfetched solution. I knew I could have come here and ask about how to do it or spend days and days in google looking for the best idea, and find solutions such as the MALA-ORI or the U-HID G, but I wanted to do it myself, and not to have to order any piece of rare hardware. I also disliked the idea of using parallel or serial ports because I think new computers no longer will have them. Also, I wanted to do this without any special knowledge of electronics nor even programming (scripting with Autohotkey is quite easy and anyone can learn). The idea of using a usb gamepad or something like that also was considered initially, but I didn't want something sending input all the time, an extra device and problems with MAME controls. I found a solution with the pendrive which was cheap and easy to be made for anyone and that could work, and actually, it works.

RyoriNoTetsujin

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 545
  • Last login:March 23, 2024, 03:55:45 pm
Re: Automatic layout rotation with USB sensor
« Reply #11 on: October 14, 2009, 02:19:19 pm »
Here I was going to welcome Howard back to the forums (despite my post count, I've been here for many, many years) and now he's gone again.  The more things change...  ;D

Anyway, I like the idea and I like the implementation.  You do with what you have.  Nice work.


raph

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 73
  • Last login:May 25, 2024, 03:21:37 am
  • Gradually adding bells and whistles to a stock cab
Re: Automatic layout rotation with USB sensor
« Reply #12 on: August 19, 2015, 02:32:10 am »
I know this post is quite old, but I wanted to report on my experience building one of these.

My current set up recently gained a manual rotation monitor, and after painstakingly making vertical versions of all my layouts I realized that I'd never see them if only the emulator were ever rotated. So I went looking for a solution and found this post.

My first try used a tilt switch from Fry's, a non-mercury one (the sort with the rolling ball). This turned out to be highly erratic and it seems like sometimes the ball would outright get stuck in there. It was tiny; it has one nail-like post and one extremely thin wire. Soldering something this small was a huge pain given my limited skills, and there was very little clearance between the two wires. On top of that, I ruined one cable somehow while trying to make it work. As in, it started giving me BSOD's in Windows 10 to even try using it.

I started over with a tilt switch intended for automotive use -- I got it at Best Buy, but I am sure there are plenty of sources. It had two nice sturdy wires emerging from a plastic enclosure. The tilt ball was audible when I moved it manually. With a fresh USB cable (a thinner one, this time, it turned out), I was able to do the soldering with no issues.

BUT... Howard Casto's warning about the weight of mounting USBs seems to be valid. The script in Stormrider's package is very nice, but it uses a 20 second check interval on the tilt sensor. I tried speeding it up, and it could result in Mala getting stuck with several flip keystrokes enqueued, which can crash the frontend entirely. I altered the settings in Mala to have separate keys for rotation 0 and 90, and changed the script to send the appropriate one for the rotation, and this was better. But still, rapid changes in the sensor's state while the USB drive is mounting can result in the entire USB port simply going offline, forcing you to unplug the sensor and move it to another port. After a while, the port seems to "wake back up."

So... it works, and I don't want to minimize the great work that Stormrider did. But don't abuse it, I suppose is what i would say. Be conservative about how often you rotate it.

In my case, it was basically a nice experiment that prodded me towards taking the plunge for an automated rotating monitor. :)