0

Muxed 60 input GPIO plugin for HD1025 problem

I need more than 8 input switches on a HD1025 

In another case I needed 10 switches and made a decimal to binary matrix with diodes so this gave max 15 inputs with switches connecting to ground. I did make a simple autorun.brs for that.

Now I need even more switches and have been looking into doing a muxed version .. gpio 0,1,2,3 whille alternate high to low and I will then read the input on gpio 4,5,6,7. I have now made a new autorun which does that and it work fine (Max 60 switches)

 

Next step is to make it as a plugin and white the sw values input to 4 variables which can be used in the BAC.

I have trouble to do that correctly ... either the script runs continually (scanning the rows  and never comes to the real application in BAC.

Or alternativ the BAC works but the sw are not scanned.

Hope you have some suggestions how to do this.???

Function Gpio_Mux(msgPort As Object, userVariables As Object, bsp As Object)
    m.port = CreateObject("roGpioControlPort")
    m.msgPort = CreateObject("roMessagePort")
    count = 55

    value_1 = 11
    value_2 = 12
    value_3 = 13
    value_4 = 14

    value_old_1 = 0
    value_old_2 = 0
    value_old_3 = 0
    value_old_4 = 0

        m.port.EnableOutput(0)
        m.port.EnableOutput(1)
        m.port.EnableOutput(2)
        m.port.EnableOutput(3)
        m.port.EnableInput(4)
        m.port.EnableInput(5)
        m.port.EnableInput(6)
        m.port.EnableInput(7)
        
rem    while true
        for colIndex = 0 to 3
                m.port.SetOutputState(0,true)  
                m.port.SetOutputState(1,true)  
                m.port.SetOutputState(2,true)  
                m.port.SetOutputState(3,true)  

                 if (colIndex = 0) then m.port.SetOutputState(0,false)  
                 if (colIndex = 1) then m.port.SetOutputState(1,false)  
                 if (colIndex = 2) then m.port.SetOutputState(2,false)  
                 if (colIndex = 3) then m.port.SetOutputState(3,false)  
                
                sleep(50)


                if (colIndex = 0) then
                        value_1 = 0
                        if  m.port.IsInputActive(4) then value_1 =  value_1 OR &h01
                        if  m.port.IsInputActive(5) then value_1 =  value_1 OR &h02
                        if  m.port.IsInputActive(6) then value_1 =  value_1 OR &h04
                        if  m.port.IsInputActive(7) then value_1 =  value_1 OR &h08
                endif

                if (colIndex = 1) then
                        value_2 = 0
                        if  m.port.IsInputActive(4) then value_2 =  value_2 OR &h01
                        if  m.port.IsInputActive(5) then value_2 =  value_2 OR &h02
                        if  m.port.IsInputActive(6) then value_2 =  value_2 OR &h04
                        if  m.port.IsInputActive(7) then value_2 =  value_2 OR &h08
                endif

                if (colIndex = 2) then
                        value_3 = 0
                        if  m.port.IsInputActive(4) then value_3 =  value_3 OR &h01
                        if  m.port.IsInputActive(5) then value_3 =  value_3 OR &h02
                        if  m.port.IsInputActive(6) then value_3 =  value_3 OR &h04
                        if  m.port.IsInputActive(7) then value_3 =  value_3 OR &h08
                endif


                if (colIndex = 3) then
                        value_4 = 0
                        if  m.port.IsInputActive(4) then value_4 =  value_4 OR &h01
                        if  m.port.IsInputActive(5) then value_4 =  value_4 OR &h02
                        if  m.port.IsInputActive(6) then value_4 =  value_4 OR &h04
                        if  m.port.IsInputActive(7) then value_4 =  value_4 OR &h08
                endif
                 
        end for

            if (NOT value_1 = value_old_1) then
                    print "Value_1: ";value_1
                    value_old_1 = value_1
rem                    m.signalBeacon("Value_1", { value_1: value_1 })
                    pluginMessageCmd = {}
                    pluginMessageCmd["PluginName"] = "value_1"
                    pluginMessageCmd["PluginMessage"] = "value_1"
                    m.msgPort.PostMessage(pluginMessageCmd)                    
            endif
            
            if (NOT value_2 = value_old_2) then
                    print "Value_2: ";value_2
                    value_old_2 = value_2

            endif

            if (NOT value_3 = value_old_3) then
                    print "Value_3: ";value_3
                    value_old_3 = value_3

            endif

            if (NOT value_4 = value_old_4) then
                    print "Value_4: ";value_4
                    value_old_4 = value_4

            endif
            

            sleep(10)
            count = count +1
            if count = 100 then 
                count = 0
                print "-----------Values-----------------"
                print "Value_1: ";value_1
                print "Value_2: ";value_2
                print "Value_3: ";value_3
                print "Value_4: ";value_4

            endif

           return Gpio_Mux
End Function

0 comments

Please sign in to leave a comment.