void effect(struct razer_chroma *chroma)
{
	int r,g,b;
	int rnd=random();
	int rnd2=random();
	int rnd3=random();
	int count = 0;
	int count_dir = 1;
	float s = 0.1f;
	int x,y;
	struct razer_rgb col;
	struct razer_pos pos;
	col.r = 255;
	col.g = 0;
	col.b = 0;
	while(running)
	{
		for(x=0;x<22;x++)
			for(y=0;y<6;y++)
			{
				r = (cos((count+((rnd%4)*90)+y)*s)+sin(count+x)*s)*255;
				g = (cos((count+((rnd2%4)*90)+y)*s)+sin(count+x)*s)*255;
				b = (cos((count+((rnd3%4)*90)+y)*s)+sin(count+x)*s)*255;
				chroma->keys->rows[y].column[x].r = (unsigned char)r;
				chroma->keys->rows[y].column[x].g = (unsigned char)g;
				chroma->keys->rows[y].column[x].b = (unsigned char)b;
				chroma->keys->update_mask |= 1<<y;
			}

		for(int i=0;i<keys_max;i++)
			if(keys_history[i]!=-1)
			{
				convert_keycode_to_pos(keys_history[i],&pos);							
				set_key_pos(chroma->keys,&pos,&col);
			}
		razer_update_keys(chroma,chroma->keys);
		count+=count_dir;
		if(count<=0 || count>=30)
		{
			count_dir=-count_dir;
			rnd = random();
			rnd2 = random();
			rnd3 = random();
		}
		razer_update(chroma);
		razer_frame_limiter(chroma,13);
	}
}
コード例 #2
0
ファイル: first_test.c プロジェクト: circuz/RazerConfig
int main(int argc,char *argv[])
{
	uid_t uid = getuid();
	if(uid != 0)
		printf("This program needs root to work correctly.\n");	
	struct razer_chroma *chroma = razer_open();
	if(!chroma)
		exit(1);
 	razer_set_input_handler(chroma,input_handler);
 	razer_set_custom_mode(chroma);
	razer_clear_all(chroma->keys);
	razer_update_keys(chroma,chroma->keys);
	for(int i=0;i<10;i++)
		keys_history[i] = -1;
 	signal(SIGINT,stop);
 	signal(SIGKILL,stop);
 	signal(SIGTERM,stop);	
	effect(chroma);
 	razer_close(chroma);
}
コード例 #3
0
ファイル: first_test.c プロジェクト: circuz/RazerConfig
void effect(struct razer_chroma *chroma)
{
	int r = 128, g = 0, b = 0;
	int count = 1;
	int count_dir = 1;
	int x,y;
	int span = 20;
	double c = 0;
	struct razer_rgb col;
	struct razer_rgb green = {.r=0,.g=255,.b=0}; //define a green color
	struct razer_pos pos;
	col.r = 0;
	col.g = 255;
	col.b = 0;
	while(running){


		//r += rand_span(span);
		r = count;		
		r = fixed_range(r, 255);

		g += rand_span(span);
		g = fixed_range(g, 255);
		g = 0;		

		b += rand_span(span);
		b = fixed_range(b, 255);
		b = 0;

		for(x=0;x<22;x++){
				for(y=0;y<6;y++){	
					
					g = fixed_range(r - (x * 10), 255);				
					
					chroma->keys->rows[y].column[x].r = (unsigned char)r;
					chroma->keys->rows[y].column[x].g = (unsigned char)g;
					chroma->keys->rows[y].column[x].b = (unsigned char)b;
					chroma->keys->update_mask |= 1<<y;
				}
			}

		
		col.g = (sin(c) + 1)/2 * 225;
		col.b = 255 - col.g;
		c += 0.05;

		pos.x = 2;
		pos.y = 3;
		razer_set_key_pos(chroma->keys,&pos,&green);
		pos.x += 1;
		razer_set_key_pos(chroma->keys,&pos,&green);
		pos.y -= 1;
		razer_set_key_pos(chroma->keys,&pos,&green);
		pos.y += 1; 
		pos.x += 1;
		razer_set_key_pos(chroma->keys,&pos,&green);
		
		for(int i=0;i<keys_max;i++)
			if(keys_history[i]!=-1){
				
				razer_convert_keycode_to_pos(keys_history[i],&pos);							
				razer_set_key_pos(chroma->keys,&pos,&col);
				
				if(pos.x == 17 && pos.y == 0){
					for(int i=0;i<keys_max;i++){
						keys_history[i] = -1;
					}
				}
				
			}
	

		razer_update_keys(chroma,chroma->keys);
		count+=count_dir;
		if(count<=0 || count>255){
			count_dir=-count_dir;
		}
		razer_update(chroma);
		razer_frame_limiter(chroma,13);
	
	}
}

#pragma GCC diagnostic pop

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"

void stop(int sig)
{
	#ifdef USE_DEBUGGING
		printf("Stopping input example\n");
	#endif
	running = 0;
}
コード例 #4
0
struct razer_daemon *daemon_open(void)
{
 	//signal(SIGINT,stop);
 	//signal(SIGKILL,stop);
        //signal(SIGTERM,stop);
	struct razer_daemon *daemon = (struct razer_daemon*)malloc(sizeof(struct razer_daemon));
 	daemon->chroma = NULL;
 	daemon->running = 1;
 	daemon->is_paused = 0;
 	daemon->fps = 12;
 	daemon->libs_uid = 1;
 	daemon->libs = list_Create(0,0);
 	daemon->effects_uid = 1;
 	daemon->effects = list_Create(0,0);
 	daemon->fx_render_nodes_uid = 1;
 	daemon->fx_render_nodes = list_Create(0,0);//list of all render_nodes available
 	daemon->is_render_nodes_dirty = 0;
 	daemon->render_nodes = list_Create(0,0);

 	if(!(daemon->chroma=razer_open()))
 	{
 		free(daemon->chroma);
		list_Close(daemon->libs);
		list_Close(daemon->fx_render_nodes);
		list_Close(daemon->render_nodes);
		list_Close(daemon->effects);
 		free(daemon);
		return(NULL);
	}
	#ifdef USE_DBUS
	 	daemon->dbus = NULL;
		#ifdef USE_DEBUGGING
			printf("dbus: opened\n");
		#endif
	 	if(!daemon_dbus_open(daemon))
	 	{
	 		free(daemon->chroma);
			list_Close(daemon->libs);
			list_Close(daemon->fx_render_nodes);
			list_Close(daemon->render_nodes);
			list_Close(daemon->effects);
	 		free(daemon);
			return(NULL);
		}
	 	if(!daemon_dbus_announce(daemon))
	 	{
 			free(daemon->chroma);
			list_Close(daemon->libs);
			list_Close(daemon->fx_render_nodes);
			list_Close(daemon->render_nodes);
			list_Close(daemon->effects);
	 		free(daemon);
			return(NULL);
		}
	#endif
	razer_set_input_handler(daemon->chroma,daemon_input_event_handler);
	daemon->chroma->tag = daemon;
	daemon->frame_buffer = razer_create_rgb_frame();
	daemon->frame_buffer_linked_uid = 0;
	daemon->return_render_node = NULL; //TODO remember what i wanted to achieve with this variable ... :-)

	razer_set_custom_mode(daemon->chroma);
	razer_clear_all(daemon->chroma->keys);
	razer_update_keys(daemon->chroma,daemon->chroma->keys);

	//TODO Move to configuration options (dbus race condition present)

	#ifdef USE_DEBUGGING
		struct daemon_lib *lib = daemon_load_fx_lib(daemon,"daemon/fx/pez2001_collection_debug.so");
	#else
		//void *lib = daemon_load_fx_lib(daemon,"daemon/fx/pez2001_collection.so");
		struct daemon_lib *lib = daemon_load_fx_lib(daemon,"/usr/share/razer_bcd/fx/pez2001_collection.so");
	#endif
	if(lib)
		daemon_register_lib(daemon,lib);

	#ifdef USE_DEBUGGING
		struct daemon_lib *blib = daemon_load_fx_lib(daemon,"daemon/fx/pez2001_light_blast_debug.so");
	#else
		struct daemon_lib *blib = daemon_load_fx_lib(daemon,"/usr/share/razer_bcd/fx/pez2001_light_blast.so");
	#endif
	if(lib)
		daemon_register_lib(daemon,blib);

	//daemon->render_node = daemon_create_render_node(daemon,daemon_get_effect(daemon,2),-1,-1,0,"First Render Node","Default Render Node");
	daemon->render_node = daemon_create_render_node(daemon,daemon_get_effect(daemon,11),-1,-1,0,"First Render Node","Default Render Node");
	daemon_register_render_node(daemon,daemon->render_node);
	daemon_compute_render_nodes(daemon);
	daemon_connect_frame_buffer(daemon,daemon->render_node);

	/*daemon->render_node = daemon_create_render_node(daemon,daemon_get_effect(daemon,3),-1,-1,0,"Second Test Render Node","Additional Testing Render Node");
	daemon_register_render_node(daemon,daemon->render_node);
	daemon_compute_render_nodes(daemon);
	*/
	
	// Catch SIGTERM
	struct sigaction sigterm_action;
	memset(&sigterm_action, 0, sizeof(struct sigaction));
	sigterm_action.sa_handler = got_sigterm_signal;
	sigaction(SIGTERM, &sigterm_action, NULL);
	
 	return(daemon);
}