Exemplo n.º 1
0
void record_cancel(){
	g15r_clearScreen(canvas,G15_COLOR_WHITE);
    g15r_renderString (canvas, (unsigned char *)"Recording", 0, G15_TEXT_LARGE, 80-((strlen("Recording")/2)*8), 4);
    g15r_renderString (canvas, (unsigned char *)"Canceled", 0, G15_TEXT_LARGE, 80-((strlen("Canceled")/2)*8), 18);
    g15_send(g15screen_fd,(char *)canvas->buffer,G15_BUFFER_LEN);
    record_cleanup();
}
Exemplo n.º 2
0
void renderHelp()
{
	// Draws the helpbox in the bottom right corner.
	g15r_drawLine(canvas, G15_LCD_WIDTH-37, 16, G15_LCD_WIDTH, 16, G15_COLOR_BLACK);
	g15r_drawLine(canvas, G15_LCD_WIDTH-37, 16, G15_LCD_WIDTH-37, G15_LCD_HEIGHT, G15_COLOR_BLACK);
	g15r_renderString (canvas, (unsigned char *)"1:Default\0", 3, G15_TEXT_SMALL, G15_LCD_WIDTH-35, 0);
	g15r_renderString (canvas, (unsigned char *)"2:     Up\0", 4, G15_TEXT_SMALL, G15_LCD_WIDTH-35, 0);
	g15r_renderString (canvas, (unsigned char *)"3:   Down\0", 5, G15_TEXT_SMALL, G15_LCD_WIDTH-35, 0);
	g15r_renderString (canvas, (unsigned char *)"4:     OK\0", 6, G15_TEXT_SMALL, G15_LCD_WIDTH-35, 0);
}
Exemplo n.º 3
0
void renderSelectionList()
{
	// Draws the three presets in the list (Selected-1,Selected,Selected+1)
	// Find config id to render
	pthread_mutex_lock(&gui_select);
	/*static*/ int tmpRenderConfID = 0;

	// Render first entry
	if (gui_selectConfig > 0)
		tmpRenderConfID = gui_selectConfig-1;
	else
		tmpRenderConfID = numConfigs;

	char* renderLine = stringTrim((char*)getConfigName(tmpRenderConfID),25);
	g15r_renderString(canvas, (unsigned char*)renderLine, 0, G15_TEXT_MED, 1, 17);
	free(renderLine);
	renderLine = NULL;


	// Render middle entry available for selection
	renderLine = stringTrim((char*)getConfigName(gui_selectConfig),25);

	g15r_renderString(canvas, (unsigned char*)renderLine, 0, G15_TEXT_MED, 1, 26);
	free(renderLine);
	renderLine = NULL;

	// Render third (last) entry
	if (gui_selectConfig < numConfigs)
		tmpRenderConfID = gui_selectConfig+1;
	else
		tmpRenderConfID = 0;
	pthread_mutex_unlock(&gui_select);

	renderLine = stringTrim((char*)getConfigName(tmpRenderConfID),25);
	g15r_renderString(canvas, (unsigned char*)renderLine, 0, G15_TEXT_MED, 1, 35);
	free(renderLine);
	renderLine = NULL;

	// Make middle look selected by inverting colours
	g15r_pixelReverseFill(canvas, 0, 24, 121, 33, 0,G15_COLOR_BLACK);

	g15_send(g15screen_fd,(char *)canvas->buffer,G15_BUFFER_LEN);
	pthread_mutex_lock(&gui_select);
	gui_oldConfig = gui_selectConfig;
	pthread_mutex_unlock(&gui_select);
}
Exemplo n.º 4
0
void record_complete(unsigned long keystate)
{
    char tmpstr[1024];
    int gkey = map_gkey(keystate);

    pthread_mutex_lock(&config_mutex);

    if(!rec_index) // nothing recorded - delete prior recording
        memset(mstates[mkey_state]->gkeys[gkey].keysequence.recorded_keypress,0,sizeof(keysequence_t));
    else
        memcpy(mstates[mkey_state]->gkeys[gkey].keysequence.recorded_keypress, &current_recording, sizeof(keysequence_t));

    mstates[mkey_state]->gkeys[gkey].keysequence.record_steps=rec_index;
    pthread_mutex_unlock(&config_mutex);

	g15r_clearScreen(canvas,G15_COLOR_WHITE);
    if(rec_index){
        strcpy(tmpstr,"For key ");
        strcat(tmpstr,gkeystring[map_gkey(keystate)]);
        g15macro_log("Recording Complete %s\n",tmpstr);
        g15r_renderString (canvas, (unsigned char *)"Recording", 0, G15_TEXT_LARGE, 80-((strlen("Recording")/2)*8), 4);
        g15r_renderString (canvas, (unsigned char *)"Complete", 0, G15_TEXT_LARGE, 80-((strlen("Complete")/2)*8), 18);

    }else{
        strcpy(tmpstr,"From Key ");
		printf("%lu\n",keystate);
        strcat(tmpstr,gkeystring[map_gkey(keystate)]);
        g15macro_log("Macro deleted %s\n",tmpstr);
        g15r_renderString (canvas, (unsigned char *)"Macro", 0, G15_TEXT_LARGE, 80-((strlen("Macro")/2)*8), 4);
        g15r_renderString (canvas, (unsigned char *)"Deleted", 0, G15_TEXT_LARGE, 80-((strlen("Deleted")/2)*8), 18);
    }
    g15r_renderString (canvas, (unsigned char *)tmpstr, 0, G15_TEXT_LARGE, 80-((strlen(tmpstr)/2)*8), 32);

    g15_send(g15screen_fd,(char *)canvas->buffer,G15_BUFFER_LEN);

    record_cleanup();
	g15_send_cmd (g15screen_fd,G15DAEMON_MKEYLEDS,mled_state);
    save_macros(configpath);
}
Exemplo n.º 5
0
void renderFull()
{
	char currPreset[1024];

	g15macro_log("Redrawing whole screen.\n");

	g15r_clearScreen(canvas,G15_COLOR_WHITE);
	drawXBM(canvas, (unsigned char*)g15macro_small_bits, g15macro_small_width, g15macro_small_height, 0, 0); // Logo
	renderHelp(); // Help box to the right
	// Draw indicator of currently selected preset
	memset(currPreset,0,sizeof(currPreset));
	snprintf(currPreset,1024,"Current:%s",getConfigName(currConfig));
	g15r_drawLine(canvas, 50, 2, 50, 11, G15_COLOR_BLACK); // Line separating logo from Current: <config>
	g15r_renderString (canvas, (unsigned char *)currPreset, 0, G15_TEXT_MED, 53, 4); // Current: <config>

	// Draw selection list
	renderSelectionList();
}
Exemplo n.º 6
0
/* take the track_info structure and render it */
void *g15display_thread(){
    long chksum=0;
    static long last_chksum;
    int i;
    unsigned char time_elapsed[41];
    unsigned char time_total[41];
    static int current = 0;
    int changed =0;
    while(!leaving){
        if(playlist_mode){

            int y=0;
            int offset=2;
            changed = 0;

            if(track_info.currentsong>-1){
                current=track_info.currentsong;
                track_info.currentsong = -1;
                changed = 1;
            }

            if(playlist_selection>0){
                if(current+1<mpd_playlist_get_playlist_length(obj)){
                    current+=playlist_selection;
                    changed = 1;
                }
                playlist_selection=0;
            }
            if(playlist_selection<0){
                if(current) {
                    current--;
                    changed = 1;
                }
                playlist_selection=0;
            }



            if(current-offset<0)
                offset-=current;

            if(changed){
                g15r_pixelBox (canvas, 0, 0, 159, 42, G15_COLOR_WHITE, 1, 1);
                for(i=current-offset;i<current+6;i++){
                    char title[100];
                    mpd_Song *song;

                    song = mpd_playlist_get_song_from_pos(obj, i);
                    if(song) {
                        if(song->title!=NULL)
                            strncpy(title,song->title,99);
                        else
                            strncpy(title,"",99);
                        if(song->artist!=NULL){
                            strncat(title," - ",99);
                            strncat(title,song->artist,99);
                        }
                    }
                    /* sanitise the display */
                    if(i==mpd_playlist_get_playlist_length(obj))
                        strncpy(title,"End of PlayList",99);
                    if(i>mpd_playlist_get_playlist_length(obj))
                        break;
                    if(i<0)
                        strncpy(title,"",99);

                    if(y==offset){
                        g15r_pixelBox (canvas, 0, 7*offset, 159 , 7*(offset+1), G15_COLOR_BLACK, 1, 1);
                        canvas->mode_xor=1;
                        if(song)
                            if(song->id)
                                item_selected=song->id;
                    }
                    g15r_renderString (canvas, (unsigned char *)title, y, G15_TEXT_MED, 1, 1);
                    canvas->mode_xor=0;
                    y++;
                }
            }
        }else{
            /* track info */
            g15r_pixelBox (canvas, 0, 0, 159, 42, G15_COLOR_WHITE, 1, 1);
            g15r_renderString (canvas, (unsigned char *)track_info.artist, 0, G15_TEXT_LARGE, 80-(strlen(track_info.artist)*8)/2, 2);
            g15r_renderString (canvas, (unsigned char *)track_info.title, 0, G15_TEXT_MED, 80-(strlen(track_info.title)*5)/2, 12);

            /* elapsed time */
            memset(time_elapsed,0,41);
            memset(time_total,0,41);
            if (track_info.total != 0) {
                snprintf((char*)time_elapsed,40,"%02i:%02i",track_info.elapsed/60, track_info.elapsed%60);
                snprintf((char*)time_total,40,"%02i:%02i",track_info.total/60, track_info.total%60);
            }
            if(track_info.elapsed>0&&track_info.total>0)
                g15r_drawBar (canvas, 10, 22, 149, 30, G15_COLOR_BLACK, track_info.elapsed, track_info.total, 1);
            canvas->mode_xor=1;
            g15r_renderString (canvas,(unsigned char*)time_elapsed,0,G15_TEXT_MED,12,23);
            g15r_renderString (canvas,(unsigned char*)time_total,0,G15_TEXT_MED,124,23);
            canvas->mode_xor=0;

            switch(track_info.playstate)
            {
                case MPD_PLAYER_PLAY:
                    playing=1;
                    paused=0;
                    break;
                case MPD_PLAYER_PAUSE:
                    g15r_pixelBox (canvas, 10, 22, 149, 30, G15_COLOR_WHITE, 1, 1);
                    g15r_renderString (canvas, (unsigned char *)"Playback Paused", 0, G15_TEXT_LARGE, 22, 23);
                    paused=1;
                    break;
                case MPD_PLAYER_STOP:
                    g15r_pixelBox (canvas, 10, 22, 149, 30, G15_COLOR_WHITE, 1, 1);
                    g15r_renderString (canvas, (unsigned char *)"Playback Stopped", 0, G15_TEXT_LARGE, 18, 23);
                    playing=0;
                    paused=0;
                    break;
                default:
                    break;
            }

            g15r_pixelBox (canvas, 1, 34, 158 , 41, G15_COLOR_WHITE, 1, 1);
            g15r_pixelBox (canvas, 10, 34, 27, 42, G15_COLOR_BLACK, 1, 1);
            canvas->mode_xor=1;
            g15r_renderString (canvas, (unsigned char *)"mode", 0, G15_TEXT_SMALL, 11, 36);
            canvas->mode_xor=0;

            if(menulevel==MENU_MODE1){
                if(track_info.random){
                    g15r_drawLine (canvas, 43, 42, 158, 42,G15_COLOR_WHITE);
                    canvas->mode_xor=1;
                    g15r_pixelBox (canvas, 104, 34, 125 , 42, G15_COLOR_BLACK, 1, 1);
                }else{
                    g15r_pixelBox (canvas, 104, 34, 125 , 42, G15_COLOR_BLACK, 1, 0);
                }
                g15r_renderString (canvas, (unsigned char *)"Rndm", 0, G15_TEXT_SMALL, 108, 36);
                canvas->mode_xor=0;

                if(track_info.repeat){
                    canvas->mode_xor=1;
                    g15r_pixelBox (canvas, 130, 34, 149 , 42, G15_COLOR_BLACK, 1, 1);
                }else {
                    g15r_pixelBox (canvas, 130, 34, 149 , 42, G15_COLOR_BLACK, 1, 0);
                }

                g15r_renderString (canvas, (unsigned char *)"Rpt", 0, G15_TEXT_SMALL, 136, 36);
                canvas->mode_xor=0;

                        // 2nd box from left - if you want it...
                if(playlist_mode==0){
                    g15r_pixelBox (canvas, 34, 34, 70 , 42, G15_COLOR_BLACK, 1, 0);
                    g15r_renderString (canvas, (unsigned char *)"Playlist", 0, G15_TEXT_SMALL, 36, 36);
                }else{
                    canvas->mode_xor=1;
                    g15r_pixelBox (canvas, 34, 34, 70 , 42, G15_COLOR_BLACK, 1, 1);
                    g15r_renderString (canvas, (unsigned char *)"Playlist", 0, G15_TEXT_SMALL, 36, 36);    
                    canvas->mode_xor=0;
                }
            }

            if(menulevel==MENU_MODE2){
                g15r_pixelBox (canvas, 104, 34, 125 , 42, G15_COLOR_BLACK, 1, 0);
                g15r_renderString (canvas, (unsigned char *)"Vol-", 0, G15_TEXT_SMALL, 108, 36);

                g15r_pixelBox (canvas, 130, 34, 149 , 42, G15_COLOR_BLACK, 1, 0);
                g15r_renderString (canvas, (unsigned char *)"Vol+", 0, G15_TEXT_SMALL, 132, 36);

                // 2nd box from left - if you want it...
                //g15r_pixelBox (canvas, 34, 34, 54 , 42, G15_COLOR_BLACK, 1, 0);
                //g15r_renderString (canvas, (unsigned char *)"test", 0, G15_TEXT_SMALL, 36, 36);
            }

            if(muted_volume != 0){
                g15r_renderString (canvas, (unsigned char *)"MUTE", 0, G15_TEXT_LARGE, 11, 2);
            }
            else if(voltimeout){
                g15r_drawBar (canvas,10, 22, 149, 30, G15_COLOR_BLACK, track_info.volume, 100, 1);
                canvas->mode_xor=1;
                g15r_renderString (canvas, (unsigned char *)"Volume", 0, G15_TEXT_LARGE, 59, 23);
                canvas->mode_xor=0;
            }
        }

        /* do a quicky checksum - only send frame if different */
        chksum=0;
        for(i=0;i<G15_BUFFER_LEN;i++){
            chksum+=canvas->buffer[i]*i;
        }
        pthread_mutex_lock(&daemon_mutex);
        if(last_chksum!=chksum) {
            while(g15_send(g15screen_fd,(char *)canvas->buffer,G15_BUFFER_LEN)<0 && !leaving) {
                perror("lost connection, tryng again\n");
                usleep(10000);
                /* connection error occurred - try to reconnect to the daemon */
                g15screen_fd=new_g15_screen(G15_G15RBUF);
            }
        }
        pthread_mutex_unlock(&daemon_mutex);
        last_chksum=chksum;
        usleep(75*1000);
        if(playlist_mode)
            usleep(75*1000);

    }
    return NULL;
}
Exemplo n.º 7
0
void xkey_handler(XEvent *event) {
	static unsigned long lasttime;
	unsigned char keytext[256];
	unsigned int keycode = event->xkey.keycode;
	int press = True;

	if(event->type==KeyRelease){ // we only do keyreleases for some keys
	pthread_mutex_lock(&x11mutex);
		KeySym key = XKeycodeToKeysym(dpy, keycode, 0);
	pthread_mutex_unlock(&x11mutex);
		switch (key) {
			case XK_Shift_L:
			case XK_Shift_R:
			case XK_Control_L:
			case XK_Control_R:
			case XK_Caps_Lock:
			case XK_Shift_Lock:
			case XK_Meta_L:
			case XK_Meta_R:
			case XK_Alt_L:
			case XK_Alt_R:
			case XK_Super_L:
			case XK_Super_R:
			case XK_Hyper_L:
			case XK_Hyper_R:
			default:
				press = False;
		}
	}
	if(recording){
		current_recording.recorded_keypress[rec_index].keycode = keycode;
		current_recording.recorded_keypress[rec_index].pressed = press;
		current_recording.recorded_keypress[rec_index].modifiers = event->xkey.state;
		if(rec_index==0)
			current_recording.recorded_keypress[rec_index].time_ms=0;
		else
			current_recording.recorded_keypress[rec_index].time_ms=g15daemon_gettime_ms() - lasttime;
		if(rec_index < MAX_KEYSTEPS)
		{
			rec_index++;
			/* now the default stuff */
			pthread_mutex_lock(&x11mutex);
			XUngrabKeyboard(dpy,CurrentTime);
			pthread_mutex_unlock(&x11mutex);

			fake_keyevent(keycode,press,event->xkey.state);

			pthread_mutex_lock(&x11mutex);
			XGrabKeyboard(dpy, root_win, True, GrabModeAsync, GrabModeAsync, CurrentTime);
			XFlush(dpy);
			strcpy((char*)keytext,XKeysymToString(XKeycodeToKeysym(dpy, keycode, 0)));
			pthread_mutex_unlock(&x11mutex);
			if(0==strcmp((char*)keytext,"space"))
				strcpy((char*)keytext," ");
			if(0==strcmp((char*)keytext,"period"))
				strcpy((char*)keytext,".");
			if(press==True){
			strcat((char*)recstring,(char*)keytext);
			g15macro_log("Adding %s to Macro\n",keytext);
			g15r_renderString (canvas, (unsigned char *)recstring, 0, G15_TEXT_MED, 80-((strlen((char*)recstring)/2)*5), 22);
			g15_send(g15screen_fd,(char *)canvas->buffer,G15_BUFFER_LEN);
			}
		}
		else
		{
			pthread_mutex_lock(&x11mutex);
			XUngrabKeyboard(dpy,CurrentTime);
			pthread_mutex_unlock(&x11mutex);
			recording = 0;
			rec_index = 0;
			printf("Saving macro\n");
			save_macros(configpath);
		}

    }
	else
		rec_index=0;

	lasttime = g15daemon_gettime_ms();
}
Exemplo n.º 8
0
void *Lkeys_thread() {
    unsigned long keystate = 0;
    struct pollfd fds;
    char ver[5];
    int foo = 0;
    float g15v;

	memset(ver,0x0,sizeof(ver));
	strncpy(ver,G15DAEMON_VERSION,3);
    sscanf(ver,"%f",&g15v);

    g15macro_log("Using version %.2f as keypress protocol\n",g15v);

    while(!leaving){

        /* g15daemon series 1.2 need key request packets */
        if((g15v*10)<=18) {
            keystate = g15_send_cmd (g15screen_fd, G15DAEMON_GET_KEYSTATE, foo);
        } else {
            fds.fd = g15screen_fd;
            fds.events = POLLIN;
            fds.revents=0;
            keystate=0;
            if ((poll(&fds, 1, 1000)) > 0) {
                read (g15screen_fd, &keystate, sizeof (keystate));
            }
        }

        if (keystate!=0)
        {
            g15macro_log("Received Keystate == %lu\n",keystate);

            switch (keystate)
            {
				case G15_KEY_L2:
				{
					int fg_check = g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, foo);
					if(!fg_check)
						break;

					// Go to default/g15macro.conf = id =0
					gui_selectChange(0);
					break;
				}
				case G15_KEY_L3:
				{
					int fg_check = g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, foo);
					if(!fg_check)
						break;

					// Scroll up
					gui_selectChange(-1);
					break;
				}
				case G15_KEY_L4:
				{
					int fg_check = g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, foo);
					if(!fg_check)
						break;

					// Scroll down
					gui_selectChange(+1);
					break;
				}
				case G15_KEY_L5:
				{
					int fg_check = g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, foo);
					if(!fg_check)
						break;

					// Change to selected

					char newConfig[1024];
					memset(newConfig,0,sizeof(newConfig));
					strcpy(newConfig,configDir);
					strncat(newConfig,configs[currConfig]->configfile,sizeof(newConfig)-strlen(newConfig));
					// Actually not the newConfig, it's the old, but didn't come up with a good name.
					save_macros(newConfig);

					// Purge all old data
					cleanMstates(1);

					// Now load the new config
					currConfig = gui_selectConfig;
					memset(newConfig,0,sizeof(newConfig));
					strcpy(newConfig,configDir);
					strncat(newConfig,configs[currConfig]->configfile,sizeof(newConfig)-strlen(newConfig));

					restore_config(newConfig);


					// Set the configpath to reflect the change
					memset(configpath,0,sizeof(configpath));
					strcpy(configpath,configDir);
					strncat(configpath,configs[currConfig]->configfile,sizeof(configpath)-strlen(configpath));
					gui_oldConfig = MAX_CONFIGS+1;

					break;
				}
                case G15_KEY_MR: {
					g15macro_log("Key pressed is MR\n");
                    if(!recording) {
                      if(0==g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, foo)){
                        usleep(1000);
                        g15_send_cmd (g15screen_fd, G15DAEMON_SWITCH_PRIORITIES, foo);
                        g15macro_log("Switching to LCD foreground\n");
                      }
                      usleep(1000);
                      g15_send_cmd (g15screen_fd,G15DAEMON_MKEYLEDS, G15_LED_MR | mled_state);
                      g15r_initCanvas (canvas);
                      g15r_renderString (canvas, (unsigned char *)"Recording", 0, G15_TEXT_LARGE, 80-((strlen("Recording")/2)*8), 1);
                      g15_send(g15screen_fd,(char *)canvas->buffer,G15_BUFFER_LEN);
                      g15macro_log("Recording Enabled\n");
                      recording = 1;
                      pthread_mutex_lock(&x11mutex);
                      XGrabKeyboard(dpy, root_win, True, GrabModeAsync, GrabModeAsync, CurrentTime);
                      pthread_mutex_unlock(&x11mutex);
                      memset(&current_recording,0,sizeof(current_recording));
                    } else {
                      record_cancel();
					  g15_send_cmd (g15screen_fd,G15DAEMON_MKEYLEDS,mled_state);
                    }
                    break;
                  }
                case G15_KEY_M1:
                    handle_mkey_switch(G15_KEY_M1);
					g15macro_log("Key pressed is M1\n");
                    break;
                case G15_KEY_M2:
                    handle_mkey_switch(G15_KEY_M2);
					g15macro_log("Key pressed is M2\n");
                    break;
                case G15_KEY_M3:
                    handle_mkey_switch(G15_KEY_M3);
					g15macro_log("Key pressed is M3\n");
                    break;
                default:
                    if(keystate >=G15_KEY_G1 && keystate <=G15_KEY_G18){
                        if(recording==1){
                            record_complete(keystate);
                        } else {
                            macro_playback(keystate);
                        }
                    }
                    break;
            }
            keystate = 0;
        }
    }
    return NULL;
}