Caanoo / WIZ Use Haptic(Vibration) On Caanoo


Rikku2000

Member
Joined
Jul 2, 2010
Messages
348
So guys here i make an small HowToUse Tutorial for CAANOO

HAPTIC

Header and Others stuff:
Code:
#include <sys/ioctl.h>

#include "simple_isa1200if.h"

#define DEVICE_FILENAME "/dev/isa1200"
#define ARRAY_SIZE(x) ((sizeof(x)) / (sizeof(x[0])))

int fd;

pattern_data_t pattern_data;

pattern_data_t ptn_double_strong_long = {
	.act_number = 6,
	.vib_act_array = {
		[0] = {0, 126},
		[1] = {100, -126},
		[2] = {120, 0},
		[3] = {150, -126},
		[4] = {250,	-126},
		[5] = {265,	0},
	}
};

pattern_data_t ptn_fadein_strong_long = {
	.act_number = 46,
	.vib_act_array = {
		{5,		26},			// 0
		{10,	28},
		{15,	31},
		{20,	33},
		{25,	34},
		{30,	37},
		{35,	39},
		{40,	41},
		{45,	43},
		{50,	45},
		{55,	48},			// 10
		{60,	50},
		{65,	52},
		{70,	54},
		{75,	57},
		{80,	59},
		{85,	61},
		{90,	63},
		{95,	66},
		{100,	68},
		{105,	70},			//20
		{110,	72},
		{115,	75},
		{120,	77},
		{125,	80},
		{130,	81},
		{135,	84},
		{140,	86},
		{145,	89},
		{150,	90},
		{155,	93},			//30
		{160,	95},
		{165,	97},
		{170,	99},
		{175,	102},
		{180,	104},
		{185,	106},
		{190,	108},
		{195,	110},
		{200,	113},
		{205,	115},			//40
		{210,	117},
		{215,	119},
		{220,	121},
		{225,	124},
		{225,	0},				//45
	}
};

pattern_data_t ptn_strong_long = {
	.act_number = 3,
	.vib_act_array = {
		{0,	126},
		{100,	-126},
		{115,	0},
	}
};

pattern_data_t ptn_weak_high_freq = {
	.act_number = 10,
	.vib_act_array = {
		{0,		65},
		{45,	0},
		{50,	65},
		{95,	0},
		{100,	65},
		{145,	0},
		{150,	65},
		{195,	0},
		{200,	65},
		{245,	0},
	}
};

pattern_data_t ptn_double_long_middle = {
	.act_number = 6,
	.vib_act_array = {
		{0,	126},
		{30,	-126},
		{50,	0},
		{70,	126},
		{100,	-126},
		{115,	0},
	}
};

pattern_data_t ptn_double_strong_short = {
	.act_number = 6,
	.vib_act_array = {
		{0,	126},
		{10,	-126},
		{15,	0},
		{40,	126},
		{50,	-126},
		{55,	0},
	}
};

pattern_data_t ptn_fadeout_strong_long = {
	.act_number = 46,
	.vib_act_array = {
		{0	,126},
		{5	,124},
		{10	,121},
		{15	,119},
		{20	,117},
		{25	,115},
		{30	,113},
		{35	,110},
		{40	,108},
		{45	,106},
		{50	,104},
		{55	,102},
		{60	,99},
		{65	,97},
		{70	,95},
		{75	,93},
		{80	,90},
		{85	,89},
		{90	,86},
		{95	,84},
		{100,	81},
		{105,	80},
		{110,	77},
		{115,	75},
		{120,	72},
		{130,	68},
		{135,	66},
		{140,	63},
		{145,	61},
		{150,	59},
		{155,	57},
		{160,	54},
		{165,	52},
		{170,	50},
		{175,	48},
		{180,	45},
		{185,	43},
		{190,	41},
		{195,	39},
		{200,	37},
		{205,	34},
		{210,	33},
		{215,	31},
		{220,	28},
		{225,	26},
		{225,	0},
	}
};

pattern_data_t ptn_strong_high_freq = {
	.act_number = 10,
	.vib_act_array = {
		{0	,126},
		{45	,0},
		{50	,126},
		{95	,0},
		{100	,126},
		{145	,0},
		{150	,126},
		{195	,0},
		{200	,126},
		{245	,0},
	}
};

typedef struct pattern_list {
	pattern_data_t * pattern_data;
	char name[50];
} pattern_list_t;

