1) Reflashed the Arduino
2) Updated the script to no longer handle the avionics, but only the essential functions in the Cessna 152 I want to fly mainly. I leave handling the avionics in the 182 to the panel itself. I *think* there was a situation where the avionics was disabled, but that wasn't reflected on the panel itself. With the avionics disabled, there were no updates from FS, and no events I sent were picked up. Hence, there were no updates. Now I'm no longer managing the avionics from my own panel; and it looks like my instrument is now working correctly.
I will clone the 182 panel and remove the instruments the 152 doesn't have. I hope AM4 sees light soon, and there is a better 152 panel that I can use. I can write software, but cannot create graphics. A man needs to know his weaknesses
As said, for transparency, I'm posting my code again
Code: Select all
-- /*
-- +----------------------------------------------------------+
-- | |
-- | +-------------------+ (53) (52) |
-- | | | |
-- | | | (38) (40) |
-- | | | [28/29] [24/25] |
-- | +-------------------+ |
-- | |
-- | (48) (51) (50) (39) (41) (43) |
-- | [30/31] [26/27] [22/23] |
-- | |
-- | (32) (46) (47) (44) (37) (42) |
-- | |
-- +----------------------------------------------------------+
-- */
local CLOCKWISE = 1
local COUNTERCLOCKWISE = -1
local btntogglecom1highlow = 38
local btntogglecom1 = 53
local knobcom1a = 28
local knobcom1b = 29
local btntogglecom2 = 52
local btntogglecom2highlow = 40
local knobcom2a = 24
local knobcom2b = 25
local btnonoffalternator = 48
local btnonoffbattery = 51
local btnonoffpitotheat = 50
local knobvor1a = 26
local knobvor1b = 27
local knobvor2a = 22
local knobvor2b = 23
local btnheadingtoggle = 39
local knobheadinga = 30
local knobheadingb = 31
local btnonoffcabinlight = 32
local btnonoffbeaconlights = 46
local btnonofflandinglights = 47
local btnonofftaxilights = 44
local btnonoffnavigationlights = 37
local btnonoffstrobelights = 42
local display
local whatcom = "FRACT"
local whatcom2 = "FRACT"
local masteralternator = true
local masterbattery = true
local headingmode = "HEADING_BUG"
local cabinlight = false
local beaconlights = false
local taxilights = false
local navlights = false
function addHardware()
display = hw_chr_display_add("HD44780", 2, 16, "ARDUINO_MEGA2560_A_D6", "ARDUINO_MEGA2560_A_D7",
"ARDUINO_MEGA2560_A_D5", "ARDUINO_MEGA2560_A_D4", "ARDUINO_MEGA2560_A_D3", "ARDUINO_MEGA2560_A_D2")
if (not (hw_connected(display))) then
return false
end
if (not (hw_connected(hw_button_add("ARDUINO_MEGA2560_A_D" .. btntogglecom1highlow, noop, btntogglecom1highlowoff)))) then
return false
end
if (not (hw_connected(hw_button_add("ARDUINO_MEGA2560_A_D" .. btntogglecom1, noop, btntogglecom1off)))) then
return false
end
if (not (hw_connected(hw_dial_add("ARDUINO_MEGA2560_A_D" .. knobcom1a, "ARDUINO_MEGA2560_A_D" .. knobcom1b,
"TYPE_1_DETENT_PER_PULSE", knobcom1callback)))) then
return false
end
if (not (hw_connected(hw_button_add("ARDUINO_MEGA2560_A_D" .. btntogglecom2highlow, noop, btntogglecom2highlowoff)))) then
return false
end
if (not (hw_connected(hw_button_add("ARDUINO_MEGA2560_A_D" .. btntogglecom2, noop, btntogglecom2off)))) then
return false
end
if (not (hw_connected(hw_dial_add("ARDUINO_MEGA2560_A_D" .. knobcom2a, "ARDUINO_MEGA2560_A_D" .. knobcom2b,
"TYPE_1_DETENT_PER_PULSE", knobcom2callback)))) then
return false
end
if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonoffalternator, btnonoffalternatorchanged)))) then
return false
end
if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonoffbattery, btnonoffbatterychanged)))) then
return false
end
if (not (hw_connected(hw_button_add("ARDUINO_MEGA2560_A_D" .. btnheadingtoggle, noop, btnheadingtoggleoff)))) then
return false
end
if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonoffpitotheat, btnonoffpitotheatchanged)))) then
return false
end
if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonoffcabinlight, btnonoffcabinlightchanged)))) then
return false
end
if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonoffbeaconlights, btnonoffbeaconlightschanged)))) then
return false
end
if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonofflandinglights, btnonofflandinglightschanged)))) then
return false
end
if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonofftaxilights, btnonofftaxilightschanged)))) then
return false
end
if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonoffnavigationlights,
btnonoffnavigationlightschanged)))) then
return false
end
if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonoffstrobelights, btnonoffstrobelightschanged)))) then
return false
end
if (not (hw_connected(hw_dial_add("ARDUINO_MEGA2560_A_D" .. knobheadinga, "ARDUINO_MEGA2560_A_D" .. knobheadingb,
"TYPE_1_DETENT_PER_PULSE", knobheadingcallback)))) then
return false
end
if (not (hw_connected(hw_dial_add("ARDUINO_MEGA2560_A_D" .. knobvor1a, "ARDUINO_MEGA2560_A_D" .. knobvor1b,
"TYPE_1_DETENT_PER_PULSE", knobvor1callback)))) then
return false
end
if (not (hw_connected(hw_dial_add("ARDUINO_MEGA2560_A_D" .. knobvor2a, "ARDUINO_MEGA2560_A_D" .. knobvor2b,
"TYPE_1_DETENT_PER_PULSE", knobvor2callback)))) then
return false
end
return true
end
function triggerOptionally(event, oldvalue, newvalue)
if (not (oldvalue == newvalue)) then
fs2020_event(event)
end
end
function noop()
end
-- ************* COM1 **********
-- Switch com1 mode (inc/dec high/low)
function btntogglecom1highlowoff()
whatcom = fif(whatcom == "FRACT", "WHOLE", "FRACT")
end
-- Switch frequencies COM1
function btntogglecom1off()
fs2020_event("COM_STBY_RADIO_SWAP")
end
-- Radio COM1 frequency
function knobcom1callback(direction)
fs2020_event("COM_RADIO_" .. whatcom .. fif(direction == CLOCKWISE, "_INC", "_DEC"))
end
function newCom1Frequencies(com1, com1stby)
hw_chr_display_set_text(display, 0, string.format("%03.03f", com1) .. " " .. string.format("%03.03f", com1stby))
end
-- ************* ENDOF COM1 **********
-- ************* COM2 **********
-- Switch com1 mode (inc/dec high/low)
function btntogglecom2highlowoff()
whatcom2 = fif(whatcom2 == "FRACT", "WHOLE", "FRACT")
end
-- Switch frequencies COM2
function btntogglecom2off()
fs2020_event("COM2_RADIO_SWAP")
end
-- Radio COM2 frequency
function knobcom2callback(direction)
fs2020_event("COM2_RADIO_" .. whatcom2 .. fif(direction == CLOCKWISE, "_INC", "_DEC"))
end
function newCom2Frequencies(com2, com2stby)
hw_chr_display_set_text(display, 1, string.format("%03.03f", com2) .. " " .. string.format("%03.03f", com2stby))
end
-- ************* ENDOF COM2 **********
-- Turn power on/off
function btnonoffalternatorchanged(position)
triggerOptionally("TOGGLE_MASTER_ALTERNATOR", masteralternator, (position == 1))
end
-- Turn avionics on/off
function btnonoffbatterychanged(position)
triggerOptionally("TOGGLE_MASTER_BATTERY", masterbattery, (position == 1))
end
-- Toggle heading / ADF
function btnheadingtoggleoff()
headingmode = fif(headingmode == "HEADING_BUG", "ADF_CARD", "HEADING_BUG")
end
-- Turn pitot head on/off
function btnonoffpitotheatchanged(position)
fs2020_event("PITOT_HEAT_SET", position)
end
-- Turn fuel pump on/off
function btnonoffcabinlightchanged(position)
triggerOptionally("TOGGLE_CABIN_LIGHTS", cabinlight, (position == 1))
end
-- Turn beacon lights on/off
function btnonoffbeaconlightschanged(position)
triggerOptionally("TOGGLE_BEACON_LIGHTS", beaconlights, (position == 1))
end
-- Turn landing lights on/off
function btnonofflandinglightschanged(position)
fs2020_event("LANDING_LIGHTS_SET", position)
end
-- Turn taxi lights on/off
function btnonofftaxilightschanged(position)
triggerOptionally("TOGGLE_TAXI_LIGHTS", taxilights, (position == 1))
end
-- Turn navigation lights on/off
function btnonoffnavigationlightschanged(position)
triggerOptionally("TOGGLE_NAV_LIGHTS", navlights, (position == 1))
end
-- Turn strobes on/off
function btnonoffstrobelightschanged(position)
fs2020_event("STROBES_SET", position)
end
-- Change heading
function knobheadingcallback(direction)
fs2020_event(headingmode .. fif(direction == CLOCKWISE, "_INC", "_DEC"))
end
-- Change VOR1
function knobvor1callback(direction)
fs2020_event("VOR1_OBI" .. fif(direction == CLOCKWISE, "_INC", "_DEC"))
end
-- Change VOR2
function knobvor2callback(direction)
fs2020_event("VOR2_OBI" .. fif(direction == CLOCKWISE, "_INC", "_DEC"))
end
function clearscreen()
hw_chr_display_set_text(display, 0, " ")
hw_chr_display_set_text(display, 1, " ")
end
-- *** Read variables from FS -----
function updateVariables(newMasterAlternator, newBeaconLights, newTaxiLights, newNavLights, newcabinlight,
newMasterBattery)
masteralternator = newMasterAlternator
beaconlights = newBeaconLights
taxilights = newTaxiLights
navlights = newNavLights
cabinlight = newcabinlight
masterbattery = newMasterBattery
if (not (masterbattery)) then
clearscreen()
else
request_callback(newCom1Frequencies)
request_callback(newCom2Frequencies)
end
end
function subscribeVariables()
fs2020_variable_subscribe("COM ACTIVE FREQUENCY:1", "Mhz", "COM STANDBY FREQUENCY:1", "MHz", newCom1Frequencies)
fs2020_variable_subscribe("COM ACTIVE FREQUENCY:2", "Mhz", "COM STANDBY FREQUENCY:2", "MHz", newCom2Frequencies)
fs2020_variable_subscribe("GENERAL ENG MASTER ALTERNATOR", "Bool", "LIGHT BEACON", "Bool", "LIGHT TAXI", "Bool",
"LIGHT NAV", "Bool", "LIGHT CABIN", "Bool", "ELECTRICAL MASTER BATTERY", "Bool", updateVariables)
end
if (not (addHardware())) then
print "Hardware is not ready..."
end
subscribeVariables()