Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Control System (http://www.chiefdelphi.com/forums/forumdisplay.php?f=177)
-   -   A few questions on programming the Control System (http://www.chiefdelphi.com/forums/showthread.php?t=24707)

rdsideresistanc 05-02-2004 12:34

Re: A few questions on programming the Control System
 
Quote:

Originally Posted by Joe Ross
you need to pass relayfwd and relayrev as pointers so that the modifications you make don't get "thrown out" when you exit the function.

You are correct about this.....hmm....could you possibly tell me how to pass them as pointers?

Raven_Writer 05-02-2004 14:57

Re: A few questions on programming the Control System
 
Quote:

Originally Posted by Mike Soukup
If they don't work, we're all in trouble since there's an enum in 'ifi_utilities.h'. Our current code has multiple enum's and we haven't had any problems with them.

enum's work. I've tried the code out on the compiler. It compiles perfectly and such.

Joe Ross 05-02-2004 15:18

Re: A few questions on programming the Control System
 
Here is how I would implement the code (from which you should be able to figure out how to implement your code with pointers)

Code:

void toggle_single_solenoid(unsigned char button, unsigned char *prev_button, unsigned char *relay_fwd)
{
  if (button && !prev_button)    //don't keep toggling if they hold the button
      *relay_fwd = !(*relay_fwd);

  *prev_button = button;
}

call it like this:
Code:

toggle_single_solenoid(p1_sw_trig, &prev_p1_sw_trig, &relay1_fwd);
Remember to declare prev_p1_sw_trig and change the variables to whichever switches and relays you want.

seanwitte 05-02-2004 15:36

Re: A few questions on programming the Control System
 
I haven't tried it, but can you have a pointer to a bit field? relay1_fwd is a macro with the value LATDbits.LATD0. Just curious.

Avarik 06-02-2004 10:13

Re: A few questions on programming the Control System
 
What exactly is prev_button?

And thanks...I've been at this for too long...

Shouldn't take me this long!

Avarik 08-02-2004 02:55

Re: A few questions on programming the Control System
 
Alright, I finally figured it out! Here is how I did it.

Code:

if (p1_sw_trig && rel1==0)
{

        rel1++;
        if (rel2==0)
        {
        relay1_fwd=1;
        rel2++;
        }
        else
        {               
        relay1_rev=1;
        rel2--;
        }
                                               
}

if (!p1_sw_trig)
{
        rel1=0;
        relay1_fwd=0;
        relay1_rev=0;
}


rel1 and rel2 are simply declared as ints, where rel1 is initialized to 0, and rel2 to 1. This makes it go forward at first, then backwards the next time.

Adam Shapiro 08-02-2004 11:42

Re: A few questions on programming the Control System
 
Quote:

Originally Posted by Avarik
Alright, I finally figured it out! Here is how I did it.

Code:

if (p1_sw_trig && rel1==0)
{

        rel1++;
        if (rel2==0)
        {
        relay1_fwd=1;
        rel2++;
        }
        else
        {               
        relay1_rev=1;
        rel2--;
        }
                                               
}

if (!p1_sw_trig)
{
        rel1=0;
        relay1_fwd=0;
        relay1_rev=0;
}


rel1 and rel2 are simply declared as ints, where rel1 is initialized to 0, and rel2 to 1. This makes it go forward at first, then backwards the next time.

Essentially my method. ;)


All times are GMT -5. The time now is 02:16.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi