Using Pixelblaze for game immersion by watching and reacting to a Journal File

Hi, brand new here. Didn’t see a “noob” or “intros” category so here I go.

Just got a PBV3 installed, in a ceiling medallion that’s spaced away from the ceiling slightly (will be a ceiling fan in the center, just awaiting the longer downrod needed to make the install all fit and wireable). Will upload a pic later when it’s all installed.

Lighting itself is fairly simple, segments of 12 LEDs (2812, edge lit type) centered on each edge…starting to wish I went continuous but as the LEDs, PB, and transformer (Class 2, wired to a 120VAC plug in a ceiling box alongside the actual ‘fan mount’ box) will require total removal of the ceiling fan to re-access, figured I’d be very overcautious with load and demand. So I have 8 ‘segments’ that don’t make up a contiguous octagon, given the medallion shape.

I’ve figured out the basics so far of creating my Pixel Map for my layout (used Excel to generate XY values for one linear edge, then did rotational transform for the other sides, and re-sorted in the right order starting from the right first pixel location), and am SLOWLY playing with existing patterns to do 2D mapping.

My long term goal is to make this lighting improve immersion of computer gaming, mainly (today) in Elite Dangerous: Odyssey. Right under this medallion is my simpit seat project. Not sure if as a total noob I can post pictures but:

In Elite, as you play there’s a “Journal” file that gets written do with events as they occur - entering supercruise, leaving it, jumping to another star, fuel scooping, etc. What I’m hoping to be able to do is create patterns that ‘match’ the behaviors (e.g. something like the “Sun Rays Thru Trees” I see on your patterns page would make sense while I was right next to a star, scooping hydrogen). Simple dim starlight twinkle when out in the black, or blaring red alarm rays rotating around when under attack.

This isn’t the same as ambilight queries - the Journal file exists, and I know can get read during play (there are helper apps for the game that generate side screen supplemental info and such). I’m hoping your Websocket API is the ticket for what I want to do, just need to I guess code up something that pings the Journal and lets me send the associated pattern of my choice.

Anyway, lots of blather I know with zero actual content to show or tell about - yet. Any advice based on what I’ve yammered about so far, I’m open. I confess to barely being able to do basic Arduino type coding for the most part, maybe a little batch or Powershell, but that’s about it.

2 Likes

Hi @rtrski!

Looks really cool!

You’ll be able to do what you want with the Websocket API.

See:

{
"activeProgramId": "<id>"
}

If you’d like a reference implementation that includes listing patterns and launching them, see the JS/Node/React Firestorm or the Python Pixelblaze Client.

Thanks, found those already. Still diving into patterns, but after that. Not sure of lowest-tech way to connect…seems like the PB client example “simpleruntimecontrol.py” can just be run in Python to pass commands, so maybe a custom py script to parse the last line of the journal every second or so that executes an associated pattern command if appropriate matching string found, which i just run with a quick batch shortcut along with launching the game so it stays running in background? Would want to be sure to protect against unneeded updates, eg only if the journal entry is new vs current clocktime. Also need to make sure the script doesnt try to grab foreground focus in windows…

I see no need to go as far as compiled executables or anything. Almost wonder if Task Scheduler can be hacked up to create tasks and execute one-off pattern .py files based on a text file value…lots of options is my initial barrier.

thats a really cool setup you’ve got there! i wish i had the time or focus to really build out my desk the way i’d like it to be. but life keeps getting in the way!

id say what you want to do is completely achievable and while i have no knowledge of windows development my software development experience would suggest a few things.

decompose the problem into smaller chunks and work on them separately. the easy one would be a script to update PB with a specific pattern code. that should be easy to manually run and verify.

the more tricky chunk would be extracting updates from the journal. im not sure if i would approach it by doing regular checks (polling) because the granularity can be hard to get right especially if the tempo of the game varies from laidback to a lot of updates happening at once and also depending on how you’re accessing the file, it could conceivably be in the middle of a write and you get incomplete string fragments.

you’d prob want to dig around the windows api and find something that can notify you when a file is modified, and then you can trigger the update on each modification.

additionally you didnt mention what kind of format the journal data is in… is it just simple line by line, does it have additional data such as timestamps or is it in a JSON format, (or xml ugh) etc… all those things could factor in how you approach this.

