- made all protocol structures explicitly carry int32_t instead of int

- fixed serial_dev_open over-writing the device name with "serial device"
- hotplug does not need to call init_devices now that we split them up,
  it's best to call init_serial_devices instead.
- preparing for reworking the string passing mechanism in protocol v1
pull/68/head
John Tsiombikas 2022-03-23 11:42:08 +02:00
rodzic 88585ca7d1
commit 34adbc5799
6 zmienionych plików z 22 dodań i 24 usunięć

Wyświetl plik

@ -40,13 +40,13 @@ static int usbdevtype(unsigned int vid, unsigned int pid);
static struct device *dev_list = NULL;
static unsigned short last_id;
int init_devices(void)
void init_devices(void)
{
init_devices_serial();
return init_devices_usb();
init_devices_usb();
}
int init_devices_serial(void)
void init_devices_serial(void)
{
struct device *dev;
spnav_event ev = {0};
@ -59,9 +59,7 @@ int init_devices_serial(void)
if(open_dev_serial(dev) == -1) {
remove_device(dev);
} else {
strcpy(dev->name, "serial device");
logmsg(LOG_INFO, "using device: %s\n", cfg.serial_dev);
device_added++;
}
/* new serial device added, send device change event */
@ -72,15 +70,13 @@ int init_devices_serial(void)
broadcast_event(&ev);
}
}
return 0;
}
int init_devices_usb(void)
{
int i;
struct device *dev;
int i, device_added = 0;
struct usb_dev_info *usblist, *usbdev;
spnav_event ev = {0};
@ -107,7 +103,6 @@ int init_devices_usb(void)
remove_device(dev);
} else {
logmsg(LOG_INFO, "using device: %s (%s)\n", dev->name, dev->path);
device_added++;
/* new USB device added, send device change event */
ev.dev.type = EVENT_DEV;
@ -161,7 +156,7 @@ void remove_device(struct device *dev)
struct device *iter;
spnav_event ev;
logmsg(LOG_INFO, "removing device: %s (id: %d)\n", dev->name, dev->id);
logmsg(LOG_INFO, "removing device: %s (id: %d path: %s)\n", dev->name, dev->id, dev->path);
dummy.next = dev_list;
iter = &dummy;

Wyświetl plik

@ -45,8 +45,8 @@ struct device {
struct device *next;
};
int init_devices(void);
int init_devices_serial(void);
void init_devices(void);
void init_devices_serial(void);
int init_devices_usb(void);
void remove_device(struct device *dev);

Wyświetl plik

@ -115,7 +115,7 @@ int open_dev_serial(struct device *dev)
if((fd = open(dev->path, O_RDWR | O_NOCTTY | O_NONBLOCK)) == -1) {
logmsg(LOG_ERR, "open_dev_serial: failed to open device: %s: %s\n", dev->path, strerror(errno));
return 0;
return -1;
}
if(!(sb = calloc(1, sizeof *sb))) {

Wyświetl plik

@ -97,7 +97,7 @@ int handle_hotplug(void)
logmsg(LOG_DEBUG, "\nhandle_hotplug called\n");
}
if(init_devices() == -1) {
if(init_devices_usb() == -1) {
return -1;
}
return 0;

Wyświetl plik

@ -1,6 +1,8 @@
#ifndef PROTO_H_
#define PROTO_H_
#include <stdint.h>
/* maximum supported protocol version */
#define MAX_PROTO_VER 1
@ -15,8 +17,8 @@ enum {
};
struct reqresp {
int type;
int data[7];
int32_t type;
int32_t data[7];
};
#define REQ_TAG 0x7faa0000
@ -30,15 +32,14 @@ struct reqresp {
*/
enum {
/* per-client settings */
REQ_SET_NAME = REQ_BASE,/* set client name: Q[0-6] name - R[6] status */
REQ_SET_NAME = REQ_BASE,/* set client name: Q[0-5] next 6 bytes Q[6] remaining length - R[6] status */
REQ_SET_SENS, /* set client sensitivity: Q[0] float - R[6] status */
REQ_GET_SENS, /* get client sensitivity: R[0] float R[6] status */
REQ_SET_EVMASK, /* set event mask: Q[0] mask - R[6] status */
REQ_GET_EVMASK, /* get event mask: R[0] mask R[6] status */
/* device queries */
REQ_DEV_NAME = 0x2000, /* get device name: R[0] length R[6] status followed
by <length> bytes */
REQ_DEV_NAME = 0x2000, /* get device name: R[0-5] next 6 bytes R[6] remaining length or -1 for failure */
REQ_DEV_PATH, /* get device path: same as above */
REQ_DEV_NAXES, /* get number of axes: R[0] num axes R[6] status */
REQ_DEV_NBUTTONS, /* get number of buttons: same as above */
@ -69,8 +70,8 @@ enum {
REQ_GCFG_LED, /* get LED state: R[0] state R[6] status */
REQ_SCFG_GRAB, /* set device grabbing: Q[0] state - R[6] status */
REQ_GCFG_GRAB, /* get device grabbing: R[0] state R[6] status */
REQ_SCFG_SERDEV, /* set serial device path: Q[0] remaining length Q[1-6] next 6 bytes - R[6] status */
REQ_GCFG_SERDEV, /* get serial device path: R[0] length R[6] status, followed by <length> bytes */
REQ_SCFG_SERDEV, /* set serial device path: Q[0-5] next 6 bytes Q[6] remaining length - R[6] status */
REQ_GCFG_SERDEV, /* get serial device path: R[0-5] next 6 bytes R[6] remaining length or -1 for failure */
/* TODO ... more */
REQ_CFG_SAVE = 0x3ffe, /* save config file: R[6] status */
REQ_CFG_RESTORE, /* load config from file: R[6] status */

Wyświetl plik

@ -100,7 +100,8 @@ int get_unix_socket(void)
void send_uevent(spnav_event *ev, struct client *c)
{
int i, data[8] = {0};
int i;
int32_t data[8] = {0};
float motion_mul;
if(lsock == -1) return;
@ -114,7 +115,7 @@ void send_uevent(spnav_event *ev, struct client *c)
motion_mul = get_client_sensitivity(c);
for(i=0; i<6; i++) {
float val = (float)ev->motion.data[i] * motion_mul;
data[i + 1] = (int)val;
data[i + 1] = (int32_t)val;
}
data[7] = ev->motion.period;
break;
@ -187,7 +188,8 @@ int handle_uevents(fd_set *rset)
int s = get_client_socket(c);
if(FD_ISSET(s, rset)) {
int rdbytes, msg;
int rdbytes;
int32_t msg;
float sens;
/* handle client requests */