Federico Posted January 20, 2021 Report Posted January 20, 2021 Good morning, After 2 weeks programming my first diy panel I have some doubts. I've read and searched inside the FAQ and official documentation but it seems not explained or maybe I didn't look so well, so excuse me in case of repetition. 1) Is there a way to read the single bit? For example in the offset 0D0C I can set taxi lights with writeUB or setbitsUB but how can I read it's status? 2) Looping. I understood event.com and event.offset are a sort a silent looping activated only when "something" happens. In case I want to read for example every 2 seconds a set of variable, the event.timer is the best way? 3) I see in some topics minor release update for the 7 version. Where to find the latest? Thanks for your help.
spokes2112 Posted January 20, 2021 Report Posted January 20, 2021 4 hours ago, Federico said: 1) Is there a way to read the single bit? For example in the offset 0D0C I can set taxi lights with writeUB or setbitsUB but how can I read it's status? 0x0D0C is a 16 bit word if you want to get all the lights. 2 function examples below, "getTaxiLights1" is run by the timer, "getTaxiLights2" is run on first load & anytime there is a change at offset 0x0D0C. The last is the preferable method. function getTaxiLights1(time) tL = ipc.readUW(0x0D0C) tL = logic.And(tL, 8) -- Taxi lights are on bit 3, therefore the mask is 8 if tL == 8 then -- Taxi Lights are on else -- Taxi Lights are off end end function getTaxiLights2(offset, value) value = logic.And(value, 8) -- Taxi lights are on bit 3, therefore the mask is 8 if value == 8 then -- Taxi Lights are on else -- Taxi Lights are off end end event.timer(2000, "getTaxiLights1") -- call function #1 every 2 seconds event.offset(0x0D0C, "UW", "getTaxiLights2") -- call function #2 whenever 0x0D0C changes, also on first load Hope this helps, Roman 1
Federico Posted January 20, 2021 Author Report Posted January 20, 2021 Thank you very much Roman, that's what I was looking for. I had a look at logic.And but maybe I'm new to this and didn't understand well. Thanks a lot
John Dowson Posted January 20, 2021 Report Posted January 20, 2021 4 hours ago, Federico said: 3) I see in some topics minor release update for the 7 version. Where to find the latest? The latest official release is always available from www.fsuipc.com, and also from Interim releases are published to forum topics for testing by the person who reported an issue or requested a new feature. You can also download and try these if you like, or wait for the official release that usually follows within a few days or weeks. 1
Pete Dowson Posted January 20, 2021 Report Posted January 20, 2021 On 1/20/2021 at 7:42 AM, Federico said: 1) Is there a way to read the single bit? For example in the offset 0D0C I can set taxi lights with writeUB or setbitsUB but how can I read it's status? If you read or write the whole value you are getting and setting 8 lights. To get notified of a single bit change, like the 08 (2^3) bit, use event.offsetmask(0X0D0C, 8, "UB", "function name") To SET one bit (or more) use ipc.setbitsUB. There are also functions to clear a bit (or more): ipc.clearbitsUB, and to change/toggle one or more bits: ipc.togglebitsUB. All these would be more efficient than reading/writing the complete value and using the Logic library functions for these basic things. It really is worth your while browsing the Lua Library document so you can see what is available. Pete 1
spokes2112 Posted January 20, 2021 Report Posted January 20, 2021 2 hours ago, Pete Dowson said: It really is worth your while browsing the Lua Library document so you can see what is available. event.offsetmask ... missed that one too 😢
Federico Posted January 20, 2021 Author Report Posted January 20, 2021 Thanks John I'm studying but it's a lot of things and the functions you described were not clear to understand. Now it's clear. Thanks so much.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now