certainly could break this down into more bite-sized chunks of work but thats how i’d start, at least.

Thanks. Think I’ve found existing opensource project code for accessing the Journal and even tagging events of interest. It’s JSON.

This is actually a reasonably easy programming task. The elite journal file is a really well documented JSON file, used by all kinds of 3rd party addons for the game. Python has good JSON support, and will run nicely as a standalone script in a cmd window.

So, if I wanted something running quickly, I’d:

  • write a Python program that periodically, say a couple of times a second, checked the journal to see if it had changed. (From Python, you can use os.path.getmtime(path) to get the time the file was last modified modified.)
  • if the file changed, read the last line and see if it’s something you’re interested in.
  • if it is, send the pattern change command to your Pixelblaze, and go back to the poll/sleep cycle 'till the next journal entry arrives.

The most time consuming part of this is likely going to be writing cool patterns for all the events you want to look at. Endless fun!

(I suppose you could use Task Scheduler, but a single Python program will be easier to wrangle, particularly in the development phase, when you’ll be changing it constantly. )

1 Like

More simply, you could make sure you never miss a line with something like this to “tail” the file:

2 Likes

Nice, @sorceror!

The other thing I’d do – pretty much what I always do when writing game addons – is go look at the source code for a couple of popular addons and see how they handle the incoming data stream. There are bound to be conventions and tricks and traps that aren’t completely documented. It can save you a lot of time and effort.

1 Like

Appreciate all the suggestions to get me there.

The physical part of the project is now in place. Medallion with PixelBlaze, 5V transformer, and LEDs. Ceiling fan. Small necessary decor decals…because I’m a sci fi geek.

Imagine a vid is too much to upload directly so here’s a OneDrive link, not ready to try exposing myself (hah) on YouTube or anything yet.

https://1drv.ms/v/s!AuHD2NL7qn3wgfUp2ExBkKOCGvQx9A?e=Y8etJm

Got my mapping set up too, used Excel and basic trig to layout the pattern, paying attention to my starting point between the ‘North’ and ‘Northwest’ edge sections.

I’ve already figured out, by just playing with a straight-line ‘passing’ the map from front to back, that I’m going to be better off with more graded and persistence patterns…the ‘front’ and ‘back’ edges parallel to the line I had passing thru just ‘flash’ once kind of unappealingly due to the gaps in my pattern. So more of a general lightfield with wider ‘waves’ of either different color or breathing will I think appear more continuous. Much to learn!!

Expect I’ll be a very slow roll on the programming, between other project backlogs (and actually wanting to play!) now that the installation is in place. (I had to use scaffolding to install the medallion and fan since this seat project is at this point…not very movable without a lot of cable-unharnessing to semi-dissasemble…so I’ve been starved of stick-time for a bit.)

2 Likes

Sorry, I promised a still of the install too - for those not comfortable clicking a rando’s one drive link…

3 Likes

How do you find your snapmaker? My gen 1 big boi was an unreliable fail from the start. Even with warranty replaced beds i couldn’t get the base flat on any mode…it always bubbles up to my million-hobby to do list…I hit a wall…and it goes back to the back for a year. :frowning:

It’s been pretty good. I got the 2.0, A250 size, enclosure. Have since upgraded print heads and to the 10W laser, upgraded the PSU fan myself for some noise abatement, added a duct to a filter box packed with activated charcoal with an auxilliary fan on the same circuit as the original enclosure one.

I only print PLA, and laser, so that might be part of why I’m ok with it. I think I tend to go for a bit more squish on a first layer, and won’t claim the bed calibration and flatness adjustment is perfect, I can get some warpage and peel off on larger parts. But compared to my ancient Solidoodle that I used before, it’s been practically plug and play. A few firmware bugs here and there but worked thru them.

Would I recommend it to someone starting now? Maybe not. There are far cheaper machines for the size these days, and good lasers too so you could get one of each for probably less. But it has served me well for years now.

Now if I could only get on with the project in this forum that I wanted to start…other things keep jumping the queue, like not being done with my 2022 taxes yet (yes, I’m on a filed extension, hah).