pattern_list_t pattern_list[] = {
	&(ptn_double_strong_long), "Double Strong Long",
	&(ptn_fadein_strong_long), "Fadein Strong long",
	&(ptn_strong_long), "Strong Long",
	&(ptn_weak_high_freq), "Weak High Frequency",
	&(ptn_strong_high_freq ), "Strong High Frequence",	
	&(ptn_double_long_middle), "Double Long Middle",
	&(ptn_double_strong_short), "Double Strong Short",
	&(ptn_fadeout_strong_long), "Fade Out Strong Long",
};

The Voids we need:
Code:
void individual_test_enable(void) {
	int flag;
	flag = 1;
	ioctl(fd, IOCTL_INDIVIDUAL_MODE, &flag);
}

void individual_test_disable(void) {
	int flag; 
	flag = 0;
	ioctl(fd, IOCTL_INDIVIDUAL_MODE, &flag);
}

void isa1200a_enable(void) {
	ioctl(fd, IOCTL_ISA1200A_ENABLE);
}

void isa1200b_enable(void) {
	ioctl(fd, IOCTL_ISA1200B_ENABLE);
}

int get_time_interval(void) {
   	int ret;
	printf("input interval(millisecond)...");
	scanf("%d", &ret);

	return ret;
}

int get_duty_cycle(void) {
	int ret;
	printf("input strength(Max: %d, Min: %d )...", VIB_STRENGTH_MAX, VIB_STRENGTH_MIN);
	scanf("%d", &ret);

	return ret;
}

void haptic(int n) { // Haptic: 0/6
	pattern_data_t * sel_pattern;
	sel_pattern = pattern_list[n].pattern_data;
	ioctl(fd, IOCTL_PLAY_PATTERN, sel_pattern);
}

Init the Haptic in MAIN:
Code:
	fd = open(DEVICE_FILENAME, O_RDWR|O_NDELAY);
	if(fd <= 0)
	   	printf("%s open failed..\n", DEVICE_FILENAME);
	else
		printf("%s file open success...\n", DEVICE_FILENAME);

	individual_test_enable();

	isa1200a_enable();
	isa1200b_enable();

Deinit the Haptic:
Code:
individual_test_disable();

Now we Call an Heptic:
Code:
haptic(1);

3G Sensor

Header and Others stuff:
Code:
#include <setjmp.h>
#include <sys/sem.h>
#include <sys/poll.h>

#include "te9_tf9_hybrid_driver.h"
#include "te9_tf9_main.h"
#include "te9_tf9_regs.h"

char str[64];
int accel_fd, exitIrqChecker = 0;
struct sigaction sigact, oldact;
static ACCEL_XYZ accel_val;

/* Signal Handler... */
static void irqChecker_sigHandler(int signo) {
	switch(signo) {
		case SIGIO:
			// KxPrint("-I- SIGIO\n");
			KIONIX_ACCEL_service_interrupt();
			break;

		case SIGINT:
		case SIGQUIT:
			KxPrint("-I- SIGINT or SIGQUIT\n");
			exitIrqChecker = 1;
			break;
	}

	return;
}

/* Device File Initialization... */
int init_accel_device_file(void) {
	accel_fd = open("/dev/accel", O_RDWR); // blocking mode open... 
	if (accel_fd == -1){
		printf("-E- Error opening accel adapter\n");
		return -1;
	}

	return 0;
}

/* Sig Action Function Initialization... */
void init_sigact(void) {
	int oflag;

	sigact.sa_handler = irqChecker_sigHandler;
	sigemptyset(&sigact.sa_mask);
	sigact.sa_flags = SA_INTERRUPT;

	if(sigaction(SIGIO, &sigact, &oldact) < 0) {
		KxPrint("-W- can't receive SIGIO event\n");
			if(accel_fd)
				close(accel_fd);
	}

	fcntl(accel_fd, F_SETOWN, getpid());
	oflag = fcntl(accel_fd, F_GETFL);
	fcntl(accel_fd, F_SETFL, oflag | FASYNC);
}

