/Riddim/Moved.txt |
---|
File deleted |
/Riddim/Makefile |
---|
0,0 → 1,12 |
# Makefile for Riddim |
# |
# |
CC=gcc |
CFLAGS+=-Wall -g |
LDFLAGS+=-g -lusb -lbluetooth -lconfuse |
riddim: config.o statistics.o fc.o joy_handler.o evdev_handler.o bluetooth_handler.o riddim.o lib/x52/x52.o |
clean: |
rm -f *.o riddim *~ lib/*/*.o |
/Riddim/README |
---|
0,0 → 1,54 |
# RIDDIM |
# |
# -> Remote Interactive Digital Drone Interface Mashup |
# |
# Author: Marcus -ligi- Bueschleb |
# |
# Contact: ligi |
# -at- |
# smart4mobile.de |
# |
# Project Start: 12/2007 |
# |
# Credits: |
# Holger & Ingo for the Mikrokopter Project ( www.mikrokopter.de ). |
# eduard -- - at - -- hasenleithner.at for the linux x-52 lib |
# Jo aka XM for helping with openwrt |
# sublab.org for infrastructure |
= Documentation / Infos = |
http://www.mikrokopter.de/ucwiki/en/Riddim |
= Licence = |
http://creativecommons.org/licenses/by-nc-sa/2.0/de/ (Creative Commons / Non Commercial / Share Alike |
Addtitonally to this Licence it is not allowed to use this software in any violent manner. |
This explicitly includes that lethal Weapon owning "People" (e.g. Army & Police) are not allowed to use this Project |
If you want to use this tool in any Commercial Context - please contact me first! |
=Compile= |
$> make |
=Run= |
$> ./riddim [configfile] |
if no configfile is given riddim is trying to load "/etc/riddim.conf". If that fails riddim is using default values ( not very usefull perhaps ) |
example socat usage: |
socat tcp-l:54321,reuseaddr,fork file:/dev/ttyUSB0,b57600,waitlock=/var/run/rfcomm0.lock |
= Changelog = |
0.8 - Modify altitude by input |
0.7 - new MK Protocol |
0.6 - misc |
0.5 - code cleanup |
0.4 - Measure time from send command to confirm |
0.3 - mode selector |
0.2 - first version with possibility to fly ( based on FC0.68b commands ) |
0.1 - initial release with basic functions and proove of concept Code ( Scanning for Blueooth Devices / read Joy / communicate to MK / ..) |
/Riddim/bluetooth_handler.c |
---|
0,0 → 1,439 |
#include "bluetooth_handler.h" |
int bt_device_count=0; |
char names[MAX_BT_DEVICES][248]; |
char addrs[MAX_BT_DEVICES][19]; |
char BtHostRxBuffer[150]; |
char BtHostRxBufferDecoded[150]; |
int BtRxCount; |
int scan_bt() |
{ |
inquiry_info *ii = NULL; |
int dev_id, sock, len, flags; |
int i; |
char addr[19] = { 0 }; |
char name[248] = { 0 }; |
dev_id = hci_get_route(NULL); |
sock = hci_open_dev( dev_id ); |
if (dev_id < 0 || sock < 0) { |
perror("opening socket"); |
return 0; |
} |
len = 8; |
flags = IREQ_CACHE_FLUSH; |
ii = (inquiry_info*)malloc(MAX_BT_DEVICES * sizeof(inquiry_info)); |
bt_device_count = hci_inquiry(dev_id, len, MAX_BT_DEVICES, NULL, &ii, flags); |
if( bt_device_count < 0 ) perror("hci_inquiry"); |
for (i = 0; i < bt_device_count; i++) { |
ba2str(&(ii+i)->bdaddr, addr); |
sprintf(addrs[i],"%s",addr); |
memset(name, 0, sizeof(name)); |
if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name), |
name, 0) < 0) |
sprintf(names[i],"[unknown]"); |
else |
sprintf(names[i],"%s",name); |
} |
free( ii ); |
close( sock ); |
return 1; |
} |
//struct timeval timeout; |
fd_set readfds, writefds; |
int s; |
struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 }; |
char buf[1024] = { 0 }; |
int client, bytes_read, status; |
unsigned int opt = sizeof(rem_addr); |
int maxfd, sock_flags; |
unsigned char BT_TxBuffer[MAX_BUFF_LEN]; |
extern struct str_DebugOut DebugOut; |
struct str_VersionInfo VersionInfo; |
int bt_host_init() |
{ |
// allocate socket |
s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); |
// bind socket to port 1 of the first available bluetooth adapter |
loc_addr.rc_family = AF_BLUETOOTH; |
loc_addr.rc_bdaddr = *BDADDR_ANY; |
loc_addr.rc_channel = 1; |
bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr)); |
// put server socket into listening mode |
listen(s, 1); |
// put server socket into nonblocking mode |
sock_flags = fcntl( s, F_GETFL, 0 ); |
fcntl( s, F_SETFL, sock_flags | O_NONBLOCK ); |
return 1; |
} |
int bt_host_connected=0; |
int bt_host_send(char RxBuffer[150],int len) |
{ |
if (bt_host_connected) |
{ |
send(client,"\r",1,0); |
send(client,RxBuffer,len,0); |
send(client,"\r",1,0); |
} |
return 1; |
} |
struct { |
unsigned char MenuePunkt; |
unsigned char MaxMenue; |
char DisplayBuff[80]; |
} menu; |
void copy_lcd_str(int x,int y,char str[]) |
{ |
int pos=0; |
while (str[pos]!=0) |
{ |
menu.DisplayBuff[y*20+x+pos]=str[pos]; |
pos++; |
} |
} |
void Menu(void) |
{ |
// menu.MenuePunkt=0; |
menu.MaxMenue=3; |
int x; |
int y; |
char tmp_str[20]; |
for (x=0;x<20;x++) |
for (y=0;y<4;y++) |
menu.DisplayBuff[y*20+x]=' '; |
switch(menu.MenuePunkt) |
{ |
case 0: |
// LCD_printfxy(0,0,"+ Riddim +"); |
/* LCD_printfxy(0,1,"Version: %d %d",0,8); |
LCD_printfxy(0,2,""); |
LCD_printfxy(0,3,"(cc) 2009 ligi"); |
*/ |
// clear_lcd |
sprintf(tmp_str,"+ Riddim +"); |
copy_lcd_str(0,0,tmp_str); |
sprintf(tmp_str,"Version: V%d.%d/%d",RIDDIM_VERSION_MAJOR,RIDDIM_VERSION_MINOR,RIDDIM_VERSION_PATCH); |
copy_lcd_str(0,1,tmp_str); |
sprintf(tmp_str,"(cc) 2009 LiGi"); |
copy_lcd_str(0,3,tmp_str); |
// sprintf(&menu.DisplayBuff,"+ Riddim ++"); |
// sprintf(&menu.DisplayBuff+20,"Version: %d %d",0,8); |
break; |
case 1: |
sprintf(tmp_str,"Loop:"); |
copy_lcd_str(0,0,tmp_str); |
sprintf(tmp_str," Count %ld",trip_count); |
copy_lcd_str(0,1,tmp_str); |
sprintf(tmp_str," Time %ld",last_trip_time); |
copy_lcd_str(0,2,tmp_str); |
break; |
case 2: |
sprintf(tmp_str,"Inputs:"); |
copy_lcd_str(0,0,tmp_str); |
sprintf(tmp_str," Complete %d",evdevs_count); |
copy_lcd_str(0,1,tmp_str); |
sprintf(tmp_str," Connected %d",input_count); |
copy_lcd_str(0,2,tmp_str); |
sprintf(tmp_str," Configured %d",configured_input_count); |
copy_lcd_str(0,3,tmp_str); |
break; |
case 3: |
sprintf(tmp_str,"Nick: %d",act_nick); |
copy_lcd_str(0,0,tmp_str); |
sprintf(tmp_str,"Roll %d",act_roll); |
copy_lcd_str(0,1,tmp_str); |
sprintf(tmp_str,"Gier %d",act_gier); |
copy_lcd_str(0,2,tmp_str); |
sprintf(tmp_str,"Gas %d",act_gas); |
copy_lcd_str(0,3,tmp_str); |
break; |
default: |
sprintf(tmp_str,"illegal page %d",menu.MenuePunkt); |
copy_lcd_str(0,0,tmp_str); |
break; |
} |
} |
void BT_Decode64(void) // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden. |
{ |
unsigned char a,b,c,d; |
unsigned char x,y,z; |
unsigned char ptrIn = 3; // start at begin of data block |
unsigned char ptrOut = 0; |
unsigned char len = BtRxCount - 5; // von der Gesamtbytezahl eines Frames gehen 3 Bytes des Headers ('#',Addr, Cmd) und 3 Bytes des Footers (CRC1, CRC2, '\r') ab. |
while(len) |
{ |
a = BtHostRxBuffer[ptrIn++] - '='; |
b = BtHostRxBuffer[ptrIn++] - '='; |
c = BtHostRxBuffer[ptrIn++] - '='; |
d = BtHostRxBuffer[ptrIn++] - '='; |
x = (a << 2) | (b >> 4); |
y = ((b & 0x0f) << 4) | (c >> 2); |
z = ((c & 0x03) << 6) | d; |
printf("\naaaaa %d / %d\naaaaa s %s => x %d ; y %d ; z %d \n",ptrOut, BtRxCount ,BtHostRxBuffer,x,y,z); |
if(len--) BtHostRxBufferDecoded[ptrOut++] = x; else break; |
if(len--) BtHostRxBufferDecoded[ptrOut++] = y; else break; |
if(len--) BtHostRxBufferDecoded[ptrOut++] = z; else break; |
} |
//RxDataLen = ptrOut ; // wie viele Bytes wurden dekodiert? |
} |
void BT_AddCRC(unsigned int wieviele) |
{ |
unsigned int tmpCRC = 0,i; |
for(i = 0; i < wieviele;i++) |
{ |
tmpCRC += BT_TxBuffer[i]; |
} |
tmpCRC %= 4096; |
BT_TxBuffer[i++] = '=' + tmpCRC / 64; |
BT_TxBuffer[i++] = '=' + tmpCRC % 64; |
BT_TxBuffer[i++] = '\r'; |
} |
void BT_SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
{ |
// return; |
int status =0; |
unsigned int pt = 0; |
unsigned char a,b,c; |
unsigned char ptr = 0; |
printf("packing base len %d -cmd %c\n",len,cmd); |
BT_TxBuffer[pt++] = '#'; // Startzeichen |
BT_TxBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
BT_TxBuffer[pt++] = cmd; // Commando |
while(len) |
{ |
if(len) { a = snd[ptr++]; len--;} else a = 0; |
if(len) { b = snd[ptr++]; len--;} else b = 0; |
if(len) { c = snd[ptr++]; len--;} else c = 0; |
BT_TxBuffer[pt++] = '=' + (a >> 2); |
BT_TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
BT_TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
BT_TxBuffer[pt++] = '=' + ( c & 0x3f); |
} |
BT_AddCRC(pt); |
printf("Sending to BT_Client %d \n" , pt); |
status = send(client,"\r" , 1, 0); |
// for (c=0;c<pt+2;c++) |
// { |
status = write(client,&BT_TxBuffer , pt+3); |
status = send(client,"\r" , 1, 0); |
printf("\n"); |
} |
void bt_process_buffer() |
{ |
printf("processing buffer\n"); |
switch(BtHostRxBuffer[2]) |
{ |
case 'v': |
printf("got version request\n"); |
VersionInfo.SWMinor=RIDDIM_VERSION_MINOR; |
VersionInfo.SWMajor=RIDDIM_VERSION_MAJOR; |
VersionInfo.SWPatch=RIDDIM_VERSION_PATCH; |
BT_SendOutData('V', RIDDIM_ADDRESS, (unsigned char *) &VersionInfo, sizeof(VersionInfo)); |
break; |
case 'l': |
printf("got display request\n"); |
Menu(); |
menu.MenuePunkt=BtHostRxBufferDecoded[0]; |
printf("sending %s \n",menu.DisplayBuff); |
BT_SendOutData('L', RIDDIM_ADDRESS, (unsigned char *) &menu, sizeof(menu)); |
break; |
} |
} |
int r=0; |
struct timeval last_debug_time; |
struct timeval act_time; |
int bt_host_tick(int mk_fd) |
{ |
// try to accept connection if none yet |
if (!bt_host_connected) |
{ |
// timeout.tv_sec = 0; |
// timeout.tv_usec = 100; |
FD_ZERO(&readfds); |
FD_ZERO(&writefds); |
FD_SET(s, &readfds); |
maxfd = s; |
printf("waiting for bt connection\n"); |
// status = select(maxfd + 1, &readfds, &writefds, 0, &timeout); |
status = select(maxfd + 1, &readfds, &writefds, 0,& (struct timeval) { 0, 100 }); |
if( status > 0 && FD_ISSET( s, &readfds ) ) { |
// incoming connection |
client = accept( s, (struct sockaddr*)&rem_addr, &opt ); |
if( client >= 0 ) |
{ |
bt_host_connected=1; |
// close the server socket, leaving only the client socket open |
// close(s); |
ba2str( &rem_addr.rc_bdaddr, buf ); |
fprintf(stderr, "accepted connection from %s!!!!!!!\n", buf); |
memset(buf, 0, sizeof(buf)); |
// put client socket into nonblocking mode |
sock_flags = fcntl( client, F_GETFL, 0 ); |
fcntl( client, F_SETFL, sock_flags | O_NONBLOCK ); |
} |
} |
} |
else |
{ |
gettimeofday(&act_time,NULL); |
if (act_time.tv_sec>last_debug_time.tv_sec) |
{ |
DebugOut.Analog[9]=23; // voltage |
DebugOut.Analog[5]=23; // alt |
BT_SendOutData('D', RIDDIM_ADDRESS, (unsigned char *) &DebugOut, sizeof(DebugOut)); |
gettimeofday(&last_debug_time,NULL); |
} |
printf("reading from bt_host"); |
char in_char='#'; |
int count=0; |
struct timeval timeout; |
timeout.tv_sec = 0; |
timeout.tv_usec = 100; |
FD_ZERO(&readfds); |
FD_ZERO(&writefds); |
FD_SET(client, &readfds); |
maxfd = client; |
printf("waiting for connection\n"); |
status = select(maxfd + 1, &readfds, 0, 0, &timeout); |
if( status >0 ) |
{ |
count=read(client,&in_char,1); |
//send(mk_fd,"\r",1,0); |
if (count==-1) |
{ |
bt_host_connected=0; |
//return 0; |
} |
else |
if(in_char!='\r') |
{ |
printf("count: %d in %d chr %c r:%d\n",count,in_char,in_char,r); |
//send(mk_fd,&in_char,1,0); |
BtHostRxBuffer[r++]=in_char; |
} |
else |
{ |
BtRxCount=r; |
r=0; |
BT_Decode64(); |
bt_process_buffer(); |
} |
// send(mk_fd,"\r",1,0); |
} |
else |
return 0; |
} |
return 1; |
} |
/Riddim/bluetooth_handler.h |
---|
0,0 → 1,57 |
#if !defined(BLUETOOTH_HANDLER_H) |
#define BLUETOOTH_HANDLER_H |
#define RIDDIM_ADDRESS 12+'a' |
#include <bluetooth/bluetooth.h> |
#include <bluetooth/rfcomm.h> |
#include <bluetooth/hci.h> |
#include <bluetooth/hci_lib.h> |
#include <unistd.h>//for close() for socket |
#include <stdlib.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <fcntl.h> |
#include <errno.h> |
#include <sys/types.h> |
#include <netinet/in.h> |
#include <sys/time.h> |
#include <unistd.h>//for close() for socket |
#include <string.h> |
#include "riddim_meta.h" |
#include "statistics.h" |
#include "config.h" |
#include "riddim.h" |
#include "fc.h" |
#define MAX_BT_DEVICES 3 |
extern int bt_device_count; |
extern char names[MAX_BT_DEVICES][248]; |
extern char addrs[MAX_BT_DEVICES][19]; |
int scan_bt(); |
int bt_host_tick(int mk_fd); |
int bt_host_init(); |
int bt_host_send(char RxBuffer[150],int len); |
#define MAX_BUFF_LEN 150 |
extern struct str_DebugOut DebugOut; |
extern struct str_VersionInfo VersionInfo; |
#endif |
/Riddim/config/riddim.conf |
---|
0,0 → 1,21 |
# Riddim Config File |
input_evdev = "/dev/input/event14" |
mk_socket_port = 5432 |
#1 |
#loop_delay=20000 |
loop_delay=90000 |
#loop_delay=50000 |
#loop_delay=500000 |
# to check how the system was inited |
exit_after_init=false |
#exit_after_init=true |
#bluetooth_mac="00:0B:CE:01:2E:00" |
gas_mul=0.3 |
rel_axis_gas=2 |
nick_mul=-0.3 |
/Riddim/config/riddim_av8r.conf |
---|
0,0 → 1,27 |
# Riddim Config File |
input_evdev = "/dev/input/event10" |
mk_socket_port = 5432 |
#1 |
#1 |
#loop_delay=20000 |
#working loop_delay=90000 |
loop_delay=600000 |
#loop_delay=50000 |
#loop_delay=500000 |
# to check how the system was inited |
#exit_after_init=false |
exit_after_init=true |
#bluetooth_mac="00:0B:CE:01:2E:00" |
gas_mul=0.003 |
rel_axis_gas=2 |
nick_mul=-0.003 |
roll_mul=0.003 |
gier_mul=0.003 |
rel_axis_gier=3 |
/Riddim/config/riddim_logitech.conf |
---|
0,0 → 1,33 |
# Riddim Config File |
input_evdev = "/dev/input/event10" |
mk_socket_port = 54321 |
#1 |
#loop_delay=20000 |
loop_delay=90000 |
#loop_delay=50000 |
#loop_delay=500000 |
# to check how the system was inited |
exit_after_init=false |
#exit_after_init=true |
#bluetooth_mac="00:0B:CE:01:2E:00" |
gas_mul=0.3 |
#rel_axis_gas=2 |
nick_mul=-0.3 |
rel_axis_roll=2 |
rel_axis_nick=5 |
rel_axis_gas=1 |
rel_axis_gier=0 |
gas_mul=-0.8 |
# a2->roll |
# a5 -> nick |
# a0 -> gas |
# a1 -> gier |
/Riddim/config/riddim_spacemouse.conf |
---|
0,0 → 1,21 |
# Riddim Config File |
input_evdev = "/dev/input/event10" |
mk_socket_port = 54321 |
#loop_delay=20000 |
loop_delay=90000 |
#loop_delay=50000 |
#loop_delay=500000 |
# to check how the system was inited |
exit_after_init=false |
#exit_after_init=true |
#bluetooth_mac="00:0B:CE:01:2E:00" |
gas_mul=0.3 |
rel_axis_gas=2 |
nick_mul=-0.3 |
/Riddim/config/test.conf |
---|
0,0 → 1,24 |
# Riddim Config File |
#input_evdev = "/dev/input/event14" |
input_joydev = "/dev/input/js0" |
mk_socket_port = 5432 |
#1 |
#loop_delay=20000 |
loop_delay=90000 |
#loop_delay=50000 |
#loop_delay=500000 |
# to check how the system was inited |
exit_after_init=true |
#bluetooth_mac="00:0B:CE:01:2E:00" |
gas_mul=0.3 |
rel_axis_gas=2 |
nick_mul=-0.3 |
/Riddim/config.c |
---|
0,0 → 1,183 |
#include "config.h" |
char *input_evdev_name; |
char *input_joydev_name; |
char *bluetooth_mac; |
char *mk_tty; |
char *evdev_path; |
int mk_socket_port=0; |
int loop_delay=0; |
double nick_mul=0.3f; |
double roll_mul=0.3f; |
double gier_mul=0.3f; |
double gas_mul=0.3f; |
double nick_add=0.3f; |
double roll_add=0.3f; |
double gier_add=0.3f; |
double gas_add=0.3f; |
int rel_axis_nick; |
int rel_axis_roll; |
int rel_axis_gier; |
int rel_axis_gas; |
cfg_bool_t exit_after_init = cfg_false; |
int input_count=0; |
int configured_input_count=0; |
cfg_t *cfg; |
void parse_config(char* fname) |
{ |
// section for inputs |
static cfg_opt_t input_opts[] = { |
CFG_STR("name", 0, CFGF_NONE), |
CFG_FLOAT("nick_mul", 1.0,CFGF_NONE), |
CFG_FLOAT("roll_mul", 1.0,CFGF_NONE), |
CFG_FLOAT("gier_mul", 1.0,CFGF_NONE), |
CFG_FLOAT("gas_mul", 1.0,CFGF_NONE), |
CFG_FLOAT("alt_mul", 1.0,CFGF_NONE), |
CFG_FLOAT("nick_add", 0,CFGF_NONE), |
CFG_FLOAT("roll_add", 0,CFGF_NONE), |
CFG_FLOAT("gier_add", 0,CFGF_NONE), |
CFG_FLOAT("gas_add", 0,CFGF_NONE), |
CFG_INT("rel_axis_nick", -1,CFGF_NONE), |
CFG_INT("rel_axis_roll", -1,CFGF_NONE), |
CFG_INT("rel_axis_gier", -1,CFGF_NONE), |
CFG_INT("rel_axis_gas", -1,CFGF_NONE), |
CFG_INT("rel_axis_alt", -1,CFGF_NONE), |
CFG_INT("nick_up_btn", -1,CFGF_NONE), |
CFG_INT("nick_down_btn", -1,CFGF_NONE), |
CFG_INT("roll_left_btn", -1,CFGF_NONE), |
CFG_INT("roll_right_btn", -1,CFGF_NONE), |
CFG_INT("engine_switch_btn", -1,CFGF_NONE), |
CFG_END() |
}; |
cfg_opt_t opts[] = { |
CFG_SEC("input", input_opts, CFGF_MULTI | CFGF_TITLE), |
CFG_SIMPLE_STR("bluetooth_mac", &bluetooth_mac), |
CFG_SIMPLE_STR("mk_tty", &mk_tty), |
CFG_SIMPLE_STR("evdev_path", &evdev_path), |
CFG_SIMPLE_BOOL("exit_after_init", &exit_after_init), |
CFG_SIMPLE_STR("input_evdev", &input_evdev_name), |
CFG_SIMPLE_STR("input_joydev", &input_joydev_name), |
CFG_SIMPLE_INT("loop_delay", &loop_delay), |
CFG_SIMPLE_INT("mk_socket_port", &mk_socket_port), |
CFG_SIMPLE_FLOAT("nick_mul", &nick_mul), |
CFG_SIMPLE_FLOAT("roll_mul", &roll_mul), |
CFG_SIMPLE_FLOAT("gier_mul", &gier_mul), |
CFG_SIMPLE_FLOAT("gas_mul", &gas_mul), |
CFG_SIMPLE_FLOAT("nick_add", &nick_add), |
CFG_SIMPLE_FLOAT("roll_add", &roll_add), |
CFG_SIMPLE_FLOAT("gier_add", &gier_add), |
CFG_SIMPLE_FLOAT("gas_add", &gas_add), |
CFG_SIMPLE_INT("rel_axis_nick", &rel_axis_nick), |
CFG_SIMPLE_INT("rel_axis_roll", &rel_axis_roll), |
CFG_SIMPLE_INT("rel_axis_gier", &rel_axis_gier), |
CFG_SIMPLE_INT("rel_axis_gas", &rel_axis_gas), |
CFG_END() |
}; |
printf("Parsing config file %s\n",fname); |
cfg = cfg_init(opts, 0); |
cfg_parse(cfg,fname); |
} |
void parse_config_input_sections() |
{ |
printf("parsing inputs \n"); |
configured_input_count=cfg_size(cfg,"input"); |
printf("%d inputs configured\n", input_count); |
int i; |
int act_input=0; |
for (i=0;i<configured_input_count;i++) |
{ |
cfg_t *input_sect=cfg_getnsec(cfg,"input",i); |
printf("processing input: %s\n",cfg_getstr( input_sect, "name")); |
int evdev_i=0; |
for (evdev_i=0;evdev_i<evdevs_count;evdev_i++) |
if (!strcmp(cfg_getstr( input_sect, "name"),evdevs[evdev_i].name)) |
{ |
sprintf( inputs[act_input].fname,"%s",evdevs[evdev_i].fname); |
// todo check lengt |
sprintf(inputs[act_input].name,"processing input: %s\n",cfg_getstr( input_sect, "name")); |
inputs[act_input].nick_mul=cfg_getfloat(input_sect,"nick_mul"); |
inputs[act_input].roll_mul=cfg_getfloat(input_sect,"roll_mul"); |
inputs[act_input].gier_mul=cfg_getfloat(input_sect,"gier_mul"); |
inputs[act_input].gas_mul=cfg_getfloat(input_sect,"gas_mul"); |
inputs[act_input].alt_mul=cfg_getfloat(input_sect,"alt_mul"); |
inputs[act_input].nick_add=cfg_getfloat(input_sect,"nick_add"); |
inputs[act_input].roll_add=cfg_getfloat(input_sect,"roll_add"); |
inputs[act_input].gier_add=cfg_getfloat(input_sect,"gier_add"); |
inputs[act_input].gas_add=cfg_getfloat(input_sect,"gas_add"); |
inputs[act_input].nick_up_btn=cfg_getint(input_sect,"nick_up_btn"); |
printf("nick_up_btn %ld\n" ,cfg_getint(input_sect,"nick_up_btn")); |
inputs[act_input].nick_down_btn=cfg_getint(input_sect,"nick_down_btn"); |
inputs[act_input].roll_left_btn=cfg_getint(input_sect,"roll_left_btn"); |
inputs[act_input].roll_right_btn=cfg_getint(input_sect,"roll_right_btn"); |
inputs[act_input].rel_axis_nick=cfg_getint(input_sect,"rel_axis_nick"); |
inputs[act_input].rel_axis_roll=cfg_getint(input_sect,"rel_axis_roll"); |
inputs[act_input].rel_axis_gier=cfg_getint(input_sect,"rel_axis_gier"); |
inputs[act_input].rel_axis_gas=cfg_getint(input_sect,"rel_axis_gas"); |
inputs[act_input].rel_axis_alt=cfg_getint(input_sect,"rel_axis_alt"); |
inputs[act_input].engine_switch_btn=cfg_getint(input_sect,"engine_switch_btn"); |
act_input++; |
} |
} |
input_count=act_input; |
printf("%d inputs matching\n", input_count); |
} |
/Riddim/config.h |
---|
0,0 → 1,87 |
#if !defined(CONFIG_H) |
#define CONFIG_H |
#define MAX_INPUTS 5 |
#include <confuse.h> |
#include "evdev_handler.h" |
// values from config |
extern char *input_evdev_name; |
extern char *input_joydev_name; |
extern char *bluetooth_mac; |
extern char *evdev_path; |
extern int mk_socket_port; |
extern char *mk_tty; |
extern int loop_delay; |
extern double nick_mul; |
extern double roll_mul; |
extern double gier_mul; |
extern double gas_mul; |
extern double nick_add; |
extern double roll_add; |
extern double gier_add; |
extern double gas_add; |
extern int rel_axis_nick; |
extern int rel_axis_roll; |
extern int rel_axis_gier; |
extern int rel_axis_gas; |
extern cfg_bool_t exit_after_init ; |
extern int input_count; |
extern int configured_input_count; |
struct { |
int *evdev_rel_axis; |
char *evdev_button; |
double nick_mul; |
double roll_mul; |
double gier_mul; |
double gas_mul; |
double alt_mul; |
double nick_add; |
double roll_add; |
double gier_add; |
double gas_add; |
double alt_add; |
int rel_axis_nick; |
int rel_axis_roll; |
int rel_axis_gier; |
int rel_axis_gas; |
int rel_axis_alt; |
int nick_up_btn; |
int nick_down_btn; |
int roll_left_btn; |
int roll_right_btn; |
int engine_switch_btn; |
char name[255]; |
char fname[255]; |
int evdev_id; |
int evdev_out_fd; |
int evdev_in_fd; |
} inputs[MAX_INPUTS]; |
void parse_config(char* fname); |
void parse_config_input_sections(); |
#endif |
/Riddim/definitions.h |
---|
0,0 → 1,0 |
#define MAX_INPUTS=2 |
/Riddim/doc/router_setup.dia |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/Riddim/evdev_handler.c |
---|
0,0 → 1,257 |
#include "evdev_handler.h" |
#include "config.h" |
int retval; |
size_t read_bytes; /* how many bytes were read */ |
struct input_event ev[64]; /* the events (up to 64 at once) */ |
struct input_event led_event; |
int counter; |
int evdevs_count=0; |
int file_select(const struct direct *entry) |
{ |
if ((strncmp(entry->d_name, "event",5))==0) |
return (TRUE); |
else |
return(FALSE); |
} |
void collect_evdev_devices() |
{ |
// char event_dev_path[]="/dev/input/"; |
struct direct **files; |
evdevs_count = scandir(evdev_path, &files, file_select, NULL); |
printf("%d inputs found in %s\n" , evdevs_count,evdev_path); |
int i=0; |
for (i=0;i<evdevs_count;++i) |
{ |
printf("%s",files[i]->d_name); |
sprintf(evdevs[i].fname,"%s%s",evdev_path,files[i]->d_name); |
int act_fd; |
if ((act_fd = open(evdevs[i].fname, O_RDONLY)) < 0) |
{ |
printf(" cant open %s for reading!",evdevs[i].name); |
} |
else |
{ |
if(ioctl(act_fd , EVIOCGNAME(sizeof(evdevs[i].name)), evdevs[i].name) < 0) { |
perror("evdev ioctl"); |
} |
printf("EVDEV reports name: %s\n", evdevs[i].name); |
close(act_fd); |
} |
/* |
FILE *fp=NULL ; |
sprintf(evdevs[i].fname,"/sys/class/input/%s/name",files[i-1]->d_name); |
fp = fopen ( evdevs[i].fname, "r") ; |
if (fp==NULL) |
{ |
printf("cannot read %s\n",evdevs[i].fname); |
// exit(1); |
} |
int ch=-2; |
int str_pos=0; |
while ( (ch!=-1) && (ch!='\n') ) |
{ |
ch = fgetc ( fp ) ; |
if ((ch!=13)&&(ch!=10))evdevs[i].name[str_pos++]=ch; |
printf("%c",ch); |
} |
fclose(fp); |
evdevs[i].name[str_pos++]=0; |
*/ |
} |
} |
void print_event_str(int id) |
{ |
switch ( id) |
{ |
case EV_KEY : |
printf("Keys or Button\n"); |
break; |
case EV_ABS : |
printf("Absolute Axis\n"); |
break; |
case EV_LED : |
printf("LED(s)\n"); |
break; |
case EV_REP : |
printf("Repeat\n"); |
break; |
case EV_SYN : |
printf("Sync?\n"); |
break; |
case EV_REL : |
printf("Relative Axis\n"); |
break; |
case EV_MSC : |
printf("Misc\n"); |
break; |
default: |
printf("Unknown event type ( 0x%04hx)\n", id); |
} |
} |
int connect_evdev() |
{ |
struct input_devinfo { |
uint16_t bustype; |
uint16_t vendor; |
uint16_t product; |
uint16_t version; |
}; |
struct input_devinfo device_info; |
int i; |
for ( i =0 ; i< input_count;i++) |
{ |
inputs[i].evdev_rel_axis = (int *) calloc( 100, sizeof( int ) ); |
inputs[i].evdev_button = (char *)calloc( 500, sizeof( char ) ); |
printf(" opening evdev %s\n",inputs[i].fname); |
if ((inputs[i].evdev_out_fd = open(inputs[i].fname, O_WRONLY)) < 0) |
{ |
printf(" cant open %s for writing\n",inputs[i].fname); |
} |
if ((inputs[i].evdev_in_fd = open(inputs[i].fname, O_RDONLY)) < 0) |
{ |
printf(" cant open %s for reading!",inputs[i].fname); |
return 0; |
} |
ioctl(inputs[i].evdev_in_fd ,EVIOCGID,&device_info); |
printf("vendor 0x%04hx product 0x%04hx version 0x%04hx \n", |
device_info.vendor, device_info.product, |
device_info.version); |
uint8_t evtype_bitmask[EV_MAX/8 + 1]; |
if(ioctl(inputs[i].evdev_in_fd , EVIOCGBIT(0, sizeof(evtype_bitmask)), evtype_bitmask) < 0) |
perror("evdev ioctl"); |
printf("Supported event types:\n"); |
int i; |
for (i = 0; i < EV_MAX; i++) { |
if (test_bit(i, evtype_bitmask)) { |
/* this means that the bit is set in the event types list */ |
printf(" Event type 0x%02x ", i); |
print_event_str(i); |
}} |
} |
return 1; |
} |
/* |
int init_evdevstatus_led() |
{ |
led_event.type=EV_LED; |
led_event.code = LED_MISC; |
led_event.value = 1; |
if (evdev_out_fd) |
retval = write(evdev_out_fd, &led_event, sizeof(struct input_event)); |
return 1; |
} |
int blink_evdev_led() |
{ |
if (evdev_out_fd) |
{ |
if (led_event.value) |
led_event.value = 0; |
else |
led_event.value = 1 ; |
retval = write(evdev_out_fd, &led_event, sizeof(struct input_event)); |
} |
return 1; |
} |
*/ |
int poll_evdev() |
{ |
printf("polling evdev\n"); |
int i; |
for ( i =0 ; i< input_count;i++) |
{ |
struct timeval tv = {0,5}; |
fd_set rfds; |
FD_ZERO(&rfds); |
FD_SET(inputs[i].evdev_in_fd,&rfds); |
retval = select(inputs[i].evdev_in_fd+1, &rfds, NULL, NULL, &tv); |
if (retval==-1) |
printf("error in select!!!!!!!!\n"); |
else if (retval) |
{ |
read_bytes = read(inputs[i].evdev_in_fd, ev, sizeof(struct input_event) * 64); |
if (read_bytes < (int) sizeof(struct input_event)) { |
perror("evtest: short read"); |
exit (1); |
} |
for (counter = 0; counter < (int) (read_bytes / sizeof(struct input_event)); counter++) |
{ |
// print_event_str(ev[counter].type); |
// printf(" code:%d val:%d \n",ev[counter].code,ev[counter].value); |
// if (ev[counter].type==EV_REL) evdev_rel_axis[ ev[counter].code]= ev[counter].value; |
// for logitech problem |
if (ev[counter].type==EV_REL) inputs[i].evdev_rel_axis[ ev[counter].code]= ev[counter].value; |
if (ev[counter].type==EV_KEY) inputs[i].evdev_button[ ev[counter].code]= ev[counter].value; |
} |
for (counter=0;counter<20;counter++) |
printf("A%d %d -" , counter, inputs[i].evdev_rel_axis[counter] ); |
printf("\n"); |
for (counter=0;counter<10;counter++) |
printf("B%d %d -" , counter, inputs[i].evdev_button[counter] ); |
// printf("input read done: nick:%d roll:%d gier:%d gas:%d\n",axis[3] , axis[4] , axis[5] , axis[2]); |
} |
else |
printf("no data from evdev data from evdev: \n"); |
} |
return 1; |
} |
/Riddim/evdev_handler.h |
---|
0,0 → 1,45 |
#if !defined(EVDEV_HANDLER_H) |
#define EVDEV_HANDLER_H |
#include <stdio.h> |
#include <sys/types.h> |
#include <fcntl.h> |
#include <stdlib.h> |
#include <unistd.h>//for close() for socket |
#include <string.h> |
#include <linux/joystick.h> |
#include <netinet/in.h> |
#include <sys/types.h> |
#include <sys/dir.h> |
#include <sys/param.h> |
#define MAX_EVDEVS 20 |
#define test_bit(bit, array) (array[bit/8] & (1<<(bit%8))) |
int connect_evdev(); |
int blink_evdev_led(); |
int init_evdevstatus_led(); |
int poll_evdev(); |
void collect_evdev_devices(); |
extern int *evdev_rel_axis; |
extern char *evdev_button; |
typedef struct |
{ |
char name[255]; |
char fname[255]; |
} evdevs_t ; |
evdevs_t evdevs[MAX_EVDEVS]; |
extern int evdevs_count; |
#define FALSE 0 |
#define TRUE 1 |
#endif |
/Riddim/fc.c |
---|
0,0 → 1,296 |
#include "fc.h" |
unsigned char TxBuffer[MAX_BUFF_LEN]; |
unsigned char _TxBuffer[MAX_BUFF_LEN]; |
unsigned char RxBuffer[MAX_BUFF_LEN]; |
char PrintableRxBuffer[MAX_BUFF_LEN]; |
int mk_socket; |
int status; |
void AddCRC(unsigned int wieviele) |
{ |
unsigned int tmpCRC = 0,i; |
for(i = 0; i < wieviele;i++) |
{ |
tmpCRC += TxBuffer[i]; |
} |
tmpCRC %= 4096; |
TxBuffer[i++] = '=' + tmpCRC / 64; |
TxBuffer[i++] = '=' + tmpCRC % 64; |
TxBuffer[i++] = '\r'; |
} |
void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
{ |
// return; |
int status =0; |
unsigned int pt = 0; |
unsigned char a,b,c; |
unsigned char ptr = 0; |
TxBuffer[pt++] = '#'; // Startzeichen |
TxBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
TxBuffer[pt++] = cmd; // Commando |
while(len) |
{ |
if(len) { a = snd[ptr++]; len--;} else a = 0; |
if(len) { b = snd[ptr++]; len--;} else b = 0; |
if(len) { c = snd[ptr++]; len--;} else c = 0; |
TxBuffer[pt++] = '=' + (a >> 2); |
TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
TxBuffer[pt++] = '=' + ( c & 0x3f); |
} |
AddCRC(pt); |
printf("Sending to MK %d \n" , pt); |
status = send(mk_socket,"\r" , 1, 0); |
// for (c=0;c<pt+2;c++) |
// { |
status = write(mk_socket,&TxBuffer , pt+3); |
// printf("Send to MK %d \n" , TxBuffer[c] ); |
// } |
/* int i=0; |
while(TxBuffer[i] !='\r' && i<150) |
{ |
// TxBuffer[i]='#'; |
status = send(mk_socket,TxBuffer[i] , 1, 0); |
printf(" +%d%c ",i,TxBuffer[i]); |
i++; |
} |
// status = send(s,"\r" , 1, 0); |
*/ |
status = send(mk_socket,"\r" , 1, 0); |
status = send(mk_socket,"\n" , 1, 0); |
printf("\n"); |
} |
int rx_last_length; |
void Decode64(unsigned char *ptrOut, unsigned char len, unsigned char ptrIn,unsigned char max) |
{ |
unsigned char a,b,c,d; |
unsigned char ptr = 0; |
unsigned char x,y,z; |
while(len) |
{ |
a = RxBuffer[ptrIn++] - '='; |
b = RxBuffer[ptrIn++] - '='; |
c = RxBuffer[ptrIn++] - '='; |
d = RxBuffer[ptrIn++] - '='; |
if(ptrIn > max - 2) break; |
x = (a << 2) | (b >> 4); |
y = ((b & 0x0f) << 4) | (c >> 2); |
z = ((c & 0x03) << 6) | d; |
if(len--) ptrOut[ptr++] = x; else break; |
if(len--) ptrOut[ptr++] = y; else break; |
if(len--) ptrOut[ptr++] = z; else break; |
} |
} |
int read_from_mk() |
{ |
char in_char='#'; |
int count=0; |
int r=0; |
// int i=0; |
int p=0; |
printf("starting read\n"); |
while(in_char!='\r') |
{ |
p++; |
// printf("b read\n"); |
count=read(mk_socket,&in_char,1); |
// if ( count ==-1) exit(0); |
printf("a read %d %d %c %d\n",p,count,in_char,in_char); |
if (count!=-1) |
{ |
// printf("%c\n",in_char); |
RxBuffer[r]=in_char; |
if (in_char!=0) |
PrintableRxBuffer[r++]=in_char; |
else |
PrintableRxBuffer[r++]='0'; |
} |
} |
rx_last_length=r; |
PrintableRxBuffer[r++]='\0'; // terminate |
printf("done --->%s\n",PrintableRxBuffer); |
if (RxBuffer[2]=='D') |
{ |
debug_sets++; |
Decode64((unsigned char *) &DebugOut,sizeof(DebugOut),3,rx_last_length); |
printf("decoded FC Debug data height:%d\n",DebugOut.Analog[5]); |
} |
return 1; |
} |
int connect_mk_bluetooth(char dest[18]) |
{ |
struct sockaddr_rc addr ; |
// allocate a socket |
mk_socket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); |
// set the connection parameters (who to connect to) |
addr.rc_family = AF_BLUETOOTH; |
addr.rc_channel = 1; |
str2ba( dest, &addr.rc_bdaddr ); |
// connect to server |
status = connect(mk_socket, (struct sockaddr *)&addr, sizeof(addr)); |
printf("connection status %d\n",status); |
return status; |
} |
int connect_mk_tty(char* tty_filename) |
{ |
mk_socket = open(tty_filename,O_RDWR | O_NOCTTY); |
struct termios termattr; |
// speed_t baudRate; |
/* Make a copy of the termios structure. */ |
tcgetattr(mk_socket, &termattr); |
termattr.c_cc[VMIN]=0; |
termattr.c_cc[VTIME]=1; |
termattr.c_cflag|=CREAD|CLOCAL; |
termattr.c_lflag&=(~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|ISIG)); |
termattr.c_iflag&=(~(INPCK|IGNPAR|PARMRK|ISTRIP|ICRNL|IXANY)); |
termattr.c_oflag&=(~OPOST); |
termattr.c_cc[VMIN]=0; |
termattr.c_cc[VINTR] = _POSIX_VDISABLE; |
termattr.c_cc[VQUIT] = _POSIX_VDISABLE; |
termattr.c_cc[VSTART] = _POSIX_VDISABLE; |
termattr.c_cc[VSTOP] = _POSIX_VDISABLE; |
termattr.c_cc[VSUSP] = _POSIX_VDISABLE; |
//data 8 |
termattr.c_cflag&=(~CSIZE); |
// no par |
termattr.c_cflag&=(~PARENB); |
termattr.c_cflag |=CS8 | CREAD | CLOCAL ; |
termattr.c_iflag |= IGNPAR; |
// stop1 |
termattr.c_cflag&=(~CSTOPB); |
// Flow off |
termattr.c_cflag&=(~CRTSCTS); |
termattr.c_iflag&=(~(IXON|IXOFF|IXANY | ICRNL)); |
cfsetospeed(&termattr,B57600); |
cfsetispeed(&termattr,B57600); |
printf("set attr: %d\n" , tcsetattr(mk_socket, TCSANOW, &termattr)); |
/* |
usleep(1000000); |
char in_char='#'; |
int count=0; |
int r=0; |
int i=0; |
int p=0; |
printf("starting read %d\n",mk_socket); |
while (1) |
{ |
p=0; |
r=0; |
char in_char='#'; |
while((in_char!='\r'))//&&(r<MAX_BUFF_LEN)) |
{ |
// p++; |
// printf("b read\n"); |
count=read(mk_socket,&in_char,1); |
// tcflush( mk_socket, TCOFLUSH ); |
// printf("\np !read %d %d %c \n",p,count,in_char); |
//count=read(mk_socket,&in_char,1); |
// tcflush( mk_socket, TCOFLUSH ); |
// printf("\np !read %d %d %d %c \n",r,p,count,in_char); |
printf("%d %c \n",r, in_char); |
if (count==1) |
{ |
// printf("%c\n",in_char); |
RxBuffer[r]=in_char; |
if (in_char!=0) |
PrintableRxBuffer[r]=in_char; |
else |
PrintableRxBuffer[r]='0'; |
r++; |
} |
//else |
//printf("%d/%d",errno,EBADF); |
} |
PrintableRxBuffer[r]=0; |
printf("buff> %d\n %s\n", r, PrintableRxBuffer); |
} |
*/ |
if (mk_socket<0) |
return 0; |
else |
return 1; |
} |
int connect_mk_localhost_socket(int port) |
{ |
struct sockaddr_in sa; |
sa.sin_family = AF_INET; |
sa.sin_addr.s_addr = htonl(0x0); |
sa.sin_port = htons(port); |
mk_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); |
return connect(mk_socket,(struct sockaddr*) &sa, sizeof(struct sockaddr_in)); |
} |
/Riddim/fc.h |
---|
0,0 → 1,79 |
#ifndef FC_H |
#define FC_H |
#include <stdio.h> |
#include <termios.h> |
#include <sys/socket.h> |
#include <sys/types.h> |
#include <netinet/in.h> |
#include <unistd.h> |
#include <inttypes.h> |
#include "bluetooth_handler.h" |
#include "statistics.h" |
struct ExternControl_s |
{ |
unsigned char Digital[2]; // (noch unbenutzt) |
unsigned char RemoteTasten; //(gab es schon für das virtuelle Display) |
signed char Nick; |
signed char Roll; |
signed char Gier; |
unsigned char Gas; //(es wird das Stick-Gas auf diesen Wert begrenzt; --> StickGas ist das Maximum) |
signed char Higt; //(Hoehenregler) |
unsigned char free; // (unbenutzt) |
unsigned char Frame; // (Bestätigung) |
unsigned char Config; |
}; |
struct ExternEvent_s |
{ |
unsigned char key; |
unsigned char value[4]; |
}; |
struct str_DebugOut |
{ |
unsigned char Digital[2]; |
//# signed int |
uint16_t Analog[32]; // Debugwert// |
}; |
struct str_VersionInfo |
{ |
unsigned char SWMajor; |
unsigned char SWMinor; |
unsigned char ProtoMajor; |
unsigned char ProtoMinor; |
unsigned char SWPatch; |
unsigned char Reserved[5]; |
}; |
struct str_DebugOut DebugOut; |
struct ExternControl_s ExternControl; |
struct ExternEvent_s ExternEvent; |
extern int mk_socket; |
//int connect_mk_bluetooth(char dest[18]); |
int connect_mk_localhost_socket(int port); |
int connect_mk_bluetooth(char dest[18]); |
int connect_mk_tty(char* tty_filename); |
void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len); |
int read_from_mk(); |
#define MAX_BUFF_LEN 150 |
extern unsigned char RxBuffer[MAX_BUFF_LEN ]; |
extern char PrintableRxBuffer[MAX_BUFF_LEN ]; |
extern int rx_last_length; |
#endif |
/Riddim/joy_handler.c |
---|
0,0 → 1,71 |
#include "joy_handler.h" |
int connect_joy() |
{ |
axis = (int *) calloc( 100, sizeof( int ) ); |
button = (char *)calloc( 100, sizeof( char ) ); |
button_trigger = (char *) calloc( 100, sizeof( char ) ); |
// axis = (int *) calloc( num_of_axis, sizeof( int ) ); |
// button = (char *)calloc( num_of_buttons, sizeof( char ) ); |
// button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) ); |
if( ( joy_input_fd = open( input_joydev_name, O_RDONLY ) ) < 0 ) |
{ |
printf( "can't open %s !\nHint: try modprobe joydev\n",input_joydev_name ); |
return 0; |
} |
ioctl( joy_input_fd, JSIOCGAXES, &num_of_axis ); |
ioctl( joy_input_fd, JSIOCGBUTTONS, &num_of_buttons ); |
ioctl( joy_input_fd, JSIOCGNAME(80), &name_of_joystick ); |
printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n" |
, name_of_joystick |
, num_of_axis |
, num_of_buttons ); |
fcntl( joy_input_fd, F_SETFL, O_NONBLOCK ); /* use non-blocking mode */ |
return 1; |
} |
/* |
int connect_joy() |
{ |
axis = (int *) calloc( 100, sizeof( int ) ); |
button = (char *)calloc( 100, sizeof( char ) ); |
button_trigger = (char *) calloc( 100, sizeof( char ) ); |
// axis = (int *) calloc( num_of_axis, sizeof( int ) ); |
// button = (char *)calloc( num_of_buttons, sizeof( char ) ); |
// button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) ); |
if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 ) |
{ |
printf( "Couldn't open joystick device %s\n", JOY_DEV ); |
printf( "try modprobe joydev\n" ); |
return 0; |
} |
ioctl( x52_input_fd, JSIOCGAXES, &num_of_axis ); |
ioctl( x52_input_fd, JSIOCGBUTTONS, &num_of_buttons ); |
ioctl( x52_input_fd, JSIOCGNAME(80), &name_of_joystick ); |
printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n" |
, name_of_joystick |
, num_of_axis |
, num_of_buttons ); |
fcntl( x52_input_fd, F_SETFL, O_NONBLOCK ); |
return 1; |
} |
*/ |
/Riddim/joy_handler.h |
---|
0,0 → 1,24 |
#if !defined(JOYDEV_HANDLER_H) |
#define JOYDEV_HANDLER_H |
#include <linux/joystick.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <fcntl.h> |
#include "config.h" |
extern int *axis; |
extern char *button; |
int joy_input_fd; |
int num_of_axis,num_of_buttons; |
char *button_trigger; |
char name_of_joystick[80]; |
int connect_joy(); |
#endif |
/Riddim/lib/x52/COPYING |
---|
0,0 → 1,510 |
GNU LESSER GENERAL PUBLIC LICENSE |
Version 2.1, February 1999 |
Copyright (C) 1991, 1999 Free Software Foundation, Inc. |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Everyone is permitted to copy and distribute verbatim copies |
of this license document, but changing it is not allowed. |
[This is the first released version of the Lesser GPL. It also counts |
as the successor of the GNU Library Public License, version 2, hence |
the version number 2.1.] |
Preamble |
The licenses for most software are designed to take away your |
freedom to share and change it. By contrast, the GNU General Public |
Licenses are intended to guarantee your freedom to share and change |
free software--to make sure the software is free for all its users. |
This license, the Lesser General Public License, applies to some |
specially designated software packages--typically libraries--of the |
Free Software Foundation and other authors who decide to use it. You |
can use it too, but we suggest you first think carefully about whether |
this license or the ordinary General Public License is the better |
strategy to use in any particular case, based on the explanations |
below. |
When we speak of free software, we are referring to freedom of use, |
not price. Our General Public Licenses are designed to make sure that |
you have the freedom to distribute copies of free software (and charge |
for this service if you wish); that you receive source code or can get |
it if you want it; that you can change the software and use pieces of |
it in new free programs; and that you are informed that you can do |
these things. |
To protect your rights, we need to make restrictions that forbid |
distributors to deny you these rights or to ask you to surrender these |
rights. These restrictions translate to certain responsibilities for |
you if you distribute copies of the library or if you modify it. |
For example, if you distribute copies of the library, whether gratis |
or for a fee, you must give the recipients all the rights that we gave |
you. You must make sure that they, too, receive or can get the source |
code. If you link other code with the library, you must provide |
complete object files to the recipients, so that they can relink them |
with the library after making changes to the library and recompiling |
it. And you must show them these terms so they know their rights. |
We protect your rights with a two-step method: (1) we copyright the |
library, and (2) we offer you this license, which gives you legal |
permission to copy, distribute and/or modify the library. |
To protect each distributor, we want to make it very clear that |
there is no warranty for the free library. Also, if the library is |
modified by someone else and passed on, the recipients should know |
that what they have is not the original version, so that the original |
author's reputation will not be affected by problems that might be |
introduced by others. |
Finally, software patents pose a constant threat to the existence of |
any free program. We wish to make sure that a company cannot |
effectively restrict the users of a free program by obtaining a |
restrictive license from a patent holder. Therefore, we insist that |
any patent license obtained for a version of the library must be |
consistent with the full freedom of use specified in this license. |
Most GNU software, including some libraries, is covered by the |
ordinary GNU General Public License. This license, the GNU Lesser |
General Public License, applies to certain designated libraries, and |
is quite different from the ordinary General Public License. We use |
this license for certain libraries in order to permit linking those |
libraries into non-free programs. |
When a program is linked with a library, whether statically or using |
a shared library, the combination of the two is legally speaking a |
combined work, a derivative of the original library. The ordinary |
General Public License therefore permits such linking only if the |
entire combination fits its criteria of freedom. The Lesser General |
Public License permits more lax criteria for linking other code with |
the library. |
We call this license the "Lesser" General Public License because it |
does Less to protect the user's freedom than the ordinary General |
Public License. It also provides other free software developers Less |
of an advantage over competing non-free programs. These disadvantages |
are the reason we use the ordinary General Public License for many |
libraries. However, the Lesser license provides advantages in certain |
special circumstances. |
For example, on rare occasions, there may be a special need to |
encourage the widest possible use of a certain library, so that it |
becomes a de-facto standard. To achieve this, non-free programs must |
be allowed to use the library. A more frequent case is that a free |
library does the same job as widely used non-free libraries. In this |
case, there is little to gain by limiting the free library to free |
software only, so we use the Lesser General Public License. |
In other cases, permission to use a particular library in non-free |
programs enables a greater number of people to use a large body of |
free software. For example, permission to use the GNU C Library in |
non-free programs enables many more people to use the whole GNU |
operating system, as well as its variant, the GNU/Linux operating |
system. |
Although the Lesser General Public License is Less protective of the |
users' freedom, it does ensure that the user of a program that is |
linked with the Library has the freedom and the wherewithal to run |
that program using a modified version of the Library. |
The precise terms and conditions for copying, distribution and |
modification follow. Pay close attention to the difference between a |
"work based on the library" and a "work that uses the library". The |
former contains code derived from the library, whereas the latter must |
be combined with the library in order to run. |
GNU LESSER GENERAL PUBLIC LICENSE |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
0. This License Agreement applies to any software library or other |
program which contains a notice placed by the copyright holder or |
other authorized party saying it may be distributed under the terms of |
this Lesser General Public License (also called "this License"). |
Each licensee is addressed as "you". |
A "library" means a collection of software functions and/or data |
prepared so as to be conveniently linked with application programs |
(which use some of those functions and data) to form executables. |
The "Library", below, refers to any such software library or work |
which has been distributed under these terms. A "work based on the |
Library" means either the Library or any derivative work under |
copyright law: that is to say, a work containing the Library or a |
portion of it, either verbatim or with modifications and/or translated |
straightforwardly into another language. (Hereinafter, translation is |
included without limitation in the term "modification".) |
"Source code" for a work means the preferred form of the work for |
making modifications to it. For a library, complete source code means |
all the source code for all modules it contains, plus any associated |
interface definition files, plus the scripts used to control |
compilation and installation of the library. |
Activities other than copying, distribution and modification are not |
covered by this License; they are outside its scope. The act of |
running a program using the Library is not restricted, and output from |
such a program is covered only if its contents constitute a work based |
on the Library (independent of the use of the Library in a tool for |
writing it). Whether that is true depends on what the Library does |
and what the program that uses the Library does. |
1. You may copy and distribute verbatim copies of the Library's |
complete source code as you receive it, in any medium, provided that |
you conspicuously and appropriately publish on each copy an |
appropriate copyright notice and disclaimer of warranty; keep intact |
all the notices that refer to this License and to the absence of any |
warranty; and distribute a copy of this License along with the |
Library. |
You may charge a fee for the physical act of transferring a copy, |
and you may at your option offer warranty protection in exchange for a |
fee. |
2. You may modify your copy or copies of the Library or any portion |
of it, thus forming a work based on the Library, and copy and |
distribute such modifications or work under the terms of Section 1 |
above, provided that you also meet all of these conditions: |
a) The modified work must itself be a software library. |
b) You must cause the files modified to carry prominent notices |
stating that you changed the files and the date of any change. |
c) You must cause the whole of the work to be licensed at no |
charge to all third parties under the terms of this License. |
d) If a facility in the modified Library refers to a function or a |
table of data to be supplied by an application program that uses |
the facility, other than as an argument passed when the facility |
is invoked, then you must make a good faith effort to ensure that, |
in the event an application does not supply such function or |
table, the facility still operates, and performs whatever part of |
its purpose remains meaningful. |
(For example, a function in a library to compute square roots has |
a purpose that is entirely well-defined independent of the |
application. Therefore, Subsection 2d requires that any |
application-supplied function or table used by this function must |
be optional: if the application does not supply it, the square |
root function must still compute square roots.) |
These requirements apply to the modified work as a whole. If |
identifiable sections of that work are not derived from the Library, |
and can be reasonably considered independent and separate works in |
themselves, then this License, and its terms, do not apply to those |
sections when you distribute them as separate works. But when you |
distribute the same sections as part of a whole which is a work based |
on the Library, the distribution of the whole must be on the terms of |
this License, whose permissions for other licensees extend to the |
entire whole, and thus to each and every part regardless of who wrote |
it. |
Thus, it is not the intent of this section to claim rights or contest |
your rights to work written entirely by you; rather, the intent is to |
exercise the right to control the distribution of derivative or |
collective works based on the Library. |
In addition, mere aggregation of another work not based on the Library |
with the Library (or with a work based on the Library) on a volume of |
a storage or distribution medium does not bring the other work under |
the scope of this License. |
3. You may opt to apply the terms of the ordinary GNU General Public |
License instead of this License to a given copy of the Library. To do |
this, you must alter all the notices that refer to this License, so |
that they refer to the ordinary GNU General Public License, version 2, |
instead of to this License. (If a newer version than version 2 of the |
ordinary GNU General Public License has appeared, then you can specify |
that version instead if you wish.) Do not make any other change in |
these notices. |
Once this change is made in a given copy, it is irreversible for |
that copy, so the ordinary GNU General Public License applies to all |
subsequent copies and derivative works made from that copy. |
This option is useful when you wish to copy part of the code of |
the Library into a program that is not a library. |
4. You may copy and distribute the Library (or a portion or |
derivative of it, under Section 2) in object code or executable form |
under the terms of Sections 1 and 2 above provided that you accompany |
it with the complete corresponding machine-readable source code, which |
must be distributed under the terms of Sections 1 and 2 above on a |
medium customarily used for software interchange. |
If distribution of object code is made by offering access to copy |
from a designated place, then offering equivalent access to copy the |
source code from the same place satisfies the requirement to |
distribute the source code, even though third parties are not |
compelled to copy the source along with the object code. |
5. A program that contains no derivative of any portion of the |
Library, but is designed to work with the Library by being compiled or |
linked with it, is called a "work that uses the Library". Such a |
work, in isolation, is not a derivative work of the Library, and |
therefore falls outside the scope of this License. |
However, linking a "work that uses the Library" with the Library |
creates an executable that is a derivative of the Library (because it |
contains portions of the Library), rather than a "work that uses the |
library". The executable is therefore covered by this License. |
Section 6 states terms for distribution of such executables. |
When a "work that uses the Library" uses material from a header file |
that is part of the Library, the object code for the work may be a |
derivative work of the Library even though the source code is not. |
Whether this is true is especially significant if the work can be |
linked without the Library, or if the work is itself a library. The |
threshold for this to be true is not precisely defined by law. |
If such an object file uses only numerical parameters, data |
structure layouts and accessors, and small macros and small inline |
functions (ten lines or less in length), then the use of the object |
file is unrestricted, regardless of whether it is legally a derivative |
work. (Executables containing this object code plus portions of the |
Library will still fall under Section 6.) |
Otherwise, if the work is a derivative of the Library, you may |
distribute the object code for the work under the terms of Section 6. |
Any executables containing that work also fall under Section 6, |
whether or not they are linked directly with the Library itself. |
6. As an exception to the Sections above, you may also combine or |
link a "work that uses the Library" with the Library to produce a |
work containing portions of the Library, and distribute that work |
under terms of your choice, provided that the terms permit |
modification of the work for the customer's own use and reverse |
engineering for debugging such modifications. |
You must give prominent notice with each copy of the work that the |
Library is used in it and that the Library and its use are covered by |
this License. You must supply a copy of this License. If the work |
during execution displays copyright notices, you must include the |
copyright notice for the Library among them, as well as a reference |
directing the user to the copy of this License. Also, you must do one |
of these things: |
a) Accompany the work with the complete corresponding |
machine-readable source code for the Library including whatever |
changes were used in the work (which must be distributed under |
Sections 1 and 2 above); and, if the work is an executable linked |
with the Library, with the complete machine-readable "work that |
uses the Library", as object code and/or source code, so that the |
user can modify the Library and then relink to produce a modified |
executable containing the modified Library. (It is understood |
that the user who changes the contents of definitions files in the |
Library will not necessarily be able to recompile the application |
to use the modified definitions.) |
b) Use a suitable shared library mechanism for linking with the |
Library. A suitable mechanism is one that (1) uses at run time a |
copy of the library already present on the user's computer system, |
rather than copying library functions into the executable, and (2) |
will operate properly with a modified version of the library, if |
the user installs one, as long as the modified version is |
interface-compatible with the version that the work was made with. |
c) Accompany the work with a written offer, valid for at least |
three years, to give the same user the materials specified in |
Subsection 6a, above, for a charge no more than the cost of |
performing this distribution. |
d) If distribution of the work is made by offering access to copy |
from a designated place, offer equivalent access to copy the above |
specified materials from the same place. |
e) Verify that the user has already received a copy of these |
materials or that you have already sent this user a copy. |
For an executable, the required form of the "work that uses the |
Library" must include any data and utility programs needed for |
reproducing the executable from it. However, as a special exception, |
the materials to be distributed need not include anything that is |
normally distributed (in either source or binary form) with the major |
components (compiler, kernel, and so on) of the operating system on |
which the executable runs, unless that component itself accompanies |
the executable. |
It may happen that this requirement contradicts the license |
restrictions of other proprietary libraries that do not normally |
accompany the operating system. Such a contradiction means you cannot |
use both them and the Library together in an executable that you |
distribute. |
7. You may place library facilities that are a work based on the |
Library side-by-side in a single library together with other library |
facilities not covered by this License, and distribute such a combined |
library, provided that the separate distribution of the work based on |
the Library and of the other library facilities is otherwise |
permitted, and provided that you do these two things: |
a) Accompany the combined library with a copy of the same work |
based on the Library, uncombined with any other library |
facilities. This must be distributed under the terms of the |
Sections above. |
b) Give prominent notice with the combined library of the fact |
that part of it is a work based on the Library, and explaining |
where to find the accompanying uncombined form of the same work. |
8. You may not copy, modify, sublicense, link with, or distribute |
the Library except as expressly provided under this License. Any |
attempt otherwise to copy, modify, sublicense, link with, or |
distribute the Library is void, and will automatically terminate your |
rights under this License. However, parties who have received copies, |
or rights, from you under this License will not have their licenses |
terminated so long as such parties remain in full compliance. |
9. You are not required to accept this License, since you have not |
signed it. However, nothing else grants you permission to modify or |
distribute the Library or its derivative works. These actions are |
prohibited by law if you do not accept this License. Therefore, by |
modifying or distributing the Library (or any work based on the |
Library), you indicate your acceptance of this License to do so, and |
all its terms and conditions for copying, distributing or modifying |
the Library or works based on it. |
10. Each time you redistribute the Library (or any work based on the |
Library), the recipient automatically receives a license from the |
original licensor to copy, distribute, link with or modify the Library |
subject to these terms and conditions. You may not impose any further |
restrictions on the recipients' exercise of the rights granted herein. |
You are not responsible for enforcing compliance by third parties with |
this License. |
11. If, as a consequence of a court judgment or allegation of patent |
infringement or for any other reason (not limited to patent issues), |
conditions are imposed on you (whether by court order, agreement or |
otherwise) that contradict the conditions of this License, they do not |
excuse you from the conditions of this License. If you cannot |
distribute so as to satisfy simultaneously your obligations under this |
License and any other pertinent obligations, then as a consequence you |
may not distribute the Library at all. For example, if a patent |
license would not permit royalty-free redistribution of the Library by |
all those who receive copies directly or indirectly through you, then |
the only way you could satisfy both it and this License would be to |
refrain entirely from distribution of the Library. |
If any portion of this section is held invalid or unenforceable under |
any particular circumstance, the balance of the section is intended to |
apply, and the section as a whole is intended to apply in other |
circumstances. |
It is not the purpose of this section to induce you to infringe any |
patents or other property right claims or to contest validity of any |
such claims; this section has the sole purpose of protecting the |
integrity of the free software distribution system which is |
implemented by public license practices. Many people have made |
generous contributions to the wide range of software distributed |
through that system in reliance on consistent application of that |
system; it is up to the author/donor to decide if he or she is willing |
to distribute software through any other system and a licensee cannot |
impose that choice. |
This section is intended to make thoroughly clear what is believed to |
be a consequence of the rest of this License. |
12. If the distribution and/or use of the Library is restricted in |
certain countries either by patents or by copyrighted interfaces, the |
original copyright holder who places the Library under this License |
may add an explicit geographical distribution limitation excluding those |
countries, so that distribution is permitted only in or among |
countries not thus excluded. In such case, this License incorporates |
the limitation as if written in the body of this License. |
13. The Free Software Foundation may publish revised and/or new |
versions of the Lesser General Public License from time to time. |
Such new versions will be similar in spirit to the present version, |
but may differ in detail to address new problems or concerns. |
Each version is given a distinguishing version number. If the Library |
specifies a version number of this License which applies to it and |
"any later version", you have the option of following the terms and |
conditions either of that version or of any later version published by |
the Free Software Foundation. If the Library does not specify a |
license version number, you may choose any version ever published by |
the Free Software Foundation. |
14. If you wish to incorporate parts of the Library into other free |
programs whose distribution conditions are incompatible with these, |
write to the author to ask for permission. For software which is |
copyrighted by the Free Software Foundation, write to the Free |
Software Foundation; we sometimes make exceptions for this. Our |
decision will be guided by the two goals of preserving the free status |
of all derivatives of our free software and of promoting the sharing |
and reuse of software generally. |
NO WARRANTY |
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO |
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. |
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR |
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY |
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE |
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME |
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. |
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN |
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY |
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU |
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE |
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
DAMAGES. |
END OF TERMS AND CONDITIONS |
How to Apply These Terms to Your New Libraries |
If you develop a new library, and you want it to be of the greatest |
possible use to the public, we recommend making it free software that |
everyone can redistribute and change. You can do so by permitting |
redistribution under these terms (or, alternatively, under the terms |
of the ordinary General Public License). |
To apply these terms, attach the following notices to the library. |
It is safest to attach them to the start of each source file to most |
effectively convey the exclusion of warranty; and each file should |
have at least the "copyright" line and a pointer to where the full |
notice is found. |
<one line to give the library's name and a brief idea of what it does.> |
Copyright (C) <year> <name of author> |
This library is free software; you can redistribute it and/or |
modify it under the terms of the GNU Lesser General Public |
License as published by the Free Software Foundation; either |
version 2.1 of the License, or (at your option) any later version. |
This library is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
Lesser General Public License for more details. |
You should have received a copy of the GNU Lesser General Public |
License along with this library; if not, write to the Free Software |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Also add information on how to contact you by electronic and paper mail. |
You should also get your employer (if you work as a programmer) or |
your school, if any, to sign a "copyright disclaimer" for the library, |
if necessary. Here is a sample; alter the names: |
Yoyodyne, Inc., hereby disclaims all copyright interest in the |
library `Frob' (a library for tweaking knobs) written by James |
Random Hacker. |
<signature of Ty Coon>, 1 April 1990 |
Ty Coon, President of Vice |
That's all there is to it! |
/Riddim/lib/x52/README |
---|
0,0 → 1,30 |
This is the first release of the Linux library for the MFD and the |
LEDs found on the SAITEK X52 ( and PRO ) HOTAS joystick. The informations needed |
for accessing this nice device where kindly supplied by saitek. |
The code is released under the LGPL. For more details please read the |
COPYING file. |
Compilation of this library requires the libusb http://www.linux-usb.org/ |
The library itself consists of the x52.c and the x52.h file. |
Programs which want to use the library have to link "x52.o" and |
the libusb. For more details please have a look at the Makefile |
supplied with this package. The Makefile builds a test program |
named x52test. |
With the x52test program it is possible to test all the features |
of the library: |
x52test text 0 'First Line' |
x52test text 1 'Second Line' |
x52test text 2 'Third Line' |
x52test bri 0 40 |
x52test bri 1 50 |
x52test led 1 1 |
x52test time 1 12 20 |
x52test date 7 10 17 |
If you have any questions regarding using this library and/or the x52 (pro) |
please send an email to <eduard@hasenleithner.at>. I also welcome |
any hints for improvements of this library. |
/Riddim/lib/x52/x52.c |
---|
0,0 → 1,194 |
/* x52pro driver library |
* Copyright (C) 2007 Eduard Hasenleithner <eduard@hasenleithner.at> |
* Licensed under the LGPL. Please see "COPYING". |
*/ |
#include <stdio.h> |
#include <string.h> |
#include <usb.h> |
#include "x52.h" |
struct x52 { |
usb_dev_handle *hdl; |
}; |
#define X52PRO_REQUEST 0x91 |
#define X52PRO_CLEAR1 0xd9 |
#define X52PRO_CLEAR2 0xda |
#define X52PRO_CLEAR3 0xdc |
#define X52PRO_WRITE1 0xd1 |
#define X52PRO_WRITE2 0xd2 |
#define X52PRO_WRITE3 0xd4 |
#define X52PRO_SETLED 0xb8 |
#define X52PRO_MFDBRI 0xb1 |
#define X52PRO_LEDBRI 0xb2 |
#define X52PRO_TIME 0xc0 |
#define X52PRO_DATE 0xc4 |
#define X52PRO_YEAR 0xc8 |
int write_idx[3] = { |
X52PRO_WRITE1, |
X52PRO_WRITE2, |
X52PRO_WRITE3, |
}; |
int clear_idx[3] = { |
X52PRO_CLEAR1, |
X52PRO_CLEAR2, |
X52PRO_CLEAR3, |
}; |
int x52_settext(struct x52 *x52, int line, char *text, int length) |
{ |
int r; |
if (line > 3) return -1; |
r = usb_control_msg(x52->hdl, |
USB_TYPE_VENDOR|USB_RECIP_DEVICE|USB_ENDPOINT_OUT, |
X52PRO_REQUEST, 0x00, clear_idx[line], NULL, 0, 1000); |
if (r < 0) { |
fprintf(stderr, "x52_settext failed at clear command (%s)\n", |
usb_strerror()); |
return -2; |
} |
while (length >= 1) { |
int chars; |
if (length == 1) chars = (' ' << 8) + *text; |
else chars = *(unsigned short*) text; |
r = usb_control_msg(x52->hdl, |
USB_TYPE_VENDOR|USB_RECIP_DEVICE|USB_ENDPOINT_OUT, |
X52PRO_REQUEST, chars, write_idx[line], NULL, 0, 1000); |
if (r<0) { |
fprintf(stderr, "x52_settext failed at write %d (%s)\n", |
length, usb_strerror()); |
return -2; |
} |
length -= 2; |
text += 2; |
} |
return 0; |
} |
int x52_setbri(struct x52 *x52, int mfd, int brightness) |
{ |
int r; |
r = usb_control_msg(x52->hdl, |
USB_TYPE_VENDOR|USB_RECIP_DEVICE|USB_ENDPOINT_OUT, |
X52PRO_REQUEST, brightness, mfd ? X52PRO_MFDBRI : X52PRO_LEDBRI, |
NULL, 0, 1000); |
if (r < 0) { |
fprintf(stderr, "x52_setbri failed (%s)\n", usb_strerror()); |
return -2; |
} |
return 0; |
} |
int x52_setled(struct x52 *x52, int led, int on) |
{ |
int r; |
r = usb_control_msg(x52->hdl, |
USB_TYPE_VENDOR|USB_RECIP_DEVICE|USB_ENDPOINT_OUT, |
X52PRO_REQUEST, on | (led<<8), X52PRO_SETLED, |
NULL, 0, 1000); |
if (r < 0) { |
fprintf(stderr, "x52_setled failed (%s)\n", usb_strerror()); |
return -2; |
} |
return 0; |
} |
int x52_settime(struct x52 *x52, int h24, int hour, int minute) |
{ |
int r; |
r = usb_control_msg(x52->hdl, |
USB_TYPE_VENDOR|USB_RECIP_DEVICE|USB_ENDPOINT_OUT, |
X52PRO_REQUEST, minute | (hour<<8) | (h24?0x8000:0), X52PRO_TIME, |
NULL, 0, 1000); |
if (r < 0) { |
fprintf(stderr, "x52_settime failed (%s)\n", usb_strerror()); |
return -2; |
} |
return 0; |
} |
int x52_setdate(struct x52 *x52, int year, int month, int day) |
{ |
int r; |
r = usb_control_msg(x52->hdl, |
USB_TYPE_VENDOR|USB_RECIP_DEVICE|USB_ENDPOINT_OUT, |
X52PRO_REQUEST, day | (month<<8), X52PRO_DATE, |
NULL, 0, 1000); |
if (r < 0) { |
fprintf(stderr, "x52_setdate failed (%s)\n", usb_strerror()); |
return -2; |
} |
r = usb_control_msg(x52->hdl, |
USB_TYPE_VENDOR|USB_RECIP_DEVICE|USB_ENDPOINT_OUT, |
X52PRO_REQUEST, year, X52PRO_YEAR, |
NULL, 0, 1000); |
if (r < 0) { |
fprintf(stderr, "x52_setdate failed for year (%s)\n", usb_strerror()); |
return -2; |
} |
return 0; |
} |
int x52_custom(struct x52 *x52, int index, int value) |
{ |
int r = usb_control_msg(x52->hdl, |
USB_TYPE_VENDOR|USB_RECIP_DEVICE|USB_ENDPOINT_OUT, |
X52PRO_REQUEST, value, index, NULL, 0, 1000); |
if (r < 0) { |
fprintf(stderr, "x52_settext failed at clear command (%s)\n", |
usb_strerror()); |
return -2; |
} |
return 0; |
} |
struct x52* x52_init(void) |
{ |
struct x52 x52, *x52p; |
usb_init(); |
usb_find_busses(); |
usb_find_devices(); |
struct usb_bus *bus; |
struct usb_device *joydev = NULL; |
for (bus = usb_busses; bus; bus = bus->next) { |
struct usb_device *dev; |
for (dev = bus->devices; dev; dev = dev->next) { |
struct usb_device_descriptor *dsc = &dev->descriptor; |
if (dsc->idVendor == 0x6a3 && ((dsc->idProduct == 0x75c)||(dsc->idProduct == 0x762))) |
{ |
joydev = dev; |
break; |
} |
} |
if (joydev) break; |
} |
if (!joydev) { |
fprintf(stderr, "joystick not found\n"); |
return NULL; |
} |
fprintf(stderr, "joystick found\n"); |
x52.hdl = usb_open(joydev); |
if (x52.hdl==NULL) { |
fprintf(stderr, "joystick open failed\n"); |
return NULL; |
} |
x52p = malloc(sizeof(*x52p)); |
*x52p = x52; |
return x52p; |
} |
void x52_close(struct x52* x52) |
{ |
int r; |
r = usb_close(x52->hdl); |
free(x52); |
printf("usb_close: %d\n", r); |
} |
/Riddim/lib/x52/x52.h |
---|
0,0 → 1,73 |
/* x52pro driver library |
* Copyright (C) 2007 Eduard Hasenleithner <eduard@hasenleithner.at> |
* Licensed under the LGPL. Please see "COPYING". |
*/ |
struct x52; |
#define X52PRO_LED_FIRE 1 /* RED/GREEN LED of Fire Button */ |
#define X52PRO_LED_ARED 2 /* RED LED of A Button */ |
#define X52PRO_LED_AGREEN 3 /* GREEN LED of A Button */ |
#define X52PRO_LED_BRED 4 /* RED LED of B Button */ |
#define X52PRO_LED_BGREEN 5 /* GREEN LED of B Button */ |
#define X52PRO_LED_DRED 6 /* RED LED of D Button */ |
#define X52PRO_LED_DGREEN 7 /* GREEN LED of D Button */ |
#define X52PRO_LED_ERED 8 /* RED LED of E Button */ |
#define X52PRO_LED_EGREEN 9 /* GREEN LED of E Button */ |
#define X52PRO_LED_T1RED 10 /* RED LED of T1 Switch */ |
#define X52PRO_LED_T1GREEN 11 /* GREEN LED of T1 Switch */ |
#define X52PRO_LED_T2RED 12 /* RED LED of T2 Switch */ |
#define X52PRO_LED_T2GREEN 13 /* GREEN LED of T2 Switch */ |
#define X52PRO_LED_T3RED 14 /* RED LED of T3 Switch */ |
#define X52PRO_LED_T3GREEN 15 /* GREEN LED of T3 Switch */ |
#define X52PRO_LED_CORED 16 /* RED LED of Coolie Hat */ |
#define X52PRO_LED_COGREEN 17 /* GREEN LED of Coolie Hat */ |
#define X52PRO_LED_IRED 18 /* RED LED of i Button */ |
#define X52PRO_LED_IGREEN 19 /* GREEN LED of i Button */ |
/* Init function |
* RETURN: handle to x52 if device opened successful */ |
struct x52* x52_init(void); |
/* Close function |
* hdl: handle to xte device */ |
void x52_close(struct x52* hdl); |
/* Set the text of the MFD |
* RETURN: 0 if successful |
* hdl: handle to x52 device |
* line: line of text to change |
* text: character string of new text |
* length: number of characters in string */ |
int x52_settext(struct x52 *hdl, int line, char *text, int length); |
/* Set the brightness of the MFD or the LEDs |
* RETURN: 0 if successful |
* hdl: handle to x52 device |
* mfd: boolean |
* 0: change the LED brightness |
* 1: change the MFD brightness |
* brightness: value (0-127) */ |
int x52_setbri(struct x52 *hdl, int mfd, int brightness); |
/* Set or clear one of the LEDs |
* RETURN: 0 if successful |
* hdl: handle to x52 device |
* led: led index (1-19), see X52PRO_LED_XXX defines |
* on: boolean */ |
int x52_setled(struct x52 *hdl, int led, int on); |
/* Set the MFD display time |
* RETURN: 0 if successful |
* hdl: handle to x52 device |
* h24: boolean, 24h output (1=on, 0=off) |
* hour: value (0-23) |
* minute: value (0-60) */ |
int x52_settime(struct x52 *hdl, int h24, int hour, int minute); |
/* Set the MFD display date |
* RETURN: 0 if successful |
* year: value (0-99) |
* month: value (1-12) |
* day: value (1-31) */ |
int x52_setdate(struct x52 *hdl, int year, int month, int day); |
/Riddim/openwrt_port/Makefile |
---|
0,0 → 1,47 |
# |
# Copyright (C) 2006 OpenWrt.org |
# |
# This is free software, licensed under the GNU General Public License v2. |
# See /LICENSE for more information. |
# |
# $Id: Makefile 9050 2007-09-28 01:23:17Z nbd $ |
include $(TOPDIR)/rules.mk |
include $(INCLUDE_DIR)/kernel.mk |
PKG_NAME:=riddim |
PKG_VERSION:=0.0.7 |
PKG_RELEASE:=1 |
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz |
PKG_SOURCE_URL:=http://mikrocontroller.cco-ev.de/mikrosvn/Projects/Riddim/ |
PKG_SOURCE_PROTO:=svn |
PKG_SOURCE_VERSION:=488 |
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) |
#PKG_MD5SUM:=9b7dc52656f5cbec846a7ba3299f73bd |
include $(INCLUDE_DIR)/package.mk |
define Package/riddim |
SECTION:=utils |
DEPENDS:=+confuse |
DEPENDS:=+kmod-hid |
CATEGORY:=Base system |
TITLE:=Remote Interactive Digital Drone Interface Mashup |
URL:=http://www.mikrokopter.de/ucwiki/en/Riddim |
endef |
define Package/riddim/description |
Remote Interactive Digital Drone Interface Mashup |
endef |
define Package/riddim/install |
$(INSTALL_DIR) $(1)/usr/sbin |
$(INSTALL_BIN) $(PKG_BUILD_DIR)/riddim $(1)/usr/sbin/ |
endef |
$(eval $(call BuildPackage,riddim)) |
/Riddim/openwrt_port/bin/riddim_0.0.7-1_mipsel.ipk |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/Riddim/riddim.c |
---|
0,0 → 1,621 |
/************************************************** |
* |
* |
* Riddim |
* Remote Interactive Digital Drone Interface Mashup |
* |
* (cc) 2007-2009 Marcus -LiGi- Bueschleb |
* |
* |
**************************************************/ |
#include "riddim.h" |
int state=STATEID_SCANNING; |
struct js_event x52_event_struct; |
int engines_on=0; |
int old_engines_on=0; |
int *axis; |
char *button; |
int act_nick=0; |
int act_roll=0; |
int act_gier=0; |
int act_gas=0; |
int act_mode=0; |
int act_alt=0; |
long act_long_alt=0; |
struct x52 *x52_output; |
int selected_bt_device=0; |
int count=0; |
int connected=0; |
int input=INPUT_NONE; |
void write_display(int line,char* text) |
{ |
if (x52_output) x52_settext(x52_output, line , text, strlen(text)); |
} |
void clear_display() |
{ |
write_display(0,""); |
write_display(1,""); |
write_display(2,""); |
} |
void output_device_list() |
{ |
int i; |
char disp_txt[20]; |
for(i=0;i<bt_device_count;i++) |
{ |
if (i<3) |
{ |
if (selected_bt_device==i) |
sprintf(disp_txt,"#%s",names[i]); |
else |
sprintf(disp_txt," %s",names[i]); |
write_display(i,disp_txt); |
} |
} |
} |
void print_device_list() |
{ |
int i; |
for(i=0;i<bt_device_count;i++) |
printf("device%i->%s\n",i,names[i]); |
} |
int main(int argc, char**argv) |
{ |
printf("Starting Riddim %d.%d \n",RIDDIM_VERSION_MAJOR,RIDDIM_VERSION_MINOR ); |
printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
printf("\nusage:\n"); |
printf("\t riddim [config_file]\n\n"); |
// check if config file as argument |
if (argv[1]) |
parse_config(argv[1]); |
else |
parse_config("/etc/riddim.conf"); |
bt_host_init(); |
collect_evdev_devices(); |
parse_config_input_sections(); |
// exit(0); |
printf("input %s:\n",input_evdev_name); |
/* |
if (bluetooth_mac) |
{ |
printf("Connecting via Bluetooth to %s\n",bluetooth_mac); |
if (connect_mk_bluetooth(bluetooth_mac));; |
connected=TRUE; |
} |
*/ |
if (mk_tty) |
{ |
printf("connecting to mk via tty: %s\n",mk_tty); |
if (!connect_mk_tty(mk_tty)) |
printf("cant connect !!"); |
else |
{ |
printf("connected !-)"); |
connected=TRUE; |
} |
} |
if (mk_socket_port) |
{ |
printf("connecting to mk via local port: %i\n",mk_socket_port); |
if (connect_mk_localhost_socket(mk_socket_port)==-1) |
printf("cant connect !!"); |
else |
{ |
printf("connected !-)"); |
connected=TRUE; |
} |
} |
// todo reenable bluetooth connection |
connect_evdev(); |
/* |
if ((input_evdev_name)) |
{ |
printf("\nInitializing evdev input (%s) ..\n",input_evdev_name); |
if (connect_evdev(input_evdev_name)) |
{ |
printf(".. done");// |
input=INPUT_EVDEV; |
} |
else |
printf(".. ERROR ");// |
} |
*/ |
if (input_joydev_name) |
{ |
printf("\nInitializing joystick input from %s ..\n",input_joydev_name); |
if (connect_joy()) |
{ |
printf(".. done");// |
input=INPUT_JOYDEV; |
} |
else |
printf(".. ERROR ");// |
} |
printf("\nInitializing X-52 output .."); |
x52_output = x52_init(); |
clear_display(); |
write_display(0, "RIDDIM active"); |
if (x52_output) x52_setbri(x52_output, 1,128); |
if (x52_output) |
printf(" done \n"); |
else |
printf(" not found \n"); |
/* |
if (!connected) |
{ |
printf("Scanning for Bluetooth Devices ..\n"); |
write_display(1,"Bluetooth Scan"); |
scan_bt(); |
printf(" done \n"); |
printf(" %d Devices found \n",bt_device_count); |
print_device_list() ; |
} |
*/ |
// int v_old; |
int polls=0; |
if (exit_after_init) |
exit(0); |
printf("starting loop ..\n"); |
int complete_misses=0; |
int complete_matches=0; |
int confirm_misses; |
// init_evdevstatus_led(); |
while( TRUE ) |
{ |
gettimeofday(&loop_start_time,NULL); |
// blink_evdev_led(); |
bt_host_tick(mk_socket); |
usleep(loop_delay); |
poll_evdev(); |
switch (input) |
{ |
case INPUT_NONE: |
printf("processing input none\n"); |
break; |
case INPUT_EVDEV: |
printf("processing input evdev\n"); |
break; |
case INPUT_JOYDEV: |
printf("processing input joydev\n"); |
// poll values from input device |
for (polls=0;polls<100;polls++) // FIXME - better Polling |
{ |
read(joy_input_fd, &x52_event_struct, sizeof(struct js_event)); |
/* see what to do with the event */ |
switch (x52_event_struct.type & ~JS_EVENT_INIT) |
{ |
case JS_EVENT_AXIS: |
axis [ x52_event_struct.number ] = x52_event_struct.value; |
break; |
case JS_EVENT_BUTTON: |
button [ x52_event_struct.number ] = x52_event_struct.value; |
break; |
} |
} |
int x; |
for( x=0 ; x<num_of_buttons ; ++x ) |
if( button[x]==0) |
button_trigger[x]=0; |
else |
{ |
if (button_trigger[x]<100)button_trigger[x]++; |
} |
break; |
} // switch (input) |
printf("input done\n"); |
switch(state) |
{ |
case STATEID_SCANNING: |
state=STATEID_CONNECTING; |
/* |
ExternControl.Digital[0]=0; |
ExternControl.Digital[1]=0; |
ExternControl.RemoteTasten=0; |
ExternControl.Nick=(axis[1]>>8)*(-1)+127;; |
printf("nick%d\n",ExternControl.Nick); |
ExternControl.Roll=(axis[0]>>8)*(-1)+127;; |
ExternControl.Gier=(axis[5]>>8)*(-1)+127;; |
ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
ExternControl.Higt=0; |
ExternControl.free=0; |
ExternControl.Frame='t'; |
ExternControl.Config=1; |
printf("sending data\n"); |
if (connected)SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
gettimeofday(&time_struct1,NULL); |
if (button_trigger[BUTTON_SELECT]==1) |
{ |
state=STATEID_CONNECTING; |
clear_display(); |
write_display(0,"connecting to"); |
write_display(1,names[selected_bt_device]); |
//connect_mk(addrs[selected_bt_device]); |
write_display(0,"connected to"); |
} |
if ((button_trigger[BUTTON_UP]+button_trigger[BUTTON_DOWN])==1) |
{ |
printf("-> sel_dev %d - %d\n",selected_bt_device,button_trigger[19]); |
if (button_trigger[BUTTON_DOWN]==1) |
if (selected_bt_device>0) selected_bt_device--; |
if (button_trigger[BUTTON_UP]==1) |
if (selected_bt_device<bt_device_count-1) selected_bt_device++; |
} |
*/ |
break; |
case STATEID_CONNECTING: |
confirm_misses=0; |
RxBuffer[2]=0; |
if (connected) |
{ |
read_from_mk(); |
if (RxBuffer[2]=='B') |
complete_misses++; |
/*while (RxBuffer[2]!='B') |
{ |
RxBuffer[1]=0; |
read_from_mk(); |
// bt_host_send(RxBuffer,rx_last_length); |
printf("sending to host: %s",PrintableRxBuffer); |
// ftime(&time_struct); |
printf("waiting for confirm frame ( confirmed:%d misses:%d %c)\n",complete_matches,complete_misses,RxBuffer[2]); |
// RxBuffer[2]=0; |
// r=0; |
// new |
//if (button_trigger[12]>1) |
// { |
// SendOutData('s', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
// button_trigger[12]=0; |
// } |
ExternControl.Frame='t'; |
if (++confirm_misses>4) |
{ |
complete_misses++; |
printf("sending again\n"); |
SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
} |
*/ |
} |
else |
printf("not connected to mk\n"); |
// gettimeofday(&time_struct2,NULL); |
// printf("last trip: %d\n",(int)(time_struct2.tv_usec-time_struct1.tv_usec)); |
// act_mode=button[24] | (button[25]<<1); |
// Step converting axis data to nick/roll/gier/gas/.. |
// act_nick=(evdev_rel_axis[rel_axis_nick]-128)*nick_mul; |
/* Mix input values */ |
act_gas=0; |
act_nick=0; |
act_roll=0; |
act_gier=0; |
int act_input=0; |
for (act_input=0;act_input<input_count;act_input++) |
{ |
printf("process b %d\n",inputs[act_input].nick_up_btn); |
//process buttons |
if (inputs[act_input].nick_up_btn!=-1) |
{ |
if (inputs[act_input].evdev_button[inputs[act_input].nick_up_btn]!=0) |
act_nick=100; |
} |
if (inputs[act_input].nick_down_btn!=-1) |
{ |
if (inputs[act_input].evdev_button[inputs[act_input].nick_down_btn]!=0) |
act_nick=-100; |
} |
if (inputs[act_input].roll_left_btn!=-1) |
{ |
if (inputs[act_input].evdev_button[inputs[act_input].roll_left_btn]!=0) |
act_roll=100; |
} |
if (inputs[act_input].roll_right_btn!=-1) |
{ |
if (inputs[act_input].evdev_button[inputs[act_input].roll_right_btn]!=0) |
act_roll=-100; |
} |
// process axis |
if (inputs[act_input].rel_axis_nick!=-1) |
act_nick=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_nick]*inputs[act_input].nick_mul; |
if (inputs[act_input].rel_axis_roll!=-1) |
act_roll=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_roll]*inputs[act_input].roll_mul; |
if (inputs[act_input].rel_axis_gier!=-1) |
act_gier=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_gier]*inputs[act_input].gier_mul; |
if (inputs[act_input].rel_axis_gas!=-1) |
act_gas=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_gas]*inputs[act_input].gas_mul; |
if (inputs[act_input].rel_axis_alt!=-1) |
{ |
if (inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_alt]>300) |
act_long_alt-=last_trip_time/100; |
if (inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_alt]<-300) |
act_long_alt+=last_trip_time/100; |
act_alt=act_long_alt/1000; |
if (act_alt>120)act_alt=120; |
else if (act_alt<-120)act_alt=-120; |
} |
// process_events |
if (inputs[act_input].engine_switch_btn!=-1) |
{ |
if ((inputs[act_input].evdev_button[inputs[act_input].engine_switch_btn]==0)&&(DebugOut.Analog[16]==1)) |
{ |
ExternEvent.key=2; |
SendOutData('e', 0, (unsigned char *)&ExternEvent, sizeof(ExternEvent)); |
} |
if ((inputs[act_input].evdev_button[inputs[act_input].engine_switch_btn]!=0)&&(DebugOut.Analog[16]==0)) |
{ |
ExternEvent.key=1; |
SendOutData('e', 0, (unsigned char *)&ExternEvent, sizeof(ExternEvent)); |
} |
} |
} |
switch(input) |
{ |
case INPUT_EVDEV: |
/* |
act_nick=(evdev_rel_axis[rel_axis_nick]-nick_add)*nick_mul; |
act_roll=(evdev_rel_axis[rel_axis_roll]-nick_add)*roll_mul; |
act_gier=(evdev_rel_axis[rel_axis_gier]-nick_add)*gier_mul; |
act_gas=(evdev_rel_axis[rel_axis_gas]-nick_add)*gas_mul; |
*/ |
break; |
case INPUT_JOYDEV: |
act_nick=(axis[rel_axis_nick])*nick_mul; |
act_roll=(axis[rel_axis_roll])*roll_mul; |
act_gier=(axis[rel_axis_gier])*gier_mul; |
act_gas=(axis[rel_axis_gas]*-1+33000)*gas_mul; |
break; |
} |
// act values clipping to usefull vals |
// act_gas=0; |
// act_gas=255; |
/* |
switch (act_mode) |
{ |
case 0: |
act_nick=(axis[AXIS_NICK])*(INVERT_NICK); |
act_roll=(axis[AXIS_ROLL])*(INVERT_ROLL); |
act_gier=(axis[AXIS_GIER])*(INVERT_GIER); |
act_gas=((axis[AXIS_GAS])-128)*(-1); |
// clip gas |
if (act_gas<0) act_gas=0; |
if (act_gas>250) act_gas=250; |
//////// act_gas=0; |
break; |
case 1: |
act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/2; |
act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/2; |
act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/2; |
act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
break; |
case 2: |
act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/3; |
act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/3; |
act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/3; |
act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
break; |
} |
*/ |
ExternControl.Digital[0]=0; |
ExternControl.Digital[1]=0; |
ExternControl.RemoteTasten=0; |
ExternControl.Higt=act_alt; |
ExternControl.free=0; |
ExternControl.Frame='t'; |
ExternControl.Config=1; |
ExternControl.Nick=act_nick; //(axis[1]>>8)*(-1)/2; |
ExternControl.Roll=act_roll*(-1); //(axis[0]>>8)*(-1)/2; |
ExternControl.Gier=act_gier; // ************ |
ExternControl.Gas=act_gas; // ************ |
ExternControl.Gas=255; // ************ |
printf("act_mode %d , act_nick %d , act_roll %d , act_gier %d , act_gas %d , act_alt %d",act_mode , act_nick , act_roll , act_gier , act_gas,act_alt); |
if (connected) |
{ |
complete_matches++; |
printf("sending data\n"); |
SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
// gettimeofday(&time_struct1,NULL); |
printf("sent data\n"); |
} |
// printf("sleeping\n"); |
// for (polls=0;polls<100;polls++) // FIXME - better Polling |
// printf("end_sleep\n"); |
// int v=axis[6]/655+50; |
// if (v!=v_old)if (x52_output) x52_setbri(x52_output, 0,v ); |
// v_old=v; |
// printf("v: %d \n",v); |
/* |
for (i=0;i<num_of_axis;i++) |
printf("A%d: %d ", i,axis[i]>>8 ); |
for( x=0 ; x<num_of_buttons ; ++x ) |
printf("B%d: %d ", x, button[x] ); |
*/ |
break; |
} |
printf("\n"); |
fflush(stdout); |
printf("loop fin ( confirmed:%d misses:%d | debug_sets:%d )\n",complete_matches,complete_misses,debug_sets); |
printf("------------------------------------------------------------------------\n"); |
gettimeofday(&loop_end_time,NULL); |
last_trip_time=(unsigned long)(loop_end_time.tv_usec-loop_start_time.tv_usec)+(unsigned long)(loop_end_time.tv_sec-loop_start_time.tv_sec)*1000000; |
printf("last trip: %ld\n",last_trip_time); |
trip_count++; |
} |
/******************** Cleanup **********************/ |
close(joy_input_fd); |
close(mk_socket); |
if (x52_output) x52_close(x52_output); |
return 0; |
} |
/Riddim/riddim.conf |
---|
0,0 → 1,20 |
# Riddim Config File |
input_evdev = "/dev/input/event10" |
mk_socket_port = 54321 |
#loop_delay=20000 |
loop_delay=90000 |
#loop_delay=50000 |
#loop_delay=500000 |
# to check how the system was inited |
exit_after_init=false |
#exit_after_init=true |
#bluetooth_mac="00:0B:CE:01:2E:00" |
gas_mul=0.3 |
rel_axis_gas=2 |
nick_mul=-0.3 |
/Riddim/riddim.h |
---|
0,0 → 1,120 |
/************************************************** |
* |
* |
* Riddim |
* Remote Interactive Digital Drone Interface Mashup |
* |
* 2008 Marcus -LiGi- Bueschleb |
* |
* |
**************************************************/ |
#if !defined(RIDDIM_H) |
#define RIDDIM_H |
// for config file parsing |
#include <confuse.h> |
#include <string.h> |
#include "riddim_meta.h" |
// for configuration file parsing |
#include "config.h" |
// for measuring |
#include "statistics.h" |
// for understanding the FC |
#include "fc.h" |
#include "bluetooth_handler.h" |
#include "evdev_handler.h" |
#include "joy_handler.h" |
#include <stdio.h> |
#include <stdlib.h> |
#include <fcntl.h> |
#include "lib/x52/x52.h" |
#include <sys/socket.h> |
#include <sys/time.h> |
#include <sys/types.h> |
#include <sys/dir.h> |
#include <sys/param.h> |
#include <stdio.h> |
#include <errno.h> |
#include <sys/types.h> |
#include <netinet/in.h> |
#include <unistd.h>//for close() for socket |
extern int act_nick; |
extern int act_roll; |
extern int act_gier; |
extern int act_gas; |
extern int act_mode; |
extern int act_alt; |
extern long act_long_alt; |
#define FALSE 0 |
#define TRUE 1 |
#define STATEID_SCANNING 0 |
#define STATEID_CONNECTING 1 |
#define BUTTON_SELECT 26 |
#define BUTTON_DOWN 28 |
#define BUTTON_UP 27 |
// #define AXIS_ROLL 0 |
// #define AXIS_NICK 1 |
// #define AXIS_GIER 5 |
// #define AXIS_GAS 2 |
// for x52 |
/* |
#define AXIS_ROLL 4 |
#define AXIS_NICK 3 |
#define AXIS_GIER 5 |
#define AXIS_GAS 2 |
#define INVERT_ROLL -1 |
#define INVERT_NICK -1 |
#define INVERT_GIER 1 |
#define INVERT_GAS -1 |
*/ |
#define AXIS_ROLL 0 |
#define AXIS_NICK 1 |
#define AXIS_GIER 3 |
#define AXIS_GAS 2 |
#define INVERT_ROLL 1 |
#define INVERT_NICK -1 |
#define INVERT_GIER 1 |
#define INVERT_GAS -1 |
#define INPUT_NONE 0 |
#define INPUT_JOYDEV 1 |
#define INPUT_EVDEV 2 |
#endif |
/Riddim/riddim_meta.h |
---|
0,0 → 1,4 |
#define RIDDIM_VERSION_MAJOR 0 |
#define RIDDIM_VERSION_MINOR 9 |
#define RIDDIM_VERSION_PATCH 1 |
/Riddim/statistics.c |
---|
0,0 → 1,15 |
#include "statistics.h" |
struct timeval loop_start_time; |
struct timeval loop_end_time; |
struct timeval time_struct1; |
struct timeval time_struct2; |
int debug_sets=0; |
int confirm_sets=0; |
int version_sets=0; |
unsigned long last_trip_time=0; |
unsigned long trip_count=0; |
/Riddim/statistics.h |
---|
0,0 → 1,14 |
#include <sys/time.h> |
// time struct for measuring |
extern struct timeval loop_start_time; |
extern struct timeval loop_end_time; |
extern int debug_sets; |
extern int confirm_sets; |
extern int version_sets; |
extern unsigned long last_trip_time; |
extern unsigned long trip_count; |