Browse Source

set_led

main
h3ndrik 13 years ago
parent
commit
a3fb3597f0
  1. BIN
      hid-example
  2. 182
      hid-example.c~
  3. BIN
      sdljpd
  4. 17
      sdljpd.c~
  5. BIN
      set_led
  6. 67
      set_led.c
  7. 67
      set_led.c~

BIN
hid-example

Binary file not shown.

182
hid-example.c~

@ -0,0 +1,182 @@
/*
* Hidraw Userspace Example
*
* Copyright (c) 2010 Alan Ott <alan@signal11.us>
* Copyright (c) 2010 Signal 11 Software
*
* The code may be used by anyone for any purpose,
* and can serve as a starting point for developing
* applications using hidraw.
*/
/* Linux */
#include <linux/types.h>
#include <linux/input.h>
#include <linux/hidraw.h>
/*
* Ugly hack to work around failing compilation on systems that don't
* yet populate new version of hidraw.h to userspace.
*
* If you need this, please have your distro update the kernel headers.
*/
#ifndef HIDIOCSFEATURE
#define HIDIOCSFEATURE(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x06, len)
#define HIDIOCGFEATURE(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x07, len)
#endif
/* Unix */
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
/* C */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
const char *bus_str(int bus);
int main(int argc, char **argv)
{
int fd;
int i, res, desc_size = 0;
char buf[256];
struct hidraw_report_descriptor rpt_desc;
struct hidraw_devinfo info;
/* Open the Device with non-blocking reads. In real life,
don't use a hard coded path; use libudev instead. */
fd = open("/dev/hidraw0", O_RDWR|O_NONBLOCK);
if (fd < 0) {
perror("Unable to open device");
return 1;
}
memset(&rpt_desc, 0x0, sizeof(rpt_desc));
memset(&info, 0x0, sizeof(info));
memset(buf, 0x0, sizeof(buf));
/* Get Report Descriptor Size */
res = ioctl(fd, HIDIOCGRDESCSIZE, &desc_size);
if (res < 0)
perror("HIDIOCGRDESCSIZE");
else
printf("Report Descriptor Size: %d\n", desc_size);
/* Get Report Descriptor */
rpt_desc.size = desc_size;
res = ioctl(fd, HIDIOCGRDESC, &rpt_desc);
if (res < 0) {
perror("HIDIOCGRDESC");
} else {
printf("Report Descriptor:\n");
for (i = 0; i < rpt_desc.size; i++)
printf("%hhx ", rpt_desc.value[i]);
puts("\n");
}
/* Get Raw Name */
res = ioctl(fd, HIDIOCGRAWNAME(256), buf);
if (res < 0)
perror("HIDIOCGRAWNAME");
else
printf("Raw Name: %s\n", buf);
/* Get Physical Location */
res = ioctl(fd, HIDIOCGRAWPHYS(256), buf);
if (res < 0)
perror("HIDIOCGRAWPHYS");
else
printf("Raw Phys: %s\n", buf);
/* Get Raw Info */
res = ioctl(fd, HIDIOCGRAWINFO, &info);
if (res < 0) {
perror("HIDIOCGRAWINFO");
} else {
printf("Raw Info:\n");
printf("\tbustype: %d (%s)\n",
info.bustype, bus_str(info.bustype));
printf("\tvendor: 0x%04hx\n", info.vendor);
printf("\tproduct: 0x%04hx\n", info.product);
}
/* Set Feature */
// buf[0] = 0x9; /* Report Number */
// buf[1] = 0xff;
// buf[2] = 0xff;
// buf[3] = 0xff;
// res = ioctl(fd, HIDIOCSFEATURE(4), buf);
// if (res < 0)
// perror("HIDIOCSFEATURE");
// else
// printf("ioctl HIDIOCGFEATURE returned: %d\n", res);
/* Get Feature */
// buf[0] = 0x9; /* Report Number */
// res = ioctl(fd, HIDIOCGFEATURE(256), buf);
// if (res < 0) {
// perror("HIDIOCGFEATURE");
// } else {
// printf("ioctl HIDIOCGFEATURE returned: %d\n", res);
// printf("Report data (not containing the report number):\n\t");
// for (i = 0; i < res; i++)
// printf("%hhx ", buf[i]);
// puts("\n");
// }
/* Send a Report to the Device */
buf[0] = 0x0; /* Report Number */
buf[1] = 0x00;
buf[2] = 0x01;
buf[3] = 0x00;
buf[4] = 0x00;
buf[5] = 0x01;
res = write(fd, buf, 6);
if (res < 0) {
printf("Error: %d\n", errno);
perror("write");
} else {
printf("write() wrote %d bytes\n", res);
}
/* Get a report from the device */
res = read(fd, buf, 16);
if (res < 0) {
perror("read");
} else {
printf("read() read %d bytes:\n\t", res);
for (i = 0; i < res; i++)
printf("%hhx ", buf[i]);
puts("\n");
}
close(fd);
return 0;
}
const char *
bus_str(int bus)
{
switch (bus) {
case BUS_USB:
return "USB";
break;
case BUS_HIL:
return "HIL";
break;
case BUS_BLUETOOTH:
return "Bluetooth";
break;
case BUS_VIRTUAL:
return "Virtual";
break;
default:
return "Other";
break;
}
}

