Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type "a" to FSUIPC Offset variables for byte[] #96

Merged

Conversation

ngreatorex
Copy link
Contributor

Hi,

I wanted to be able to read the contents of the PMDG 777 CDU units via FSUIPC. In particular, I want to do this to determine if the auto time compression functionality is enabled. In order to do so, it would be very useful to be able to retrieve a byte[] from FSUIPC. This PR adds the capability to do that.

Out of completeness, here is an extract of my global Lua script that I wrote to use the new functionality:

RunSim("MSFS")
RunAircraft("PMDG 777")
RunInterval(200, "UpdateVariables")

local CDU_COLUMNS = 24
local CDU_ROWS = 14
local AutoCruise = 0

SimVar("0x5800:1024:a")
function UpdateVariables()
    local bytes = SimRead("0x5800:1024:a")
    local rows = {}
    local byteIndex = 0

    for col=1,CDU_COLUMNS do
        for row=1,CDU_ROWS do
            if col == 1 then
                rows[row] = {}
            end
        
            rows[row][col] = { Symbol=string.char(bytes[byteIndex]), Color=bytes[byteIndex+1], Flags=bytes[byteIndex+2] }
            byteIndex = byteIndex + 3
        end
    end

    local title = ""
    for idx, cell in ipairs(rows[1]) do
        if cell.Symbol ~= string.char(0) and cell.Symbol ~= " " then
            title = title .. cell.Symbol
        end
    end

    if title == "AUTOCRUISE" then
        if bit32.extract(rows[9][2].Flags, 0) == 0 then
            AutoCruise = 2
        else
            AutoCruise = 1
        end
    else
        AutoCruise = 0
    end
end

function GetAutoCruise()
    return AutoCruise
end

PS. Great work on this project! I find it very useful and use it every flight 😃

@ngreatorex ngreatorex changed the title Add type a to Offset variables for byte[] Add type "a" to FSUIPC Offset variables for byte[] Jan 26, 2025
@Fragtality
Copy link
Owner

Uhm ... I'm a bit surprised to be honest 😅
That is all that is needed for it to just work? 😳

Have you tried what happens when such a Byte/Array-Address is used with in an Action? I.e. as Read or Command Address? 🤔

@ngreatorex
Copy link
Contributor Author

I haven't tried writing as the offset I was testing with is read only. I will try to test tomorrow

@ngreatorex
Copy link
Contributor Author

ngreatorex commented Jan 28, 2025

I've added support for writing as well, using any of the formats: "[int,int ...]", "[0xff,0xff ...]" or "0xFFFFFFFF...".

Still need to update the README though with that info 😃

@ngreatorex
Copy link
Contributor Author

README updated

@ngreatorex
Copy link
Contributor Author

Hi @Fragtality. Just wanted to give you a nudge on this in case you'd forgotten. Would be great to see this in an official release 🙂

@Fragtality
Copy link
Owner

Oh it will definitely be in the official release, it is a really great Contribution!
Not forgotten, more like pushing it in front of me all the time 😅

The "problem" is that the Plugin was/is undergoing some underlying Changes again which certainly cause merge conflicts (including changes to Folder-Names, the Build Process and Stuff moved out of the Plugin to a common Library). And I'm still a bit unsure what the best/fairest approach would be 🤔
I think I'll just merge/pull your Request to the Repo first, then merge/synch it with my local & current code and then push it all to the Repo. While constantly praying to get out of the Mess 😂

@ngreatorex
Copy link
Contributor Author

Alright, no worries. As I said, just wanted to check it wasn't forgotten 😄

I find Git is much better than it used to be at handling renamed files, as long as you commit the rename as a separate commit to modifying said file!

Hope the merge conflicts aren't too painful 😄

@Fragtality
Copy link
Owner

What could possibly go wrong?

git-merge

@Fragtality Fragtality merged commit 1f227cc into Fragtality:master Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants