Re: [Emc-users] Joypad Example

2008-03-02 Thread Jeff Epler
On Sun, Mar 02, 2008 at 10:34:28PM -0500, Stephen Wille Padnos wrote:
 The reason is that there's no way to get a complete list of all joystick
 devices (axes and buttons) before you get the first event.  If you try
 to enumerate all the axes first, and the joystick gets moved while
 you're doing it, then there will be a motion event thrown in the middle
 of the capabilities enumeration.  Also, there's no that's it, those are
 all the buttons I've got message.  You can get notified of a new button
 or axis at any time.  So, the best thing to do is to just start the
 event loop, and if you receive an event that says this is analog axis
 #7, just export a HAL pin.  If it's a button or motion event, then
 change the appropriate HAL pin.
 
 (at least that's my recollection of the issues jmkasunich had to deal
 with when writing the driver in the first place)

And for this reason, the driver is broken (strictly speaking) -- all
userspace drivers must call hal_ready() after creating all pins.  This
is what allows halcmd 'loadusr -W' to wait the proper amount of time
before executing the following commands.

Jeff

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Joypad Example

2008-02-23 Thread ben lipkowitz
On Fri, 22 Feb 2008, Kirk Wallace wrote:
 Another bit I don't understand:

/* STEP 3: allocate shared memory for joystick data */
js_data = (hal_js_t *) hal_malloc(sizeof(hal_js_t));
if (js_data == 0) {
   printf( ERROR: hal_malloc() failed\n);
   hal_exit(comp_id);
   return -1;
}

 hal_js_t is a defined variable type.
 sizeof(hal_js_t) is the memory size of this type.
 hal_malloc(sizeof(hal_js_t)) returns the memory location of this
 variable.
 I don't understand what (hal_js_t *) does. hal_js_t is a type so it is
 similar to (int *)?

hal_malloc returns a (void *) pointer; this would presumably make 
subsequent code complain about pointer mismatches, and the compiler 
wouldn't know where to look in the data structure for variables like 
(js_data-axis[n]). the (hal_js_t *) casts the returned pointer to the 
correct pointer type.

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Joypad Example

2008-02-23 Thread Kirk Wallace
On Sat, 2008-02-23 at 07:52 +, ben lipkowitz wrote:
 On Fri, 22 Feb 2008, Kirk Wallace wrote:
  Another bit I don't understand:
 
 /* STEP 3: allocate shared memory for joystick data */
 js_data = (hal_js_t *) hal_malloc(sizeof(hal_js_t));
 if (js_data == 0) {
  printf( ERROR: hal_malloc() failed\n);
  hal_exit(comp_id);
  return -1;
 }
 
  hal_js_t is a defined variable type.
  sizeof(hal_js_t) is the memory size of this type.
  hal_malloc(sizeof(hal_js_t)) returns the memory location of this
  variable.
  I don't understand what (hal_js_t *) does. hal_js_t is a type so it is
  similar to (int *)?
 
 hal_malloc returns a (void *) pointer; this would presumably make 
 subsequent code complain about pointer mismatches, and the compiler 
 wouldn't know where to look in the data structure for variables like 
 (js_data-axis[n]). the (hal_js_t *) casts the returned pointer to the 
 correct pointer type.

Thanks Ben. The cast makes sense. I think of void as being an invention
to allow functions that return nothing, so the function return type
(void *) tells me that a pointer is returned that points to a
nonexistent variable. Is the (void *) just a reminder to always cast the
return pointer to the variable type we happen to need?

-- 
Kirk Wallace (California, USA
http://www.wallacecompany.com/machine_shop/ 
Hardinge HNC lathe,
Bridgeport mill conversion, doing XY now,
Zubal lathe conversion pending)


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


[Emc-users] Joypad Example

2008-02-22 Thread Kirk Wallace
I think hal_joystick.c:

http://cvs.linuxcnc.org/cgi-bin/cvsweb.cgi/emc2/src/hal/user_comps/devices/hal_joystick.c?rev=1.2;content-type=text%2Fplain

might be a good model to follow for making my modbus user-land
component. My guess would be that one would setup HAL and the the HAL
pins and then loop to update the inputs and outputs, but the joystick
pins are set up in the main loop. Why is that?

There is a prefix parameter used to name the pins and buttons but not
the component itself:
...
snprintf(name, HAL_NAME_LEN-1, hal_joystick-%d, getpid());
comp_id = hal_init(name);
...
Is there a reason not to use the prefix here?

Thanks.

-- 
Kirk Wallace (California, USA
http://www.wallacecompany.com/machine_shop/ 
Hardinge HNC lathe,
Bridgeport mill conversion, doing XY now,
Zubal lathe conversion pending)


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users


Re: [Emc-users] Joypad Example

2008-02-22 Thread Kirk Wallace
On Fri, 2008-02-22 at 17:51 -0800, Kirk Wallace wrote:
 I think hal_joystick.c:
 
 http://cvs.linuxcnc.org/cgi-bin/cvsweb.cgi/emc2/src/hal/user_comps/devices/hal_joystick.c?rev=1.2;content-type=text%2Fplain
 
 might be a good model to follow for making my modbus user-land
 component. My guess would be that one would setup HAL and the the HAL
 pins and then loop to update the inputs and outputs, but the joystick
 pins are set up in the main loop. Why is that?
 
 There is a prefix parameter used to name the pins and buttons but not
 the component itself:
 ...
 snprintf(name, HAL_NAME_LEN-1, hal_joystick-%d, getpid());
 comp_id = hal_init(name);
 ...
 Is there a reason not to use the prefix here?
 
 Thanks.
 

Another bit I don't understand:

/* STEP 3: allocate shared memory for joystick data */
js_data = (hal_js_t *) hal_malloc(sizeof(hal_js_t));
if (js_data == 0) {
printf( ERROR: hal_malloc() failed\n);
hal_exit(comp_id);
return -1;
}

hal_js_t is a defined variable type.
sizeof(hal_js_t) is the memory size of this type.
hal_malloc(sizeof(hal_js_t)) returns the memory location of this
variable.
I don't understand what (hal_js_t *) does. hal_js_t is a type so it is
similar to (int *)?

-- 
Kirk Wallace (California, USA
http://www.wallacecompany.com/machine_shop/ 
Hardinge HNC lathe,
Bridgeport mill conversion, doing XY now,
Zubal lathe conversion pending)


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users