📜 ⬆️ ⬇️

Automatic image rotation on the monitor

Historically, I don't have a monitor. I use TV instead. Thirty two inch TV. And no, I have not yet oskoglazil. It works quite comfortably behind it, replacing 2 monitors at once. But he has one unpleasant feature. When I open my favorite editor, the code is a narrow column on the left side of the screen. Almost two thirds of the screen remain empty and unused.



I put up with it for a long time, until I remembered vertical monitors. Why not? How am I worse? That's when I decided to retool my workplace a little. It would be possible to make fasteners and permanently place the monitor in a vertical position, but this did not suit me because I often watch movies on my “monitor”. And vertical films, thank God, are not yet filmed. At this point, the idea to purchase a swivel bracket and hang the TV on the wall, to turn it if necessary. That's exactly what I did.


That's better, isn't it?
')
Life has become much more convenient. Need to work? He got up from the chair, turned the monitor, sat back, entered the command in the terminal
xrandr -o left and work yourself comfortably. Want to see a movie? Do the same, just xrandr -o normal already xrandr -o normal and relax.

All this suited me completely, until I was just tired. Tired of typing these commands. Get up and turn this colossus, I, too, really tired, but do not attach a motor to it, right? But I could automate the input commands at no extra cost. But how to explain to the computer that the monitor has been turned over? It would be possible to be confused, like, for example, this guy , but this is no use to anyone. As an interface, I immediately decided to use a serial port (if there is no embedded one, you can buy an usb-to-serial adapter). But what about the sensor? And here it is even easier. I found a tube of lipstick that no one needed, pulled a metal ball out of a bearing and made it:



A tube, on one side of which 2 pins are placed, connected to the TxD and RxD pins of the serial port.



Inside the tube rolls a metal ball. If it rolls to the contacts, it closes them, thereby connecting the pins of transmission and reception of the serial port. The tube is hung behind the “monitor” at an angle of 45 degrees so that when horizontal the ball is in the non-contact end of the tube, and when the monitor is placed in the vertical mode, the ball rolls down and closes the contacts.

It remains to write the software part. The principle of operation is very simple: the word is written to the serial port and immediately read. If the program has read anything, then the contacts are closed, which means the monitor is in a vertical position. As a result, the command xrandr -o left is executed. When you turn back to the horizontal position, a similar action takes place, but with the xrandr -o normal command.

The first time I wrote a script on my favorite python. It was a two-line monster that, according to top , guzzled 120% of the CPU. Why it happened so for me is still a mystery. In the end I decided to rewrite the C program, which helped not to load the processor so much.

That's basically it. It remains only to add the program to autoload.

I decided to share this little life hacking with the habrosobschestvom. Suddenly someone come in handy.

The code can be found on the githaba .

Please send information about grammatical and punctual errors to personal messages in order not to clutter up comments.

UPD:
And this is how it looks in life (I apologize for the quality):


Source: https://habr.com/ru/post/137650/


All Articles