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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ngreatorex
Copy link

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
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
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
Author

README updated

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