[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

How do i cast this?



I'm having the following situation:

I have a global variabele that is declared in main.c, the variabele
holds the status of the parallel port.  Now and then I have to write
that variabele to the parallel port to control a stepper motor:

gint mot_portstatus=0;

I want to set this global variabele in a file called motor.c with the
following callback function:

/* --- Setting full step requires the bit on pin4 (Data2) 
 * --- to be LOW
 */
void mot_set_full_step(GtkWidget *widget, gpointer user_data)
{
 (int)user_data=(int)user_data & (~0x04);
 g_print("%d\n", (int)user_data);	// for debugging
}

I think that the casting I'm using right now isn't correct because the
values that are sent to the parallell port aren't correct when i start
turning the motor with other callback functions. I have tried different
castings such as:

(int)user_data
-> seems to set the values fine, but when i start to turn the motor with
the following functions:

void mot_turn_left(GtkWidget *widget, gpointer user_data)
{
 mot_set_left((int *)&user_data);
 mot_turn((int *)&user_data);
}

/* --- Sending a clock signal to the L297N is giving a clock HIGH
signal,
 * --- followed by a clock LOW signal on pin 3 (Data1)
 */
void mot_turn(int *user_data)
{
 mot_turn_ok=TRUE;
 g_print("%d\n", *user_data);
 while ( mot_turn_ok ) {
   *user_data = *user_data | 0x02;
   outb(*user_data, BASEPORT);
   g_print("%d\n", *user_data);  				// for debugging
   g_print("clock_time_high: %d\n", mot_clock_time_high);	// for
debugging
   usleep(mot_clock_time_high*1000);
   *user_data = *user_data & (~0x02);
   outb(*user_data, BASEPORT);
   g_print("%d\n", *user_data);					// for debugging
   g_print("clock_time_low: %d\n", mot_clock_time_low);		// for
debugging
   usleep(mot_clock_time_low*1000);
   while(gtk_events_pending()) gtk_main_iteration(); }
}

then i don't get the right values sent to the parallel port.


(int *)user_data
-> this gives me an error at compilation:
motor.c: In function `mot_set_full_step':
motor.c:39: invalid operands to binary &
motor.c:40: warning: int format, pointer arg (arg 2)

*((int *)user_data)
-> gives me a segmentation fault and program kills itself (strange,
because I think this is the right casting method...)

Can someone get me out of my misery?  The full program can be found at
http://hello.to/MC303  -> follow the link to 'My Thesis' on the left.

Thanks!


-- 
Bart Vandewoestyne		http://hello.to/MC303		
Hugo Verrieststraat 48		Bart.Vandewoestyne@skynet.be
8550 ZWEVEGEM			ICQ# 21275340
BELGIUM - EUROPE		nick: MC303
Phone: +32(0)56/75.48.11
-------------------------------------------------------------
"If we knew what it was we were doing, it would not
 be called research, would it?"
				-- Albert Einstein --



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]