BIN
sdljpd

Binary file not shown.

17
sdljpd.c~

@ -26,6 +26,7 @@
#include "SDL_image.h" #include "SDL_image.h"
#include "SDL_ttf.h" #include "SDL_ttf.h"
#include "SDL_mixer.h" #include "SDL_mixer.h"
#include "SDL_haptic.h"
/* Define our booleans */ /* Define our booleans */
#define TRUE 1 #define TRUE 1
@ -464,7 +465,7 @@ void draw_sdl (void)
for (i=0; i<strlen(myblock[xpos][ypos].antwort); i+=45) for (i=0; i<strlen(myblock[xpos][ypos].antwort); i+=45)
{ {
drect.y = drect.y + 23; drect.y = drect.y + 23;
strncpy(buf,myblock[xpos][ypos].antwort,45); strncpy(buf,myblock[xpos][ypos].antwort+i,45);
SDL_FreeSurface(text); SDL_FreeSurface(text);
text = TTF_RenderText_Blended(font, buf , color); text = TTF_RenderText_Blended(font, buf , color);
SDL_BlitSurface(text,NULL,surface,&drect); SDL_BlitSurface(text,NULL,surface,&drect);
@ -663,6 +664,20 @@ int main( int argc, char **argv )
printf ( "%s\n", SDL_JoystickName ( 0 ) ); printf ( "%s\n", SDL_JoystickName ( 0 ) );
SDL_Haptic *haptic;
haptic = SDL_HapticOpen( 0 );
if (haptic == NULL)
return -1;
if (SDL_HapticRumbleInit( haptic ) != 0)
return -1;
if (SDL_HapticRumblePlay( haptic, 0.5, 2000 ) != 0)
return -1;
SDL_Delay( 2000 );
SDL_HapticClose( haptic );
SDL_WM_SetCaption(wmcapt, NULL); SDL_WM_SetCaption(wmcapt, NULL);
/*SDL_WM_SetIcon(SDL_LoadBMP("glpong.bmp"),NULL);*/ /*SDL_WM_SetIcon(SDL_LoadBMP("glpong.bmp"),NULL);*/

BIN
set_led

Binary file not shown.

67
set_led.c

@ -0,0 +1,67 @@
#include <linux/types.h>
#include <linux/input.h>
#include <linux/hidraw.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
int main(int argc, char **argv)
{
int fd;
int res = 0;
char buf[256];
/* Open the Device with non-blocking reads. In real life,
don't use a hard coded path; use libudev instead. */
fd = open("/dev/hidraw0", O_RDWR|O_NONBLOCK);
if (fd < 0) {
perror("Unable to open device");
return 1;
}
memset(buf, 0x0, sizeof(buf));
switch (argv[1][0]) {
case '0':
break;
case '1':
buf[2] = 0xff;
break;
case '2':
buf[3] = 0xff;
break;
case '3':
buf[4] = 0xff;
break;
case '4':
buf[5] = 0xff;
break;
default:
printf("Please specify 0 ... 4 as single argument.\n");
}
/* Send a Report to the Device */
buf[0] = 0x00; /* Report Number */
buf[1] = 0x00; /* Report ID */
//buf[2] = 0x01; /* Buzzer 1 */
//buf[3] = 0x00; /* Buzzer 2 */
//buf[4] = 0x00; /* Buzzer 3 */
//buf[5] = 0x01; /* Buzzer 4 */
res = write(fd, buf, 6);
if (res < 0) {
printf("Error: %d\n", errno);
perror("write");
} else {
//printf("write() wrote %d bytes\n", res);
}
close(fd);
return 0;
}

67
set_led.c~

@ -0,0 +1,67 @@
#include <linux/types.h>
#include <linux/input.h>
#include <linux/hidraw.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
int main(int argc, char **argv)
{
int fd;
int i, res = 0;
char buf[256];
/* Open the Device with non-blocking reads. In real life,
don't use a hard coded path; use libudev instead. */
fd = open("/dev/hidraw0", O_RDWR|O_NONBLOCK);
if (fd < 0) {
perror("Unable to open device");
return 1;
}
memset(buf, 0x0, sizeof(buf));
switch (argv[1][0]) {
case '0':
break;
case '1':
buf[2] = 0xff;
break;
case '2':
buf[3] = 0xff;
break;
case '3':
buf[4] = 0xff;
break;
case '4':
buf[5] = 0xff;
break;
default:
printf("Please specify 0 ... 4 as single argument.\n");
}
/* Send a Report to the Device */
buf[0] = 0x00; /* Report Number */
buf[1] = 0x00; /* Report ID */
//buf[2] = 0x01; /* Buzzer 1 */
//buf[3] = 0x00; /* Buzzer 2 */
//buf[4] = 0x00; /* Buzzer 3 */
//buf[5] = 0x01; /* Buzzer 4 */
res = write(fd, buf, 6);
if (res < 0) {
printf("Error: %d\n", errno);
perror("write");
} else {
//printf("write() wrote %d bytes\n", res);
}
close(fd);
return 0;
}
Loading…
Cancel
Save