helicontrol.c File Reference

Implementation of libhelicontrol, read me if you want to know how usb communication works in detail. More...

#include "../firmware/com_def.h"
#include "helicontrol.h"
#include "helicontrol_firmware.h"
#include "frame.h"
#include <string.h>
#include <stdio.h>

Include dependency graph for helicontrol.c:

Go to the source code of this file.

Defines

#define TIMEOUT_MS   2000

Functions

struct usb_dev_handle * HC_Init (void)
 try to open helicontrol usb device.
int HC_Read_Firmware_Revision (usb_dev_handle *handle, char *fwstring, size_t maxlen)
 read firmware revision from device
int HC_Read_Firmware_Build_Date (usb_dev_handle *handle, char *datestring, size_t maxlen)
void HC_Read_Lib_Build_Date (char *datestring, size_t maxlen)
int HC_CMD_Repeat (usb_dev_handle *handle, char repeat)
 switch continious sending.
int HC_CMD_Interval (usb_dev_handle *handle, int interval_ms)
 specifies rate at which commands are sent.
int HC_CMD_Stop (usb_dev_handle *handle)
 stop sending.
int HC_Send_Picooz (usb_dev_handle *handle, char channel, char throttle, char yaw, char trim)
 PicooZ.
int HC_Send_Challenger (usb_dev_handle *handle, char channel, char throttle, char yaw, char trim, char fire)
 Challanger.
int HC_Send_Uranus (usb_dev_handle *handle, char channel, char throttle, char yaw, char pitch, char trim, char light)
 Uranus.
int HC_Send_Tandemz (usb_dev_handle *handle, char channel, char throttle, char yaw, char pitch, char pitch_trim, char light)
 TandemZ.
int HC_Send_Ibird (usb_dev_handle *handle, char channel, char throttle, char yaw, char unknown, char checksum)
 i-Bird checksum algorithm is undetermined, but helicontrol firmware supports bit encoding for iBird, so checksum could be calculated/brute forced by host application
int HC_Send_Saucer (usb_dev_handle *handle, char throttle, char yaw, char pitch, char roll)
 saucer
void HC_Close (usb_dev_handle *handle)
 Close device.


Detailed Description

Implementation of libhelicontrol, read me if you want to know how usb communication works in detail.

.. Sorry, I am Q&D and don't come with helpful comments in the code :-(

Definition in file helicontrol.c.


Define Documentation

#define TIMEOUT_MS   2000

Definition at line 38 of file helicontrol.c.

Referenced by HC_CMD_Interval(), HC_CMD_Repeat(), HC_CMD_Stop(), HC_Send_Challenger(), HC_Send_Ibird(), HC_Send_Picooz(), HC_Send_Saucer(), HC_Send_Tandemz(), and HC_Send_Uranus().


Function Documentation

void HC_Close ( usb_dev_handle *  handle  ) 

Close device.

Please call me on exit.

Parameters:
handle handle of usb device (obtained by HC_Init())
See also:
HC_Init()
Examples:
helictrl.cc, helidemo_sdl.c, and helidemo_simple.c.

Definition at line 264 of file helicontrol.c.

Referenced by main().

int HC_CMD_Interval ( usb_dev_handle *  handle,
int  interval_ms 
)

specifies rate at which commands are sent.

See also:
HC_CMD_Repeat() which is used to enable continious sending.
Parameters:
handle handle of usb device (obtained by HC_Init())
interval_ms interval in ms between end of a frame and start of the next one. If 0 the interval will be reset to its default value (200ms)
Returns:
number of bytes written/read or < 0 on error. See libusb/usb_control_msg() documentation.
See also:
HC_CMD_Repeat

Definition at line 173 of file helicontrol.c.

int HC_CMD_Repeat ( usb_dev_handle *  handle,
char  repeat 
)

switch continious sending.

Note that all helis will stop after 300ms without command.

Parameters:
handle handle of usb device (obtained by HC_Init())yy
repeat 0/1 enable or disable automatic repetition for the last command
Returns:
number of bytes written/read or < 0 on error. See libusb/usb_control_msg() documentation.
See also:
HC_CMD_Interval
Examples:
helictrl.cc, and helidemo_sdl.c.

Definition at line 167 of file helicontrol.c.

Referenced by main().

int HC_CMD_Stop ( usb_dev_handle *  handle  ) 

stop sending.

Note that it is better to set throttle to 0 for an emergency stop of the heli. Otherwise stop will occur approx. 300ms after calling HC_CMD_Stop().

Parameters:
handle handle of usb device (obtained by HC_Init())
Returns:
number of bytes written/read or < 0 on error. See libusb/usb_control_msg() documentation.
Examples:
helictrl.cc, and helidemo_sdl.c.

Definition at line 179 of file helicontrol.c.

Referenced by main().

struct usb_dev_handle* HC_Init ( void   )  [read]

try to open helicontrol usb device.

If more than one is connected, returns handle to first device which has not been opened.

Returns:
ptr to usb device handle, if one is found. NULL on error.
See also:
HC_Close
Examples:
helictrl.cc, helidemo_sdl.c, and helidemo_simple.c.

Definition at line 40 of file helicontrol.c.

Referenced by main().

int HC_Read_Firmware_Build_Date ( usb_dev_handle *  handle,
char *  datestring,
size_t  maxlen 
)

Examples:
helictrl.cc.

Definition at line 139 of file helicontrol.c.

Referenced by main().

int HC_Read_Firmware_Revision ( usb_dev_handle *  handle,
char *  fwstring,
size_t  maxlen 
)

read firmware revision from device

