00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00035 #include <stdio.h>
00036 #include <errno.h>
00037 #include <helicontrol.h>
00038
00039 #define bound(min,num,max) ((num) >= (min) ? ((num) < (max) ? (num) : (max)) : (min))
00040
00041
00042
00043 struct usb_dev_handle *handle;
00044
00045 static void send_frame(char protocol, char channel, char throttle,
00046 char trim, char yaw, char pitch, char special)
00047 {
00048 int error;
00049
00050 switch (protocol)
00051 {
00052 case PROTO_PICOOZ:
00053 error = HC_Send_Picooz(handle, bound(0, channel-'a', 2), throttle, trim, yaw);
00054 break;
00055 case PROTO_CHALLENGER:
00056 error = HC_Send_Challenger(handle, bound(1, channel-'a'+1, 2), throttle, trim, yaw, special);
00057 break;
00058 case PROTO_URANUS:
00059 error = HC_Send_Uranus(handle, bound(0, channel-'a', 2), throttle, trim, yaw, pitch, special);
00060 break;
00061 case PROTO_TANDEMZ:
00062 error = HC_Send_Tandemz(handle, bound(0, channel-'a', 2), special, throttle, pitch, trim, yaw);
00063 break;
00064 case PROTO_SAUCER:
00065 error = HC_Send_Saucer(handle, special, pitch, throttle, yaw);
00066 break;
00067 default:
00068 error = -1;
00069 }
00070 if (error < 0)
00071 {
00072 puts("USB_control_msg error!");
00073 exit(EXIT_FAILURE);
00074 }
00075 }
00076
00077 int main(void)
00078 {
00079 char t, channel, throttle, trim, yaw, pitch, special, protocol = PROTO_CHALLENGER;
00080 int i;
00081
00082 handle = HC_Init();
00083 if (handle == NULL)
00084 {
00085 puts("USB device handle not found!");
00086 exit(EXIT_FAILURE);
00087 }
00088
00089 protocol = PROTO_PICOOZ;
00090 channel = 'a';
00091 throttle = 5;
00092 trim = 0;
00093 yaw = 0;
00094 pitch = 0;
00095 special = 0;
00096 for (i = 170; i>0; --i)
00097 {
00098 t = (i/3) % 28 + 1;
00099 if (t>14) t = 30 - t;
00100 if (1 == i) t = 0;
00101
00102 send_frame(protocol, channel, t , trim, yaw, pitch, special);
00103 #ifdef WIN32
00104 Sleep(150);
00105 #else
00106 usleep(150000);
00107 #endif
00108 }
00109
00110 HC_Close(handle);
00111
00112 exit(EXIT_SUCCESS);
00113 }
00114