Python programming project. Control Logitech G510 LCD and show SteemIT stats

in #programming6 years ago

Hello guys.

I recently found a library for the Logitech Gaming Software for Python and created this:

photo5362096082001176921.jpg

You get it with the python package installer.
pip install GLCD_SDK
you can also find the files here

And there started the first problem:

I am using Python 3.5 and the library is written in python 2.7 i think. So with the package installer I got a few errors.
To fix this I have installed this library by hand and edited the setup.py to python 3.5 syntax.

Now we can start coding...

First of all we have to import some librarys:
import GLCD_SDK, time, urllib3, json

after the import we have to use a function from the GLCD library to specify the directory to the LogitechLcdEnginesWrapper.dll. You can download the gamepanelSDK here

To specify the directory we use this command: GLCD_SDK.initDLL("\\path\\LogitechLcdEnginesWrapper.dll")
After that we can use the command from the dll trough the GLCD_SDK. There is a documentary in the gamepanel SDK

The next step is to initialise our script:
GLCD_SDK.LogiLcdInit("Steem helper", GLCD_SDK.TYPE_MONO) The first parameter is the name shown in the Logitech Gaming Software. The second one describes the LCD type. The Logitech G510 only has a monochrome LCD.
After running this script it should look like this in the Logitech Gaming Software:
2018-04-14 15_03_25-Logitech Gaming Software.png

Now we want to get our steemit userdata trough their API. Simply add a .json after your url like this:
https://steemit.com/@flash4yard.json

The next codeblock creates a http request and downloads the .json data:

pm = urllib3.PoolManager()
acc_request = pm.request('GET', 'https://steemit.com/@flash4yard.json')
acc_json = json.loads(acc_request.data.decode('utf-8'))

This is copied code from stackoverflow. I do not know exactly what the "poolmanager" does. But it works^^
If you know what it does please tell me xD.

Now we got the .json in the acc_json variable. As the next step we want to extract the current voting power:

vp = acc_json["user"]["voting_power"]
The value in "vp" is a four digit number without a comma. To solve this we have to convert the integer to a string:
vp_string = str(vp)

This way we can read the variable like an array. Now we want to format the string as we like.
From 1234 to 12,34%

vp_mod = "%s,%s%%" % (vp_string[:2], vp_string[-2:])

There we add the comma and the percent sign to a new string.

In the last step we write to the LCD:

GLCD_SDK.LogiLcdMonoSetText(0, "User: @flash4yard") The "0" defines the line on the LCD. Counted from the top.
GLCD_SDK.LogiLcdMonoSetText(3, "Voting Power: %s" % vp_mod)
GLCD_SDK.LogiLcdUpdate() This applies the changes made the lines above

The result should look like this:
photo5362096082001176921.jpg

In addation you can add a while loop to get the new data every X seconds with the "time" library.
I did it and it updates every 5 minutes. Also I have added a few lines of code to assign the username and saving it in a text file. So the link to the .json changes to the set user name.

This variable have to be passed in the pm.request('GET',acc_url) command

In the future I am planning to add more information about your profile to be shown and something like a config were you can select which stats you want to show and which not.

I hope you liked this project

If you have any questions feel free to ask!

Have a nice day!

Sort:  

Well, today I learned there are keyboards out there with LCD screens attached! That is so cool :)

I also didn't know you could just add .json to your profile URL.

You taught me two things even without the code :D

Thanks. There are even keyboards with a color display like the Logitech G19 here is your link^^

Congratulations This post has been upvoted by SteemMakers. We are a community-based project that aims to support makers and DIYers on the blockchain in every way possible.

Join our Discord Channel to connect with us and nominate your own or somebody else's posts in our review channel.

Help us to reward you for making it ! Join our voting trail or delegate steem power to the community account.

Your post is also presented on the community website www.steemmakers.com where you can find other selected content.

If you like our work, please consider upvoting this comment to support the growth of our community. Thank you.

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 62860.75
ETH 3112.64
USDT 1.00
SBD 3.86