Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** Copyright 2012, Alexey Roslyakov <alexey.roslyakov@newsycat.com>
- **
- ** Licensed under the Apache License, Version 2.0 (the "License");
- ** you may not use this file except in compliance with the License.
- ** You may obtain a copy of the License at
- **
- ** http://www.apache.org/licenses/LICENSE-2.0
- **
- ** Unless required by applicable law or agreed to in writing, software
- ** distributed under the License is distributed on an "AS IS" BASIS,
- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ** See the License for the specific language governing permissions and
- ** limitations under the License.
- */
- #include <unistd.h>
- #include <errno.h>
- #include <stdio.h>
- #include <fcntl.h>
- #include <linux/input.h>
- static int print_usage(const char *prog)
- {
- fprintf(stderr, "Usage: %s <force_feedback_device_path>\n", prog);
- return -1;
- }
- int main(int argc, const char **argv)
- {
- int i;
- if (argc != 2)
- return print_usage(argv[0]);
- struct input_event play;
- struct input_event stop;
- struct ff_effect effect;
- int fd, res;
- fd = open(argv[1], O_RDWR);
- if (fd <= 0)
- perror("open");
- //unsigned short data[] = {1000,10000, 1000, 10000,0};
- unsigned short data[500];
- for (i=0; i < 500; i+=2) {
- data[i] = 0xff;
- data[i+1] = 0xff;
- }
- memset(&effect, 1, sizeof(effect));
- effect.id = -1;
- effect.type = FF_PERIODIC;
- effect.u.periodic.waveform = FF_CUSTOM;
- effect.u.periodic.period = 6;//100*0x100;
- effect.u.periodic.magnitude = 0;//0x7000;
- effect.u.periodic.offset = 0;
- effect.u.periodic.custom_len = 500;
- effect.u.periodic.custom_data = data;
- effect.direction = 0x40000;
- effect.u.periodic.envelope.attack_length = 0x1000;
- effect.u.periodic.envelope.attack_level = 0x7fff;
- effect.u.periodic.envelope.fade_length = 0;//0x100;
- effect.u.periodic.envelope.fade_level = 0;
- effect.trigger.button = 0;
- effect.trigger.interval = 0;
- effect.replay.length = 1; /* 20 seconds */
- for (i=0; i < 50; i++) {
- res = ioctl(fd, EVIOCSFF, &effect);
- fprintf(stderr, "EVIOCSFF res: %d %d\n", res, effect.id);
- int gain = 100; /* between 0 and 100 */
- struct input_event ie; /* structure used to communicate with the driver */
- ie.type = EV_FF;
- ie.code = FF_GAIN;
- ie.value = 0xFFFFUL;// * gain / 100;
- #if 1
- if (write(fd, &ie, sizeof(ie)) == -1)
- perror("set gain");
- fprintf(stderr, "eff.id: %d\n", effect.id);
- #endif
- /* Play three times */
- //play.id = 0;
- play.type = EV_FF;
- play.code = effect.id;
- play.value = 3;
- write(fd, (const void*) &play, sizeof(play));
- //.....
- /* Stop an effect */
- stop.type = EV_FF;
- stop.code = effect.id;
- stop.value = 0;
- //sleep(1);
- write(fd, (const void*) &stop, sizeof(stop));
- usleep(12*1000);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement