diff --git a/gns430-hardware/lib/buttons.lua b/gns430-hardware/lib/buttons.lua index c307abd..0fa80d0 100644 --- a/gns430-hardware/lib/buttons.lua +++ b/gns430-hardware/lib/buttons.lua @@ -10,19 +10,16 @@ end -- add button with one event (press) function assign(buttonName, config) - local defaultHardwareId = arduino .. config.pin - hw_id = user_prop_add_hardware_id("Button " .. tostring(buttonName), defaultHardwareId, tostring(buttonName)) - hw_button_add(tostring(hw_id), function() + local buttonNameWithPin = config.name .. " (Default Pin: " .. config.pin .. ")" + hw_button_add(buttonNameWithPin, function() event(config.event) end) end -- add button with two events (press/release) function assignClr(buttonName, config) - local defaultHardwareId = arduino .. config.pin - hw_id = user_prop_add_hardware_id("Button " .. tostring(buttonName), defaultHardwareId, tostring(buttonName)) - - hw_button_add(tostring(hw_id), function() + local buttonNameWithPin = config.name .. " (Default Pin: " .. config.pin .. ")" + hw_button_add(buttonNameWithPin, function() timer_clear = timer_start(2000, function() event(config.event2) end) diff --git a/gns430-hardware/lib/encoders.lua b/gns430-hardware/lib/encoders.lua index 57d099e..a0d4d7f 100644 --- a/gns430-hardware/lib/encoders.lua +++ b/gns430-hardware/lib/encoders.lua @@ -1,4 +1,3 @@ - function logEncoder(knobName, config) print(knobName) print("default hw id A: " .. arduino .. config.pinA) @@ -12,34 +11,17 @@ function leftRight(direction) return direction == 1 and "_Right" or "_Left" end -local default_acceleration = 3 -local default_debounce = 4 - -- How to add Rotary Encoders: -- https://siminnovations.com/wiki/index.php?title=Rotary_encoder_connection_tutorial -- https://siminnovations.com/wiki/index.php?title=Hw_dial_add -- hw_dial_add(hw_id_a, hw_id_b, callback) -function encoder(knobName, config) - - type = "TYPE_1_DETENT_PER_PULSE" - - local defaultPinA = arduino .. config.pinA - local hw_id_pin_a = user_prop_add_hardware_id("Encoder " .. knobName .. " pin A", defaultPinA, knobName .. " pin A") - - local defaultPinB = arduino .. config.pinB - local hw_id_pin_b = user_prop_add_hardware_id("Encoder " .. knobName .. " pin B", defaultPinB, knobName .. " pin B") - - hw_dial_add( - tostring(hw_id_pin_a), - tostring(hw_id_pin_b), type, default_acceleration, default_debounce, function(direction) - event(config.event .. leftRight(direction)) - end) -end - function setupEncoders() - -- Run the four encoders through the assignment function + -- Run the four encoders through the assignment function for knobName, config in pairs(knobs) do - logEncoder(knobName, config) - encoder(knobName, config) + logEncoder(knobName, config) + local knobNameWithPin = config.name .. " (Default Pins: " .. config.pinA .. ", " .. config.pinB .. ")" + hw_dial_add(knobNameWithPin, function(direction) + event(config.event .. leftRight(direction)) + end) end end diff --git a/gns430-hardware/logic.lua b/gns430-hardware/logic.lua index d02d56c..4d7bb8e 100644 --- a/gns430-hardware/logic.lua +++ b/gns430-hardware/logic.lua @@ -13,67 +13,82 @@ end buttons = { -- Left side Buttons COMSWAP = { + name = "COM FlipFlop", pin = "D2", event = "H:AS430_COMSWAP_Push" }, NAVSWAP = { + name = "NAV FlipFlop", pin = "D3", event = "H:AS430_NAVSWAP_Push" }, -- Lower Buttons CDI = { + name = "CDI", pin = "D4", event = "TOGGLE_GPS_DRIVES_NAV1" }, OBS = { + name = "OBS", pin = "D5", event = "H:AS430_OBS_Push" }, MSG = { + name = "MSG", pin = "D6", event = "H:AS430_MSG_Push" }, FPL = { + name = "FPL", pin = "D7", event = "H:AS430_FPL_Push" }, PROC = { + name = "PROC", pin = "D8", event = "H:AS430_PROC_Push" }, -- Right Side Buttons DCT = { + name = "DCT", pin = "D9", event = "H:AS430_DirectTo_Push" }, MENU = { + name = "MENU", pin = "D10", event = "H:AS430_MENU_Push" }, CLR = { + name = "CLR", pin = "D11", event = "H:AS430_CLR_Push", event2 = "H:AS430_CLR_Push_Long" }, ENT = { + name = "ENT", pin = "D12", event = "H:AS430_ENT_Push" }, -- Zoom Buttons ZOOM = { + name = "Range +", pin = "D13", event = "H:AS430_RNG_Zoom" }, DEZOOM = { + name = "Range -", pin = "D14", event = "H:AS430_RNG_Dezoom" }, -- Knob Push Buttons CVPUSH = { + name = "C/V Push", pin = "D15", event = "H:AS430_LeftSmallKnob_Push" }, CRSRPUSH = { + name = "CRSR Push", pin = "D16", event = "H:AS430_RightSmallKnob_Push" } @@ -81,21 +96,25 @@ buttons = { knobs = { CVBig = { + name = "C/V Large Knob", pinA = "D17", pinB = "D18", event = "H:AS430_LeftLargeKnob" }, CVSmall = { + name = "C/V Small Knob", pinA = "D19", pinB = "D20", event = "H:AS430_LeftSmallKnob" }, CRSRBig = { + name = "CRSR Large Knob", pinA = "D21", pinB = "D22", event = "H:AS430_RightLargeKnob" }, CRSRSmall = { + name = "CRSR Small Knob", pinA = "D23", pinB = "D24", event = "H:AS430_RightSmallKnob"