void AccelTest_Init(void) {
	int device_type;

	KIONIX_ACCEL_init();

	device_type = KIONIX_ACCEL_get_device_type();
	if(device_type != DEVICE_TYPE_KIONIX_KXTF9)	{
		printf("Wrong device type, val: %d\n", device_type);
	}

	KXTF9_set_G_range(2);
	KXTF9_set_resolution(12);
	KIONIX_ACCEL_int_activeh();
	KIONIX_ACCEL_int_latch();

	KXTF9_set_odr_tap(400);

	KXTF9_tap_unmask_TFU();
	KXTF9_tap_unmask_TFD();
	KXTF9_tap_unmask_TUP();
	KXTF9_tap_unmask_TDO();

	KXTF9_tap_mask_TRI();
	KXTF9_tap_mask_TLE();

	KXTF9_enable_tap_detection();
	KXTF9_set_odr_tilt(12);		
	KIONIX_ACCEL_tilt_timer(5);

	KIONIX_ACCEL_position_unmask_fu();
	KIONIX_ACCEL_position_unmask_fd();

	KIONIX_ACCEL_position_mask_up();
	KIONIX_ACCEL_position_mask_do();
	KIONIX_ACCEL_position_mask_ri();
	KIONIX_ACCEL_position_mask_le();

	KIONIX_ACCEL_enable_tilt_function();

	KIONIX_ACCEL_enable_interrupt();
	KIONIX_ACCEL_enable_outputs();
}

void AccelTest_deinit(void) {
	KIONIX_ACCEL_deinit();

	if(accel_fd)
		close(accel_fd);
}

Init the Sensor in MAIN:
Code:
        fd = open(DEVICE_FILENAME, O_RDWR|O_NDELAY);
        if(fd <= 0)
                printf("%s open failed..\n", DEVICE_FILENAME);
        else
                printf("%s file open success...\n", DEVICE_FILENAME);

        individual_test_enable();

        isa1200a_enable();
        isa1200b_enable();

Deinit the Sensor:
Code:
AccelTest_deinit();

Now we Call an Sensor:
Code:
	while(1) {
		KIONIX_ACCEL_read_LPF_g(&accel_val.x, &accel_val.y, &accel_val.z);
		// printf("X-Y-Z = %d mg, %d mg, %d mg\n", accel_val.x, accel_val.y, accel_val.z);

		if (accel_val.y < -80) {} // Up
		if (accel_val.x < -120) {} // Left
		if (accel_val.y > 80) {} // Down
		if (accel_val.x > 120) {} // Right
	}
 
Thanks,
Nice tutorial. Maybe I find use for it as the caanoo actually have such nice hardware in it. :)

One question: How do the arrays describe the rumble effect (I mean the numbers)? Do they describe the strength of rumble on the left/right side?
 
lenrlad said:
That means it's no problem of making custom rumble effects? It would be nice if you're not forced to use standard effects. :)

maybe this http://sbock.net/upload/Haptic_Motor_API.pdf brings a bit more insight to the variables used in the example ;)
 
Last edited by a moderator:
crow_riot said:
lenrlad said:
That means it's no problem of making custom rumble effects? It would be nice if you're not forced to use standard effects. :)

maybe this http://sbock.net/upl...c_Motor_API.pdf brings a bit more insight to the variables used in the example ;)

Hey thanks.
Where do you get this. Looks like sbock had uploaded it.

EDIT:
Arrrgh...
Second thread at this board.
 
Last edited by a moderator:
Nope its from GPH SDK but it have a lot of code and thats the easy way to add the Haptic and GSensor to your project with some small infos.
 
crow_riot said:
lenrlad said:
That means it's no problem of making custom rumble effects? It would be nice if you're not forced to use standard effects. :)

maybe this http://sbock.net/upl...c_Motor_API.pdf brings a bit more insight to the variables used in the example ;)
Are you kidding me? I'm German and not Korean!!! :angry: But I get that the first value is the time in milliseconds and the second the strange of rumble. (English Diagrams :blink: )

Rikku2000 said:
Nope its from GPH SDK but it have a lot of code and thats the easy way to add the Haptic and GSensor to your project with some small infos.
Your tut is nice, yes.
But I mean crow_riot's hint with the (Korean) API Documentation by GPH, uploaded by sbock. Not your tutorial code. ;)

lenrlad
 
Last edited by a moderator:
well there's nothing more than this available, GPH didnt translate it. but the code samples should be enough to understand what the values mean...
 
Wonderful Rikku!!!

Could you give an example of the touch screen? If it is not asking too much.
 
crow_riot said:
lenrlad said:
That means it's no problem of making custom rumble effects? It would be nice if you're not forced to use standard effects. :)

maybe this http://sbock.net/upload/Haptic_Motor_API.pdf brings a bit more insight to the variables used in the example ;)

Does anyone know where can i get this in English?
 
Last edited by a moderator:
Back
Top