Beta 35 with Arduino hangs when connecting to FS2020
Posted: Tue Apr 13, 2021 9:24 pm
Note: the script 'hangs'. I can still use AM itself...
This happens 9 out of 10 times. I have an Arduino script, connecting a couple of buttons and 5 rotary encoders. I also use a LCD display. With the latest beta 35 it looks like the panel code 'hangs' after first subscribing to a fs2020-variable, or getting new values for them (can't really figure out when *exactly* it happens. I have reflashed the Arduino, I also restart the fsbridge. I close and re-open the panel and even restarting AM or the whole machine. 9 out of 10 times it doesn't start. 1 out of 10 times it does, and then the script works fine. For reference I'll post the script below (it is work in progress and will be cleaned up a bit later on). I also created a test script with just the com1-code; that gives the same effect.
Also, AM reports a new version of the fsbridge all the time. Doesn't matter if I install the linked setup or not; it keeps reporting that. I've also tried a clean install of AM beta 35; to no avail.
I no longer have an older beta version. Can that be made available? Can't find it that quick on the site.
This happened before but also after today's update of fs2020. So, it looks like this is a AM issue
Any hints on how to debug this particular issue?
The script:
This happens 9 out of 10 times. I have an Arduino script, connecting a couple of buttons and 5 rotary encoders. I also use a LCD display. With the latest beta 35 it looks like the panel code 'hangs' after first subscribing to a fs2020-variable, or getting new values for them (can't really figure out when *exactly* it happens. I have reflashed the Arduino, I also restart the fsbridge. I close and re-open the panel and even restarting AM or the whole machine. 9 out of 10 times it doesn't start. 1 out of 10 times it does, and then the script works fine. For reference I'll post the script below (it is work in progress and will be cleaned up a bit later on). I also created a test script with just the com1-code; that gives the same effect.
Also, AM reports a new version of the fsbridge all the time. Doesn't matter if I install the linked setup or not; it keeps reporting that. I've also tried a clean install of AM beta 35; to no avail.
I no longer have an older beta version. Can that be made available? Can't find it that quick on the site.
This happened before but also after today's update of fs2020. So, it looks like this is a AM issue
Any hints on how to debug this particular issue?
The script:
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) |
-- | |
-- +----------------------------------------------------------+
-- */
CLOCKWISE = 1
COUNTERCLOCKWISE = -1
btntogglecom1highlow = 38
btntogglecom1 = 53
knobcom1a = 28
knobcom1b = 29
btntogglecom2 = 52
btntogglecom2highlow = 40
knobcom2a = 24
knobcom2b = 25
btnonoffpower = 48
btnonoffavionics = 51
btnonoffpitotheat = 50
knobvor1a = 26
knobvor1b = 27
knobvor2a = 22
knobvor2b = 23
btnheadingtoggle = 39
knobheadinga = 30
knobheadingb = 31
btnonofffuelpump = 32
btnonoffbeaconlights = 46
btnonofflandinglights = 47
btnonofftaxilights = 44
btnonoffnavigationlights = 37
btnonoffstrobelights = 42
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")
function debugprint(what)
-- hw_chr_display_set_text(display, 0, what)
print(what)
end
-- ************* COM1 **********
-- Switch com1 mode (inc/dec high/low)
com1high = true
function btntogglecom1highlowon()
end
function btntogglecom1highlowoff()
com1high = not (com1high)
end
hw_button_add("ARDUINO_MEGA2560_A_D" .. btntogglecom1highlow, btntogglecom1highlowon, btntogglecom1highlowoff)
-- Switch frequencies COM1
function btntogglecom1on()
end
function btntogglecom1off()
fs2020_event("COM_STBY_RADIO_SWAP")
end
hw_button_add("ARDUINO_MEGA2560_A_D" .. btntogglecom1, btntogglecom1on, btntogglecom1off)
-- Radio COM1 frequency
function knobcom1callback(direction)
if (direction == CLOCKWISE) then
if (com1high) then
fs2020_event("COM_RADIO_WHOLE_INC")
else
fs2020_event("COM_RADIO_FRACT_INC")
end
else
if (com1high) then
fs2020_event("COM_RADIO_WHOLE_DEC")
else
fs2020_event("COM_RADIO_FRACT_DEC")
end
end
end
function newCom1Frequencies(com1, com1stby)
hw_chr_display_set_text(display, 0, string.format("%03.03f", com1) .. " " .. string.format("%03.03f", com1stby))
end
hw_dial_add("ARDUINO_MEGA2560_A_D" .. knobcom1a, "ARDUINO_MEGA2560_A_D" .. knobcom1b, "TYPE_1_DETENT_PER_PULSE",
knobcom1callback)
fs2020_variable_subscribe("COM ACTIVE FREQUENCY:1", "Mhz", "COM STANDBY FREQUENCY:1", "MHz", newCom1Frequencies)
-- ************* ENDOF COM1 **********
-- ************* COM2 ****************
-- Switch frequencies COM2
function btntogglecom2on()
end
function btntogglecom2off()
fs2020_event("COM2_RADIO_SWAP")
end
hw_button_add("ARDUINO_MEGA2560_A_D" .. btntogglecom2, btntogglecom2on, btntogglecom2off)
-- Switch com2 mode (inc/dec high/low)
com2high = true
function btntogglecom2highlowon()
end
function btntogglecom2highlowoff()
com2high = not (com2high)
end
hw_button_add("ARDUINO_MEGA2560_A_D" .. btntogglecom2highlow, btntogglecom2highlowon, btntogglecom2highlowoff)
-- Radio COM2 frequency
function knobcom2callback(direction)
if (direction == CLOCKWISE) then
if (com2high) then
fs2020_event("COM2_RADIO_WHOLE_INC")
else
fs2020_event("COM2_RADIO_FRACT_INC")
end
else
if (com2high) then
fs2020_event("COM2_RADIO_WHOLE_DEC")
else
fs2020_event("COM2_RADIO_FRACT_DEC")
end
end
end
hw_dial_add("ARDUINO_MEGA2560_A_D" .. knobcom2a, "ARDUINO_MEGA2560_A_D" .. knobcom2b, "TYPE_1_DETENT_PER_PULSE",
knobcom2callback)
function newCom2Frequencies(com2, com2stby)
hw_chr_display_set_text(display, 1, string.format("%03.03f", com2) .. " " .. string.format("%03.03f", com2stby))
end
fs2020_variable_subscribe("COM ACTIVE FREQUENCY:2", "Mhz", "COM STANDBY FREQUENCY:2", "Mhz", newCom2Frequencies)
-- ********** ENDCOM2 ******************
-- Turn power on/off
masteralternator = false
function btnonoffpoweron()
triggerOptionally("TOGGLE_MASTER_ALTERNATOR", masteralternator, true)
end
function btnonoffpoweroff()
triggerOptionally("TOGGLE_MASTER_ALTERNATOR", masteralternator, false)
end
hw_button_add("ARDUINO_MEGA2560_A_D" .. btnonoffpower, btnonoffpoweron, btnonoffpoweroff)
-- Turn avionics on/off
function btnonoffavionicson()
fs2020_event("AVIONICS_MASTER_SET", 1)
end
function btnonoffavionicsoff()
fs2020_event("AVIONICS_MASTER_SET", 0)
end
hw_button_add("ARDUINO_MEGA2560_A_D" .. btnonoffavionics, btnonoffavionicson, btnonoffavionicsoff)
-- Turn pitot head on/off
function btnonoffpitotheaton()
fs2020_event("PITOT_HEAT_SET", 1)
end
function btnonoffpitotheatoff()
fs2020_event("PITOT_HEAT_SET", 0)
end
hw_button_add("ARDUINO_MEGA2560_A_D" .. btnonoffpitotheat, btnonoffpitotheaton, btnonoffpitotheatoff)
-- Toggle heading / ADF
headingmode = false
function btnheadingtoggleon()
end
function btnheadingtoggleoff()
headingmode = not (headingmode)
end
hw_button_add("ARDUINO_MEGA2560_A_D" .. btnheadingtoggle, btnheadingtoggleon, btnheadingtoggleoff)
-- Turn fuel pump on/off
fuelpump = false
function btnonofffuelpumpon()
triggerOptionally("FUEL_PUMP", fuelpump, true)
end
function btnonofffuelpumpoff()
triggerOptionally("FUEL_PUMP", fuelpump, false)
end
hw_button_add("ARDUINO_MEGA2560_A_D" .. btnonofffuelpump, btnonofffuelpumpon, btnonofffuelpumpoff)
-- Turn beacon lights on/off
beaconlights = false
function btnonoffbeaconlightson()
triggerOptionally("TOGGLE_BEACON_LIGHTS", beaconlights, true)
end
function btnonoffbeaconlightsoff()
triggerOptionally("TOGGLE_BEACON_LIGHTS", beaconlights, false)
end
hw_button_add("ARDUINO_MEGA2560_A_D" .. btnonoffbeaconlights, btnonoffbeaconlightson, btnonoffbeaconlightsoff)
-- Turn landing lights on/off
function btnonofflandinglightson()
fs2020_event("LANDING_LIGHTS_SET", 1)
end
function btnonofflandinglightsoff()
fs2020_event("LANDING_LIGHTS_SET", 0)
end
hw_button_add("ARDUINO_MEGA2560_A_D" .. btnonofflandinglights, btnonofflandinglightson, btnonofflandinglightsoff)
-- Turn taxi lights on/off
taxilights = false
function btnonofftaxilightson()
triggerOptionally("TOGGLE_TAXI_LIGHTS", taxilights, true)
end
function btnonofftaxilightsoff()
triggerOptionally("TOGGLE_TAXI_LIGHTS", taxilights, false)
end
hw_button_add("ARDUINO_MEGA2560_A_D" .. btnonofftaxilights, btnonofftaxilightson, btnonofftaxilightsoff)
-- Turn taxi lights on/off
navlights = false
function btnonoffnavigationlightson()
triggerOptionally("TOGGLE_NAV_LIGHTS", navlights, true)
end
function btnonoffnavigationlightsoff()
triggerOptionally("TOGGLE_NAV_LIGHTS", navlights, false)
end
hw_button_add("ARDUINO_MEGA2560_A_D" .. btnonoffnavigationlights, btnonoffnavigationlightson,
btnonoffnavigationlightsoff)
-- Turn taxi lights on/off
function btnonoffstrobelightson()
fs2020_event("STROBES_SET", 1)
end
function btnonoffstrobelightsoff()
fs2020_event("STROBES_SET", 0)
end
hw_button_add("ARDUINO_MEGA2560_A_D" .. btnonoffstrobelights, btnonoffstrobelightson, btnonoffstrobelightsoff)
-- Change heading
function knobheadingcallback(direction)
if (direction == CLOCKWISE) then
if (headingmode) then
fs2020_event("HEADING_BUG_INC")
else
fs2020_event("ADF_CARD_INC")
end
else
if (headingmode) then
fs2020_event("HEADING_BUG_DEC")
else
fs2020_event("ADF_CARD_DEC")
end
end
end
hw_dial_add("ARDUINO_MEGA2560_A_D" .. knobheadinga, "ARDUINO_MEGA2560_A_D" .. knobheadingb, "TYPE_1_DETENT_PER_PULSE",
knobheadingcallback)
-- Change VOR1
function knobvor1callback(direction)
if (direction == CLOCKWISE) then
fs2020_event("VOR1_OBI_INC")
else
fs2020_event("VOR1_OBI_DEC")
end
end
hw_dial_add("ARDUINO_MEGA2560_A_D" .. knobvor1a, "ARDUINO_MEGA2560_A_D" .. knobvor1b, "TYPE_1_DETENT_PER_PULSE",
knobvor1callback)
-- Change VOR2
function knobvor2callback(direction)
if (direction == CLOCKWISE) then
fs2020_event("VOR2_OBI_INC")
else
fs2020_event("VOR2_OBI_DEC")
end
end
hw_dial_add("ARDUINO_MEGA2560_A_D" .. knobvor2a, "ARDUINO_MEGA2560_A_D" .. knobvor2b, "TYPE_1_DETENT_PER_PULSE",
knobvor2callback)
function updateVariables(newMasterAlternator, newBeaconLights, newTaxiLights, newNavLights, newFuelPump)
masteralternator = newMasterAlternator
beaconlights = newBeaconLights
taxilights = newTaxiLights
navlights = newNavLights
fuelpump = newFuelPump
end
function triggerOptionally(event, oldvalue, newvalue)
if (not (oldvalue == newvalue)) then
fs2020_event(event)
end
end
fs2020_variable_subscribe("GENERAL ENG MASTER ALTERNATOR", "Bool", "LIGHT BEACON", "Bool", "LIGHT TAXI", "Bool",
"LIGHT NAV", "Bool", "GENERAL ENG FUEL PUMP SWITCH:1", "Bool", updateVariables)
debugprint("Ready...")