Parameters:
handle handle of usb device (obtained by HC_Init())
fwstring pointer to memory where revision string will be stored to (null-terminated).
maxlen maximum length of string, including tailing null.
Returns:
something < 0 on error.
Examples:
helictrl.cc.

Definition at line 118 of file helicontrol.c.

Referenced by HC_Init(), and main().

void HC_Read_Lib_Build_Date ( char *  datestring,
size_t  maxlen 
)

Examples:
helictrl.cc.

Definition at line 160 of file helicontrol.c.

Referenced by main().

int HC_Send_Challenger ( usb_dev_handle *  handle,
char  channel,
char  throttle,
char  yaw,
char  trim,
char  fire 
)

Challanger.

Parameters:
handle handle of usb device (obtained by HC_Init())
channel channel, 0..2 for A..C, see down side of heli
throttle throttle, 0..15
trim yaw trim, 1 = right, 0 = normal, -1 = left (trim value is stored in helicopter and only increased, when the trim bits are different from the previous frame)
yaw yaw, 1..3 left, 0 center, -1..-3 right
fire 0/1, triggers "fire" LED in helicopter when set to 1
Returns:
Examples:
helictrl.cc, helidemo_sdl.c, and helidemo_simple.c.

Definition at line 197 of file helicontrol.c.

Referenced by send_frame().

int HC_Send_Ibird ( usb_dev_handle *  handle,
char  channel,
char  throttle,
char  yaw,
char  unknown,
char  checksum 
)

i-Bird checksum algorithm is undetermined, but helicontrol firmware supports bit encoding for iBird, so checksum could be calculated/brute forced by host application

Parameters:
handle handle of usb device (obtained by HC_Init())
channel channel, 2 bits
throttle throttle, 0..15
yaw yaw, 3 bits
unknown 5 bits, unknown purpose
checksum 5 bit checksum, algorithm undetermined
Returns:
number of bytes written/read or < 0 on error. See libusb/usb_control_msg() documentation.

Definition at line 239 of file helicontrol.c.

int HC_Send_Picooz ( usb_dev_handle *  handle,
char  channel,
char  throttle,
char  yaw,
char  trim 
)

PicooZ.

Parameters:
handle handle of usb device (obtained by HC_Init())
channel channel, 0..2 for A..C, see down side of heli
throttle throttle, 0..15
trim yaw trim, 1 = right, 0 = normal, -1 = left (trim value is stored in helicopter and only increased, when the trim bits are different from the previous frame)
yaw yaw, 1..3 left, 0 center, -1..-3 right
Returns:
number of bytes written/read or < 0 on error. See libusb/usb_control_msg() documentation.
Examples:
helictrl.cc, helidemo_sdl.c, and helidemo_simple.c.

Definition at line 185 of file helicontrol.c.

Referenced by send_frame().

int HC_Send_Saucer ( usb_dev_handle *  handle,
char  throttle,
char  yaw,
char  pitch,
char  roll 
)

saucer

Parameters:
handle handle of usb device (obtained by HC_Init)
roll roll, -7..7, negative = left, positive = right
pitch pitch, -7..7, negative = forward, positive = backward
throttle throttle, 0..15
yaw yaw, -7..7, negative = left, positive = right
Returns:
number of bytes written/read or < 0 on error. See libusb/usb_control_msg() documentation.
Examples:
helictrl.cc, helidemo_sdl.c, and helidemo_simple.c.

Definition at line 252 of file helicontrol.c.

Referenced by send_frame().

int HC_Send_Tandemz ( usb_dev_handle *  handle,
char  channel,
char  throttle,
char  yaw,
char  pitch,
char  pitch_trim,
char  light 
)

TandemZ.

Parameters:
handle handle of usb device (obtained by HC_Init())
channel channel, 0..2 for A..C, see down side of heli
light 0/1, turns on light when 1
throttle throttle, 0..15
pitch 0..1 = backwards, 2 = neutral/hover, 3..5 = forward
pitch_trim 0..31, 0 = max. forward, 31 = max. backwards
yaw 0..31, 0 = full left, 31 = full forward, center depends on helicopter (the original rc adds yaw trim to this value), steps 3-5, 19-22 and 27-29 are not valid, the helicontrol firmware will map those values to the nearest valid step
Returns:
number of bytes written/read or < 0 on error. See libusb/usb_control_msg() documentation.
Examples:
helictrl.cc, helidemo_sdl.c, and helidemo_simple.c.

Definition at line 224 of file helicontrol.c.

Referenced by send_frame().

int HC_Send_Uranus ( usb_dev_handle *  handle,
char  channel,
char  throttle,
char  yaw,
char  pitch,
char  trim,
char  light 
)

Uranus.

Parameters:
handle handle of usb device (obtained by HC_Init())
channel channel, 0..2 for A..C, see down side of heli
throttle throttle, 0..15
trim yaw trim, 1 = right, 0 = normal, -1 = left (trim value is stored in helicopter and only increased, when the trim bits are different from the previous frame)
yaw yaw, 1..3 left, 0 center, -1..-3 right
pitch 0..2, 0 = neutral/hover, 1 = slow boost, 2 = fast boost, 3 = continuous boost
light 0/1, turns on light when 1
Returns:
number of bytes written/read or < 0 on error. See libusb/usb_control_msg() documentation.
Examples:
helictrl.cc, helidemo_sdl.c, and helidemo_simple.c.

Definition at line 210 of file helicontrol.c.

Referenced by send_frame().


Generated on Thu Dec 18 00:02:52 2008 for libhelicontrol by  doxygen 1.5.3