On Thu, 31 Mar 2011, Roberto Inzerillo wrote: > Hallo everybody, I purchased a few rotary encoder and a bunch of > 7segment displays to build a physical replacement of the Bendix KX165. > I'm using Arduino which feeds data to FGFS on a serial connection. I'd > like to update "instrumentation/comm[0]/frequencies/standby-mhz" > property using the rotary encoder, I wonder what's the best strategy. > > My current setup lets me read the rotary encoder rotation (it's a signed > int value that measures it's direction and the amount of rotation; e.g. > +3 equals three steps CW, -1 is 1 step CCW and 0 means it's not > rotating) and send it to fgsf at 30Hz. This encoder is meant to be the > KX165 physical equivalent of the frequency selector knob. > I would only send the data if it's changed. No sense in running the pump unless there's something to send.
> I can send those values to FGFS but that's useless as it is now; I > should make FGFS increment the "standby-mhz" property accordingly; > problem is that using the generic protocol to feed those data I can't > use the same approach as in kx165-1.xml where the "property-adjust" > (with a proper <step> value) command has been used. > You might want to trigger an up/down event via Nasal that will do what you need. I did something similar to this with the hardware interface software I built a few years ago. Here's the Lua end of it: ----------------------------------------------------------- -- Cockpit Interface Master - Copyright 2008 by Gene Buckle -- Controls COM1 frequency selection ----------------------------------------------------------- -- Get the currently selected frequency from the simulator. Com1Freq = CIM:GetStringValue("COM1_FRQ") if Com1Freq == "" then CIM:SetValue(0, "Com1Freq was blank for this cycle.") return end -- Choose the correct frequency "step" based upon what the current -- simulator needs. if SimType == "FlightGear" then kHz_offset = .0250 Mhz_Offset = 1.0 elseif SimType == "MSFS" then kHz_offset = 2 Mhz_Offset = 100 else CIM:SetValue(0, "Invalid SimType - >" .. SimType .. "<-") return end -- The next four if..then blocks control how the step up/step down -- buttons work for gross (Mhz) and fine (kHz) tuning of the COM -- radio. -- The routines are written to eliminate "keybounce" by ensuring that -- the user has released the button before the script terminates. -- The "CIM:SetValue(0,...)" calls are an easy way to see how the code is operating -- if there is a problem with the simulator. if CIM:GetInput("KHZ_DOWN") == true then repeat -- do nothing until CIM:GetInput("KHZ_DOWN") == false Com1Freq = Com1Freq - kHz_offset CIM:SetStringValue("COM1_FRQ", Com1Freq) CIM:SetValue(0, "KHZ_DOWN ->" .. Com1Freq .. "<-") return end if CIM:GetInput("KHZ_UP") == true then repeat -- do nothing until CIM:GetInput("KHZ_UP") == false Com1Freq = Com1Freq + kHz_offset CIM:SetStringValue("COM1_FRQ", Com1Freq) CIM:SetValue(0, "KHZ_UP - " .. Com1Freq) return end if CIM:GetInput("MHZ_UP") == true then repeat -- do nothing until CIM:GetInput("MHZ_UP") == false Com1Freq = Com1Freq + Mhz_Offset CIM:SetStringValue("COM1_FRQ", Com1Freq) CIM:SetValue(0, "MHZ_UP - " .. Com1Freq) return end if CIM:GetInput("MHZ_DOWN") == true then repeat -- do nothing until CIM:GetInput("MHZ_DOWN") == false Com1Freq = Com1Freq - Mhz_Offset CIM:SetStringValue("COM1_FRQ", Com1Freq) CIM:SetValue(0, "MHZ_DOWN - " .. Com1Freq) return end ------------------------------------------ If I can find the files for the FG end of things I'll post them. g. -- Proud owner of F-15C 80-0007 http://www.f15sim.com - The only one of its kind. http://www.simpits.org/geneb - The Me-109F/X Project ScarletDME - The red hot Data Management Environment A Multi-Value database for the masses, not the classes. http://www.scarletdme.org - Get it _today_! Political correctness is a doctrine, fostered by a delusional, illogical minority, and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end. ------------------------------------------------------------------------------ Create and publish websites with WebMatrix Use the most popular FREE web apps or write code yourself; WebMatrix provides all the features you need to develop and publish your website. http://p.sf.net/sfu/ms-webmatrix-sf _______________________________________________ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel