Announcement

Collapse
No announcement yet.

Virtual switches

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Virtual switches

    I'm not sure if this is where this needs to be posted, but if anyone is interested, I made some commands to act as virtual switches.

    I needed three switches to turn my amp on/off and various other things, but it could be used for neons, radar detectors, etc... This works through the parallel port. If you look up a pin-out, you can determine how to wire it to the connector. (If I can find it, I'll post the site where I found help with wiring it up)

    Before I post this, I want to state that I am not a programmer, so my code is by no means elegant.

    First you need Inpout32.dll from http://www.logix4u.net/

    Then I opened Guinos source code and added the following module:

    Code:
    'Inp and Out declarations for port I/O using inpout32.dll.
    'By http://www.logix4u.net/
    
    Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32" _
        (ByVal PortAddress As Integer) _
        As Integer
        
    Public Declare Sub Out Lib "inpout32.dll" Alias "Out32" _
        (ByVal PortAddress As Integer, _
        ByVal Value As Integer)
    
    
    'Following written by Carlos Paiva
    'Downloaded from http://www.freevbcode.com/ShowCode.asp?ID=4500
    
    Public Function CBin(ByVal Nr As Long, _
       Optional Precision As Integer = 3) As String
      Do Until Nr = 0
        CBin = CStr((Nr Mod 2)) + CBin
        Nr = Nr \ 2
      Loop
      CBin = Format(Val(CBin), String(Precision, "0"))
    End Function
    
    
    'Following Function downloaded from http://www.vba-programmer.com/VB_Code/Binary_to_Decimal.txt
    
    Public Function ConvertBinaryToDecimal(BinVal As String) As String
    Dim iVal#, temp#, i%, Length%
    
    Length = Len(BinVal)
    For i = 0 To Length - 1
        temp = CInt(Mid(BinVal, Length - i, 1))
        iVal = iVal + (temp * (2 ^ i))
    Next i
    ConvertBinaryToDecimal = iVal
    End Function
    Finally, I wrote the following code and placed it in all the "modRoadRunner" module in with all of the command cases and compiled it:

    Code:
    Case "switch3"
                If Mid$(CBin(Inp(&H378)), 1, 1) = 1 Then
                    Out &H378, ConvertBinaryToDecimal("0" & Right$(CBin(Inp(&H378)), 2))
                Else
                    Out &H378, ConvertBinaryToDecimal("1" & Right$(CBin(Inp(&H378)), 2))
                End If
                
    Case "switch2"
                If Mid$(CBin(Inp(&H378)), 2, 1) = 1 Then
                    Out &H378, ConvertBinaryToDecimal(Left$(CBin(Inp(&H378)), 1) & "0" & Right$(CBin(Inp(&H378)), 1))
                Else
                    Out &H378, ConvertBinaryToDecimal(Left$(CBin(Inp(&H378)), 1) & "1" & Right$(CBin(Inp(&H378)), 1))
                End If
    Case "switch1"
                If Mid$(CBin(Inp(&H378)), 3, 1) = 1 Then
                    Out &H378, ConvertBinaryToDecimal(Left$(CBin(Inp(&H378)), 2) & "0")
                Else
                    Out &H378, ConvertBinaryToDecimal(Left$(CBin(Inp(&H378)), 2) & "1")
                End If
    Hope that helps. Sorry if it wasn't very clear. If you have any questions, I'll try to answer them as best I can.

  • #2
    Could these commands be integrated into RoadRunner easily?

    I mean can we have a screen called "Controls" or something, and be able to have some sweet vintage looking rocker switch images that could be labeled?

    Comment


    • #3
      Originally posted by maiwand
      I'm not sure if this is where this needs to be posted, but if anyone is interested, I made some commands to act as virtual switches...
      is this already working in your system? could you could provide some pic or video??

      danon
      [....99.9%]
      [HW] 566eMHz/128mb/6gb, FlyVideo3k, RandMgps, M1-ATX, 7" Lilliput, VGA2AVadptrFor2ndVideo, 4CH/100rms, 10"Sub, 40AhDeepCycleTank
      [....99.8%]
      [SW] XP/MMC/FP:D3,FlyTV/AxifeFM,CarMM?
      [Working on] puttingBackEvrythg.

      Comment


      • #4
        Can you please post a wiring diagram? tks
        Ikea Case. Epia M10000.M1-ATX. 512 Mb. 2,5" 80 GB HDD. 7" Lilliput. BU-303 GPS. Sony Joystick.
        Status -->
        Lilliput Installed (not indash yet..)
        BraveCar 2.5

        Comment


        • #5
          How many switches do you get? Inputs/Outputs?

          Comment


          • #6
            If you can control switches, I may wait a while to mount the 12 flip down. It would be sweet to be able turn on and off any selected monitors from RR!

            Comment


            • #7
              He's just using LPT1... this is why I never been key of those "relay control boards".. they're merely an extension of this.. basically with the above RR can set the state of a data pin on the LPT port (total of 8) and that levelcan be converted (using a basic circuit) onto a Rele state and/or any digitally controlled circuit..

              I'd say the best thing to do for this is a little DLL+SOURCE so the same basic code in RR could be used for different circuit boards by selecting a DLL file..
              Ride Runner RR's Myspace

              "Being happy is not about having what you want, it's about wanting what you have."
              "The best things in life are always free - but that doesn't mean money can't buy you good things."

              Comment


              • #8
                bump
                View My Blog


                Click for 2GB FREE on-line storage!

                Comment


                • #9
                  Sorry for the delay. I don't have it actually installed yet, but to try it, I made a simple test device. It is basically a connector with some resistors/leds soldered on the pins that can be turned on and off through my RR. The pictures and wiring diagram are below (sorry, my camera is crap):




                  The resistors in the diagram are 470 ohm

                  Mine is just set up for 3, but like Guino said, there is a possibility of exapanding it to 8

                  I'd say the best thing to do for this is a little DLL+SOURCE so the same basic code in RR could be used for different circuit boards by selecting a DLL file..
                  Guino, can you clarify this? I don't understand what you mean exactly. Also, I'm looking at coding it as an indictor, so that when it is in the on state, the "down" screen is displayed like with your pause or shuffle ones. I'm not having any luck finding there this is so I can duplicate your code. Do you think you could point me in the right direction?

                  Thanks guys, I hope this helps. I'm going to be gone for the rest of the weekend, so I'll answer any more questions when I get back, although I'm sure there are a lot of people here that are more knowledgeable on this subject than me.

                  Comment


                  • #10
                    I'll probably do something as example for this pretty soon (as soon as I find time to do it)... there's too much going on at the moment...
                    Ride Runner RR's Myspace

                    "Being happy is not about having what you want, it's about wanting what you have."
                    "The best things in life are always free - but that doesn't mean money can't buy you good things."

                    Comment


                    • #11
                      Originally posted by guino
                      I'll probably do something as example for this pretty soon (as soon as I find time to do it)... there's too much going on at the moment...
                      the clock starts ticking.., now...
                      [....99.9%]
                      [HW] 566eMHz/128mb/6gb, FlyVideo3k, RandMgps, M1-ATX, 7" Lilliput, VGA2AVadptrFor2ndVideo, 4CH/100rms, 10"Sub, 40AhDeepCycleTank
                      [....99.8%]
                      [SW] XP/MMC/FP:D3,FlyTV/AxifeFM,CarMM?
                      [Working on] puttingBackEvrythg.

                      Comment


                      • #12
                        I know that the priority must be RR and all, but a small executable with command line switches would be great, like:

                        lptrelay.exe /p=1 /r=1 /on

                        where
                        /p=x ; x=lpt port
                        /r=x ; 1<=x>=8 - Relay number
                        /on ; sets relay on
                        /off ; sets relay off

                        or maybe a tiny service that could receive sendmessages??

                        It would be possible to integrate this with a lot of diferent setups

                        On another thread, http://www.mp3car.com/vbulletin/showthread.php?t=57539, we discuss the possibility that Ezsync, when you arrive home, after it detects the server it runs a scritp and on syncing complete runs another script.
                        Using this virtual switches, it could switch the DC/DC ACC line to the 12v line on sync start ( together with a timer to switch back just in case something goes wrong ) and switch back to acc when sync ends.
                        Like this, it would never shutdow the carputer when you leave the house because you have acc on, but it would shutdown as usual after sync when you arrive because you have acc off.

                        I just wish I could code.. damm
                        Ikea Case. Epia M10000.M1-ATX. 512 Mb. 2,5" 80 GB HDD. 7" Lilliput. BU-303 GPS. Sony Joystick.
                        Status -->
                        Lilliput Installed (not indash yet..)
                        BraveCar 2.5

                        Comment

                        Working...
                        X