Controlling the Stylus

While the user controls stylus movement and button presses, your application can cause the stylus to vibrate or make the LED lights on the stylus turn on. Vibration can help the user identify when the stylus is intersecting a selectable object or UI control. A subtle vibration provides haptic feedback, suggesting that something is "touched."

Stylus Vibration

The following partial code example illustrates enabling vibration, defining the vibration settings, and starting the vibration. For brevity, error handling is omitted. For the complete sample code, refer to the Stylus Vibrate sample application in the Samples\Device subdirectory.

  // zSpaceContext set during initialization. 
  // ZSContext zSpaceContext = ...; 
  // Get the stylus target.
  ZSHandle stylusHandle = NULL;
  zsFindTargetByType(zSpaceContext, ZS_TARGET_TYPE_PRIMARY, 0, &stylusHandle);

  // Enable the stylus vibration capability. 
  zsSetTargetVibrationEnabled(stylusHandle, true);

  // Specify an on period, off period, and number of times such that 
  // the stylus will vibrate for 1 second and pause for 
  // 2 seconds. This will occur four times.
  ZSFloat onPeriod    = 1.0f;
  ZSFloat offPeriod   = 2.0f;
  ZSInt32 numTimes    = 4;

  // Start the vibration. 
  zsStartTargetVibration(stylusHandle, onPeriod, offPeriod, numTimes);

In the above example, we define the length of time the stylus vibrates (on period), the length of time it pauses (off period), and the number of times it vibrates.

If you need to interrupt the vibration before it ends, call zsStopTargetVibration().

LED Light

The LED light's meaning may not be clear to your users, so you might combine it with other feedback. For example, you might display a warning dialog and cause the LED light to turn red. The Target LED API has functions you can use to set the LED color, turn it on, and turn it off. For an example, refer to the Stylus LED sample application in the Samples\Device subdirectory.