Tool/software: Linux
I am trying to test the DRV2605 using an ERM with the Linux driver (github.com/.../drv260x.c) installed. On startup the motor works during calibration, however I am unable to get it to work by writing to the device file as described in www.kernel.org/.../ff.html. Test code below
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <linux/input.h>
#include <sys/ioctl.h>
#define BITS_TO_LONGS(x) \
(((x) + 8 * sizeof (unsigned long) - 1) / (8 * sizeof (unsigned long)))
unsigned long features[BITS_TO_LONGS(FF_CNT)];
int main(const int argc, const char **argv)
{
int fd;
if (argc != 2) {
printf("usage: %s <device-file>\n", argv[0]);
return 1;
}
fd = open(argv[1], O_RDWR);
if (fd < 0) {
printf("Error opening file '%s': %s\n", argv[1], strerror(errno));
return 1;
}
int num_effects;
if (ioctl(fd, EVIOCGEFFECTS, &num_effects) < 0) {
printf("Error getting number of effects playable at the same time: %s\n", strerror(errno));
return 1;
}
printf("%d effects playable at the same time\n", num_effects);
struct ff_effect effect = {
.type = FF_RUMBLE,
.id = -1,
.direction = 0,
.trigger = {0, 0},
.replay = {
.length = 1000,
.delay = 0
}
};
effect.u.rumble.strong_magnitude = 0x7F;
if (ioctl(fd, EVIOCSFF, &effect) < 0) {
printf("Error creating new effect: %s\n", strerror(errno));
return 1;
}
printf("New effect ID: %d\n", effect.id);
struct input_event play = {
.type = EV_FF,
.code = effect.id,
.value = 3
};
if (write(fd, (const void*) &play, sizeof(play)) < 0) {
printf("Error writing effect to file: %s\n", strerror(errno));
return 1;
}
printf("Wrote effect\n");
return 0;
}
The program runs fine with no errors but nothing happens to the ERM.