Пример #1
0
void read_input (void)
{

    while (SDL_PollEvent (&event))
    {
        if (event.type == SDL_TEXTINPUT && score_entry)
        {
            if ( event.text.text[0] >= '0' && event.text.text[0] <= '9')
            {
                if (strlen (score_str) < 10)
                    sprintf (score_str, "%s%s", score_str, event.text.text);
            }
        }

        if (event.type == SDL_KEYDOWN)
        {
            switch (event.key.keysym.sym)
            {
                case SDLK_ESCAPE:
                    fprintf (stderr, "Quit\n");
                    running = 0;
                    break;
                case SDLK_RIGHTBRACKET:
                    volume_up ();
                    break;
                case SDLK_LEFTBRACKET:
                    volume_down ();
                    break;
                case SDLK_UP:
                    cmd_index_inc ();
                    break;
                case SDLK_DOWN:
                    cmd_index_dec ();
                    break;
                case SDLK_LEFT:
                    cmd_mode = MODE_CMD;
                    break;
                case SDLK_RIGHT:
                    if (udp_cmds[cmd_index].data_size > 0 && score_entry != 1)
                        cmd_mode = MODE_VALUE;
                    break;
                case SDLK_RETURN:
                    send_cmd ();
                    break;
                case SDLK_BACKSPACE:
                    if (score_entry)
                        remove_score_digit ();
                    break;
            }
        }
        if (event.type == SDL_QUIT)
        {
            running = 0;
        }
    }
}
void pb_interrupt_handler(uint32_t state) {
	if (state & BTN_LEFT_MASK) {
		play_track(SOUND_TANK_SHOT);
	} else if (state & BTN_CENTER_MASK) {
		play_track(SOUND_ALIEN_MOVE2);
	} else if (state & BTN_RIGHT_MASK) {
		play_track(SOUND_ALIEN_MOVE3);
	} else if (state & BTN_DOWN_MASK) {
		volume_down();
	} else if (state & BTN_UP_MASK) {
		volume_up();
	}
}
Пример #3
0
void sculpture_release(int min, int max)  {
  printf("\n\n***7x7 sculpture release***\n\n");
  for (;;)  {
    int x = analogRead(ultrasound_pin); 
//    button(min, max);
    if (x<100)  {
      release_track();
      volume_up(min, max);
      sculpture_play(min, max);
    }
    printf("ultrasound = %d\n",x);
    delay(50);
  }

}
Пример #4
0
/* Runs forwever waiting for input from mixer queue */
void mixer_msg_loop(void) 
{
    DBG_PRINTF("mixer: processing loop started\n");
    for (;;) {
        msg_t *msg = getq(&mixerq);

        DBG_PRINTF("mixer: msg id %d\n", msg->type);

        switch (msg->type) {
        case MSG_REMOTE_VOLUMEUP:
            volume_up();
            break;

        case MSG_REMOTE_VOLUMEDOWN:
            volume_down();
            break;
        }
        free(msg);
    }
}
Пример #5
0
int mute()
{
    int value;
   
    get_volume(&value);
   
    if (value) {
       oldvalue=value;
       value=0;
       set_volume(&value);
    }
    else {
       if (!oldvalue) {
      volume_up();       
       }
       else {
          set_volume(&oldvalue);
       }
    }

    return 0;
}
Пример #6
0
void run()
{
	WSADATA wsa;
	if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
	{
		printf("Init failed");
		exit(-1);
	}

	SOCKET server_fd;

	server_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

	if (server_fd == INVALID_SOCKET)
	{
		printf("Invalid socket");
		exit(-1);
	}

	struct sockaddr_in server_addr;
	int port = 56789;
	memset(&server_addr, 0, sizeof(struct sockaddr_in));
	server_addr.sin_family = AF_INET;
	server_addr.sin_addr.s_addr = INADDR_ANY;
	server_addr.sin_port = htons(port);

	if (bind(server_fd, (struct sockaddr*)&server_addr, sizeof(server_addr)) == SOCKET_ERROR)
	{
		printf("Socket bind error");
		exit(-1);
	}

	if (listen(server_fd, SOMAXCONN) == SOCKET_ERROR)
	{
		printf("Socket execute error");
		exit(-1);
	}

	char hostname[255];
	char *ip;
	char *local = "*";
	struct hostent *hostinfo;
	if (gethostname(hostname, sizeof(hostname)) == 0)
	{
		if ((hostinfo = gethostbyname(hostname)) != NULL)
		{
			ip = inet_ntoa(*(struct in_addr *)*hostinfo->h_addr_list);
		}
		else
		{			
			ip = local;
		}
	}
	else
	{
		ip = local;
	}

	printf("Server is listening on %s:%d\n", ip, port);
	char doccmd[BUF_SIZE];
	sprintf_s(doccmd, BUF_SIZE, "start http://%s:%d/", ip, port);
	//system(doccmd);

	while (true)
	{
		SOCKET client;
		struct sockaddr_in client_addr;
		memset(&client_addr, 0, sizeof(struct sockaddr_in));
		client = accept(server_fd, (struct sockaddr*)&client_addr, 0);
		if (client == INVALID_SOCKET)
		{
			printf("Invalid socket");
		}

		char request[BUF_SIZE];
		char htmlfile[255];

		int receive_rs = recv(client, request, sizeof(request), 0);
		struct req_head head = parse_request_head(request);
		printf("Request: %s\n", head.path);

		if (strcmp(head.path, "/next") == 0)
		{
			play_next();
			strcpy_s(htmlfile, "html/index.html");
		}
		else if (strcmp(head.path, "/prev") == 0)
		{
			play_prev();
			strcpy_s(htmlfile, "html/index.html");
		}
		else if (strcmp(head.path, "/play") == 0)
		{
			play();
			strcpy_s(htmlfile, "html/index.html");
		}
		else if (strcmp(head.path, "/up") == 0)
		{
			volume_up();
			strcpy_s(htmlfile, "html/index.html");
		}
		else if (strcmp(head.path, "/down") == 0)
		{
			volume_down();
			strcpy_s(htmlfile, "html/index.html");
		}
		else if (strcmp(head.path, "/mute") == 0)
		{
			mute();
			strcpy_s(htmlfile, "html/index.html");
		}
		else if (strcmp(head.path, "/shutdown") == 0)
		{
			poweroff();
			strcpy_s(htmlfile, "html/index.html");
		}
		else if (strcmp(head.path, "/") == 0)
		{
			strcpy_s(htmlfile, "html/index.html");
		}	
		else
		{
			strcpyn(htmlfile, head.path, 1, sizeof(head) - 1);
		}

		// 加载要显示的页面
		struct fbuf *html = load_file(htmlfile);
		//printf("Loading file: %s\n", htmlfile);

		char *content;
		if (html == NULL)
		{
			content = (char *)calloc(BUF_SIZE, sizeof(char));
			sprintf_s(content, BUF_SIZE, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: %d\r\n\r\n%s", 22, "<h1>404 NOT FOUND</h1>");
			send(client, content, strlen(content), 0);
		}
		else
		{
			size_t total_size = html->buf_size + 67;
			content = (char *)calloc(total_size, sizeof(char));
			sprintf_s(content, total_size, "HTTP/1.1 200 OK\r\nContent-Type: %s\r\nContent-Length: %d\r\n\r\n", html->mime, html->buf_size * sizeof(char));
			// send head
			send(client, content, strlen(content), 0);

			// send body
			send(client, html->buf, html->buf_size, 0);
		}
		
		free(content);
		free(html);

		closesocket(client);
	}

	closesocket(server_fd);
}
Пример #7
0
Файл: cmod.c Проект: imclab/cmod
int main(int argc, char *argv[])
{
  char *buff;
  int ch;
  int i;

  initscr();
  cbreak();
  noecho();
  nonl();
  curs_set(0);
  // nodelay(stdscr, TRUE);
  intrflush(stdscr, FALSE);
  keypad(stdscr, TRUE);

  if((color = has_colors())) {
    start_color();
    init_pair(1, COLOR_WHITE, COLOR_BLUE);
    init_pair(2, COLOR_CYAN, COLOR_BLUE);
  }

  signal(SIGINT, cleanup);

  init_windows();
  init_bass();

  create_playlist(&playlist_h, &playlist_t);

  if(argc>1) {
    if(strncmp("/", argv[1], 1) != 0) {
      error("argument must be an absolute path", FALSE);
    }
    if(dirname(opendir(argv[1]))) { // is a dir
      if(add(&playlist_h, argv[1], &playlist_t)) {
        p_p++;
        c_p_p++;
        nsongs++;
        active_win = PLAYLIST_WIN;
        bass_loop = BASS_MUSIC_LOOP;
        play(argv[1], PLAYING_PLAYLIST);
      }
      current_path = strdup((char*)dirname(argv[1]));
    } else {
      error("argument not valid", FALSE);
    }
  } else {
    current_path = (char*)malloc(sizeof(char)*PATH_MAX);
    current_path = (char*)getcwd(current_path, PATH_MAX);
  }

  entries = refresh_browser(current_path, 0);

  mvprintw(0, 0, "%s", current_path);

  repaint_windows();

  while((ch = getch()) != 'q') {
    switch(ch) {
      case 'a': // add song to playlist
          if(active_win == BROWSER_WIN) {
            if(!is_dir(current_path, entries[p_b])) {
              buff = mystrcat(current_path,entries[p_b],1);
              if(add(&playlist_h, buff, &playlist_t)) {
                if(p_p == -1) p_p++;
                nsongs++;
                repaint_windows();
              }
              free(buff);
            }
          }
        break;
      case 'e': // add all songs in current dir
          if(active_win == BROWSER_WIN) {
            for(i=0; i<nfiles; i++) {
              if(!is_dir(current_path, entries[i])) {
                buff = mystrcat(current_path,entries[i],1);
                if(add(&playlist_h, buff, &playlist_t)) {
                  if(p_p == -1) p_p++;
                  nsongs++;
                }
                free(buff);
              }
            }
          }
          repaint_windows();
        break;
      case 'c': // recursive add
          if(active_win == BROWSER_WIN) {
            //printw("---%s+++", current_path);
            add_recursive(current_path, entries, nfiles);
            repaint_windows();
            //printw("---%s", current_path);
          }
        break;
      case 'd': // remove one song from playlist
          if(active_win == PLAYLIST_WIN) {
            if(del(&playlist_h, p_p, &playlist_t)) {
              nsongs--;
              if(p_p > nsongs - 1) {
                p_p = nsongs - 1;
              }
              if(p_p < c_p_p) {
                c_p_p--;
              }
              //stop();
              repaint_windows();
            }
          }
        break;
      case 'r': // remove all songs from playlist
          if(del_all(&playlist_h, &playlist_t)) {
            p_p = -1;
            c_p_p = -1;
            nsongs = 0;
            repaint_windows();
          }
        break;
      case ' ': // start playback or browse filesystem
      case 13: //enter key
          if(active_win == BROWSER_WIN) {
            if(strcmp(entries[p_b], "..\0") == 0) {
              current_path = dirname(current_path);
              p_b = 0;
              entries = refresh_browser(current_path, 0);
            } else {
              if(is_dir(current_path, entries[p_b])) {
                current_path = dir_up(current_path, entries[p_b]);
                p_b = 0;
                entries = refresh_browser(current_path, 0);
              } else {
                buff = mystrcat(current_path,entries[p_b],1);
                play(buff, PLAYING_BROWSER);
                free(buff);
                c_p_p = -1;
                if(p_b < nfiles-1) {
                  p_b++;
                }
              }
            }
            refresh_path();
          } else { // PLAYLIST_WIN
            if(nsongs != 0) {
              play(get(&playlist_h, p_p, &playlist_t)->file, PLAYING_PLAYLIST);
              c_p_p = p_p;
              if(p_p < nsongs - 1) {
                p_p++;
              }
            }
          }
          repaint_windows();
        break;

      case 's': // stop playback
          stop();
          c_p_p = -1;
          repaint_windows();
          clear_statusbar(NULL);
        break;

      case 'n': // next song
          next();
        break;

      case 'p': // prev song
          prev();
        break;

      case 'g': // go to current song
          p_p = c_p_p;
          repaint_windows();
        break;

      case 'l': // toggle loop
          loop();
          stop();
          c_p_p = -1;
          repaint_windows();
        break;

      case 'z': // toggle random
          random_mode();
        break;

      case '.': // seek forward
          seek(1);
        break;

      case ',': // seek backward
          seek(-1);
        break;

      case '+':
          volume_up();
        break;

      case '-':
          volume_down();
        break;

      case '>':
          amplify_up();
        break;

      case '<':
          amplify_down();
        break;

      case KEY_UP:
        if(active_win == BROWSER_WIN) {
          if(p_b > 0) {
            p_b--;
          }
        } else {
          if(p_p > 0) {
            p_p--;
          }
        }
        repaint_windows();
        break;

      case KEY_DOWN:
        if(active_win == BROWSER_WIN) {
          if(p_b < nfiles-1) {
            p_b++;
          }
        } else {
          if(p_p < nsongs - 1) {
            p_p++;
          }
        }
        repaint_windows();
        break;

      case KEY_LEFT:
      case KEY_RIGHT:
          switch_activewindow();
          repaint_windows();
        break;

      case KEY_HOME:
          if(active_win == BROWSER_WIN) {
            p_b = 0;
          } else {
            if(p_p != -1) p_p = 0;
          }
          repaint_windows();
        break;

      case KEY_END:
          if(active_win == BROWSER_WIN) {
            p_b = nfiles-1;
          } else {
            if(p_p != -1) p_p = nsongs - 1;
          }
          repaint_windows();
        break;

      case KEY_NPAGE:
        if(active_win == BROWSER_WIN) {
          if((p_b + (browser_win->_maxy - 2)) < nfiles-1 ) {
            p_b += browser_win->_maxy - 1;
          } else {
            p_b = nfiles-1;
          }
        } else {
          if((p_p + (playlist_win->_maxy - 2)) < nsongs) {
            p_p += playlist_win->_maxy - 1;
          } else {
            p_p = nsongs - 1;
          }
        }
        repaint_windows();
        break;

      case KEY_PPAGE:
        if(active_win == BROWSER_WIN) {
          if((p_b - (browser_win->_maxy - 2)) > 0) {
            p_b -= browser_win->_maxy - 1;
          } else {
            p_b = 0;
          }
        } else {
          if((p_p - (playlist_win->_maxy - 2)) > 0) {
            p_p -= playlist_win->_maxy - 1;
          } else {
            if(p_p != -1) p_p = 0;
          }
        }
        repaint_windows();
        break;
    }

    //usleep(10);

    //update_status();

  }

  cleanup();

  return 0;

}
Пример #8
0
void
loop ()
{
  // event interface
  int fd = -1;			/* the file descriptor for the device */
  int i;			/* loop counter */
  size_t read_bytes;		/* how many bytes were read */
  struct input_event ev[64];	/* the events (up to 64 at once) */
  int key;			/*key code */
  /* used if event hit fn */
  int hasSomething;

#ifdef HAVE_LIBXOSD
  // prepare queue handling
  int flag = 0, brightness = 0, sound = 0;
  createqueue ();
#endif
  
  if (strcasecmp(devinput,"AUTO")==0) { // try to figure out rigth event value for keyboard
	  snprintf(devinput,MAX_DEVINPUT_SIZE,"/dev/input/event%d",getItemEvent(DEFAULT_KEYBOARD_NAME));
	  syslog(LOG_INFO,"autodevice determines %s as keyboard event",devinput);
  }
  
  if ((fd = open (devinput, O_RDONLY)) < 0)
    {
      syslog (LOG_CRIT,"event interface (%s) open failed: %m",devinput);
      // shoot auto as LAST chance
      snprintf(devinput,MAX_DEVINPUT_SIZE,"/dev/input/event%d",getItemEvent(DEFAULT_KEYBOARD_NAME));
      syslog(LOG_CRIT,"autodevice determines %s as a last chance keyboard event",devinput);
      if ((fd = open (devinput, O_RDONLY)) < 0)
        {
	      syslog(LOG_CRIT,"Event interface (%s) open failed: %m",devinput);
              cleanExit(EXIT_FAILURE);
	}
    }

  /* handle important signal */
  if (signal(SIGTERM,signal_handler) < 0)
    {
      perror("signal");
      exit(EXIT_FAILURE);
    }
  if (signal(SIGHUP,signal_handler) < 0)
    {
      perror("signal");
      exit(EXIT_FAILURE);
    }

  syslog(LOG_INFO,"fsfn loaded");


  while (1)
    {				/* loop */
      hasSomething = 0;		/* nothing yet */

      /*
       * read the event interface 
       */
      if ( (read_bytes = read (fd, ev, sizeof (struct input_event) * 64))==-1) {
	      //fprintf(stderr,"Error: %d\n",errno);
	      if (errno==ENODEV) { // event is now invalid ? must be back from sleep...
		      syslog(LOG_NOTICE,"Start sleeping...");
		      sleep(10);		      
		      syslog(LOG_NOTICE,"End sleeping...");

		      close(fd); // is this needed ??
		      
		      syslog(LOG_NOTICE,"Input device changed, back from suspend ?: %m");
		      
		      // get new event
		      snprintf(devinput,MAX_DEVINPUT_SIZE,"/dev/input/event%d",getItemEvent(DEFAULT_KEYBOARD_NAME));
      		      syslog(LOG_NOTICE,"autodevice determines %s as new event",devinput);
		      
		      // reopen - seems to be problems after a hibernate :(
      		      if ((fd = open (devinput, O_RDONLY)) < 0)
        	        {
				syslog(LOG_CRIT,"New event interface (%s) open failed: %m",devinput); 
				cleanExit(EXIT_FAILURE);
			}
		      // read it
		      if ((read_bytes = read (fd, ev, sizeof (struct input_event) * 64))==-1) 
		        {
				syslog(LOG_CRIT,"Reading new device (%s) failed: %m",devinput);
				cleanExit(EXIT_FAILURE);
		        }
	      }
	      else {
		      syslog(LOG_CRIT,"Input device reading failed: %m");
		      cleanExit(EXIT_FAILURE);
	      }
	}
      	
      if (read_bytes < (int) sizeof (struct input_event))
	{
	  syslog (LOG_CRIT,"short read: %m");
	  cleanExit(EXIT_FAILURE);
	}
      
      /*
       * Loop for all readed events until we have something
       * interesting.. 
       */
      for (i = 0;
	   !hasSomething
	   && (i < (int) (read_bytes / sizeof (struct input_event))); i++)
	{
	  hasSomething = (ev[i].type == FN_INPUT_TYPE)
	    && (ev[i].code == FN_INPUT_CODE)
	    && (ev[i].value == FN_INPUT_VALUE);
	}
      
      /*
       * If we got a FN event, plz do something... 
       */
      if (hasSomething && (key = getCodes ()))
	{
	  if ((key & FN_F5) == FN_F5)
	    { 
	      	// check config
	      	if (!checkConfig("F5_CMD"))
		  {
	      		// lower brightness
#ifdef HAVE_LIBXOSD
	      		flag = MOD_BRIGHTNESS;
	      		brightness = setBrightness (getBrightness () - 1);
	      		sendmsg (flag, brightness, sound);
			sendcmd (FN_F5);
#else
	      		setBrightness (getBrightness () - 1);
#endif
		  }
	    }
	  if ((key & FN_F6) == FN_F6)
	    {
	    	// check config
		if (!checkConfig("F6_CMD")) 
		  {
		  	
	    		// higher brightness
#ifdef HAVE_LIBXOSD
	      		flag = MOD_BRIGHTNESS;
	      		brightness = setBrightness (getBrightness () + 1);
	      		sendmsg (flag, brightness, sound);
			sendcmd (FN_F6);
#else
	      		setBrightness (getBrightness () + 1);
#endif
		  }
	    }

	  if ((key & FN_F2) == FN_F2)
	    {
		// check config
		if (!checkConfig("F2_CMD"))
		  {
#ifdef HAVE_LIBXOSD
	      		flag = MOD_SOUND;
	      		sound = mute (SOUND_STEP);
	      		sendmsg (flag, brightness, sound);
			sendcmd(FN_F2);
#else
	      		mute (SOUND_STEP);			
#endif
		  }
	    }
	  if ((key & FN_F3) == FN_F3)
	    {
		if (!checkConfig("F3_CMD"))
	          {
#ifdef HAVE_LIBXOSD
	      		flag = MOD_SOUND;
	      		sound = volume_down (SOUND_STEP);	//mod by SilSha
	      		sendmsg (flag, brightness, sound);
			sendcmd(FN_F3);
#else
	      		volume_down (SOUND_STEP);
#endif
		  }
	    }
	  if ((key & FN_F4) == FN_F4)
	    {
	       if (!checkConfig("F4_CMD"))
	         {
#ifdef HAVE_LIBXOSD
	      		flag = MOD_SOUND;
	      		sound = volume_up (SOUND_STEP);		//mod by SilSha
	      		sendmsg (flag, brightness, sound);
			sendcmd(FN_F4);
#else
	      		volume_up (SOUND_STEP);
#endif
		 }	
	    }
	 /* NO built in commands */
	  if ((key & FN_F7) == FN_F7)
	    {
#ifdef HAVE_LIBXOSD
	      if (!checkConfig("F7_CMD"))
		sendcmd(FN_F7);
#else
	      sendcmd(FN_F7);
#endif
	    }
	  if ((key & FN_F10) == FN_F10)
	    {
#ifdef HAVE_LIBXOSD
	      if(!checkConfig("F10_CMD"))
		sendcmd(FN_F10);
#else
	      sendcmd(FN_F10);
#endif
	    }
	  if ((key & FN_F12) == FN_F12)
	    {
#ifdef HAVE_LIBXOSD
	      if (!checkConfig("F12_CMD"))
		sendcmd(FN_F12);
#else
	      checkConfig("F12_CMD");
#endif
	    }
	  if (( key & S1_BTN) == S1_BTN) 
	    {
#ifdef HAVE_LIBXOSD
	      if (!checkConfig("S1_CMD"))
		sendcmd(S1_BTN);
#else
	      checkConfig("S1_CMD");
#endif
	    }
	  if (( key & S2_BTN) == S2_BTN)
	    {
#ifdef HAVE_LIBXOSD
	      if (!checkConfig("S2_CMD"))
		sendcmd(S2_BTN);
#else
	      checkConfig("S2_CMD");
#endif
	    }		  
	}
    }// while
}
Пример #9
0
// main and loop
int main(int argc, char **argv) {
    // event interface
    int fd = -1;                /* the file descriptor for the device */
    int i;                      /* loop counter */
    size_t read_bytes;          /* how many bytes were read */
    struct input_event ev[64];  /* the events (up to 64 at once) */
      
    /* key code */
    int key;

    /* used if event hit fn */
    int hasSomething;
    
    /* Volume */
    int value = 0;

    fileops(0, 0);

    /* open event interface*/
    if (argc != 2) {
        /* i don't like outputs...
        fprintf(stderr, "Using /dev/input/event1 for input\n");
        fprintf(stderr, "Overide with %s event-device\n", argv[0]);
        */
        if ((fd = open("/dev/input/event1", O_RDONLY)) < 0) {
            perror("event interface open failed");
            exit(1);
        }
    } else {   
        if ((fd = open(argv[1], O_RDONLY)) < 0) {
            perror("event interface open failed");
            exit(1);
        }
    }

    nice(10); // be a nice dirty code (less dirty but keep nice)

    while(1) {          /* loop */
        hasSomething=0; /* nothing yet */
      
        /* read the event interface */
        read_bytes = read(fd, ev, sizeof(struct input_event) * 64);
      
        if (read_bytes < (int) sizeof(struct input_event)) {
            perror("sonyfn: short read");
            exit (1);
        }

        /* Loop for all readed events until we have something interesting.. */
        for (i = 0;! hasSomething && ( i < (int) (read_bytes /
                                sizeof(struct input_event)) ); i++) {
            hasSomething= (ev[i].type == FN_INPUT_TYPE)
                && (ev[i].code == FN_INPUT_CODE)
                && (ev[i].value == FN_INPUT_VALUE);
          }

        /* If we got a FN event, plz do something...*/
        if ( hasSomething && (key=getCodes()) ) {
            if ((key & FN_F5)==FN_F5) { // lower brightness
                setBrightness(getBrightness()-1);
                fileops(FN_F5, getBrightness());
            }
            if ((key & FN_F6)==FN_F6) { // higher brightness
                setBrightness(getBrightness()+1);
                fileops(FN_F6, getBrightness());
            }
            if ((key & FN_F2)==FN_F2){
                mute();
                fileops(FN_F2, 0);
            }
            if ((key & FN_F3)==FN_F3) {
                volume_down();
                get_volume(&value);
                fileops(FN_F3, value);
            }
            if ((key & FN_F4)==FN_F4) {
                volume_up();
                get_volume(&value);
                fileops(FN_F4, value);
            }
            if ((key & FN_F7)==FN_F7) {
                fileops(FN_F7, 0);
		usleep(100000);
                fileops(0, 0);
            }
            if ((key & FN_F10)==FN_F10) {
                fileops(FN_F10, 0);
		usleep(100000);
                fileops(0, 0);
            }
            if ((key & FN_F12)==FN_F12) {
                fileops(FN_F12, 0);
		usleep(100000);
                fileops(0, 0);
            }     
        }
    }// while
   
    close(fd);
    return 0;
} 
Пример #10
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{	
		case WM_FOO_GET_ACTIVE_PLAYLIST_COUNT:
			if(plist_api) return activeplaylist_get_item_count(&plist_api);
			return P_ERROR;

		case WM_FOO_GET_PLAYLIST_ITEM:
		{
			char title[512];
			wchar_t w_title[512];
			if(!ptcomp_api || !plist_api || !pback_api) return P_ERROR;
			if(wParam == -1 && !is_playing(&pback_api)) return P_ERROR;
			int tracknumb = (wParam==-1)?(int)get_playing_item_location(&plist_api):wParam;
			PTITLEFORMAT_OBJECT *t_obj=0;	// Must be 0!!!
			if(!GetWindowText(p_hWnd, title, 512)) return P_ERROR;

			if(compile(&ptcomp_api, &t_obj, title))
			{
				string_free();
				playlist_item_format_title(&plist_api, get_active_playlist(&plist_api), tracknumb, 0, &str,
								&t_obj, 0, display_level_all);
				MultiByteToWideChar(CP_UTF8, 0, str.data, -1, w_title, 512);
				SetWindowTextW(p_hWnd, w_title);
				service_release((PSERVICE_BASE*)t_obj);
				return 0;
			}
			return P_ERROR;
		}

		case WM_FOO_GET_CURRENT_TRACK:
			if(plist_api) return get_playing_item_location(&plist_api);
			return P_ERROR;

		case WM_FOO_ORDER:
			if(plist_api) {playback_order_set_active(&plist_api, wParam); return 0;}
			return P_ERROR;

		case WM_FOO_OPEN:	return main_open(&g_api);
		case WM_FOO_ADD:	return main_add_files(&g_api);
		case WM_FOO_ADDDIR:	return main_add_directory(&g_api);

		case WM_FOO_PLAY:
			if(pback_api) {start_resume(&pback_api); return 0;}
			return P_ERROR;

		case WM_FOO_STOP:
			if(pback_api) {stop(&pback_api); return 0;}
			return P_ERROR;

		case WM_FOO_PLAY_NEXT:
			if(pback_api) {start(&pback_api, track_command_next); return 0;}
			return P_ERROR;

		case WM_FOO_PLAY_PREV:
			if(pback_api) {start(&pback_api, track_command_prev); return 0;}
			return P_ERROR;

		case WM_FOO_PLAY_RANDOM:
			if(pback_api) {start(&pback_api, track_command_rand); return 0;}
			return P_ERROR;

		case WM_FOO_PAUSE:
			if(pback_api) {pause(&pback_api, true); return 0;}
			return P_ERROR;

		case WM_FOO_PLAY_PAUSE:
			if(pback_api) {play_pause(&pback_api); return 0;}
			return P_ERROR;

		case WM_FOO_VOLUME_UP:
			if(pback_api) {volume_up(&pback_api); return 0;}
			return P_ERROR;

		case WM_FOO_VOLUME_DOWN:
			if(pback_api) {volume_down(&pback_api); return 0;}
			return P_ERROR;

		case WM_FOO_GET_VOLUME:
			if(pback_api) return get_volume(&pback_api);
			return P_ERROR;

		case WM_FOO_SET_VOLUME:
			if(pback_api) {set_volume(&pback_api, wParam); return 0;}
			return P_ERROR;

		case WM_FOO_MUTE:
			if(pback_api) {mute(&pback_api); return 0;}
			return P_ERROR;

		case WM_FOO_IS_PLAYING:
			if(pback_api) return (is_playing(&pback_api) && !is_paused(&pback_api));
			return P_ERROR;

		case WM_FOOL_IS_PAUSED:
			if(pback_api) return is_paused(&pback_api);
			return P_ERROR;

		case WM_FOO_GET_STOP_AFTER_CURRENT:
			if(pback_api) return get_stop_after_current(&pback_api);
			return P_ERROR;

		case WM_FOO_SET_STOP_AFTER_CURRENT:
			if(pback_api) {set_stop_after_current(&pback_api, wParam); return 0;}
			return P_ERROR;

		case WM_FOO_PLAYBACK_CAN_SEEK:
			if(pback_api) return playback_can_seek(&pback_api);
			return P_ERROR;

		case WM_FOO_PLAYBACK_SEEK:
			if(pback_api) {playback_seek(&pback_api, wParam); return 0;}
			return P_ERROR;

		case WM_FOO_PLAYBACK_SEEK_DELTA:
			if(pback_api) {playback_seek_delta(&pback_api, wParam); return 0;}
			return P_ERROR;

		case WM_FOO_GET_POSITION:
			if(pback_api) return playback_get_position(&pback_api);
			return P_ERROR;

		case WM_FOO_GET_LENGTH:
			if(pback_api) return playback_get_length(&pback_api);
			return P_ERROR;

		case WM_FOO_EXIT:	return main_exit(&g_api);
		case WM_FOO_ACTIVATE:	return main_activate(&g_api);
		case WM_FOO_HIDE:	return main_hide(&g_api);

		case WM_FOO_PLAY_TRACK:
			if(plist_api) {playlist_execute_default_action(&plist_api, get_active_playlist(&plist_api), wParam); return 0;}
			return P_ERROR;

		case WM_FOO_REGISTER_CALLBACK:
			if(wParam & PLAYBACK_START)			AddCallback((PFCALLBACK)&callbacks, CSTARTING, (HWND)lParam, 0);
			if(wParam & PLAYBACK_DYNAMIC_INFO) 		AddCallback((PFCALLBACK)&callbacks, CDYNAMIC_INFO, (HWND)lParam, 0);
			if(wParam & PLAYBACK_DYNAMIC_INFO_TRACK)	AddCallback((PFCALLBACK)&callbacks, CDYNAMIC_INFO_TRACK, (HWND)lParam, 0);
			if(wParam & PLAYBACK_TIME)			AddCallback((PFCALLBACK)&callbacks, CTIME, (HWND)lParam, 0);
			if(wParam & PLAYBACK_VOLUME_CHANGE)		AddCallback((PFCALLBACK)&callbacks, CVOLUME_CHANGE, (HWND)lParam, 0);
			if(wParam & PLAYBACK_STOP)			AddCallback((PFCALLBACK)&callbacks, CSTOP, (HWND)lParam, 0);
			if(wParam & PLAYBACK_SEEK)			AddCallback((PFCALLBACK)&callbacks, CSEEK, (HWND)lParam, 0);
			if(wParam & PLAYBACK_PAUSE)			AddCallback((PFCALLBACK)&callbacks, CPAUSE, (HWND)lParam, 0);
			if(wParam & PLAYBACK_NEW_TRACK)
			{
				char caption[512];
				if(GetWindowText(p_hWnd, caption, 512))	AddCallback((PFCALLBACK)&callbacks, CNEW_TRACK, (HWND)lParam, caption);
			}
			
			if(wParam & PLAYBACK_EDITED)
			{
				char caption[512];
				if(GetWindowText(p_hWnd, caption, 512))	AddCallback((PFCALLBACK)&callbacks, CEDITED, (HWND)lParam, caption);
			}
			return 0;

		case WM_FOO_UNREGISTER_CALLBACK:
			if(wParam & PLAYBACK_START)			RemoveCallback((PFCALLBACK)&callbacks, CSTARTING, (HWND)lParam);
			if(wParam & PLAYBACK_NEW_TRACK) 		RemoveCallback((PFCALLBACK)&callbacks, CNEW_TRACK, (HWND)lParam);
			if(wParam & PLAYBACK_STOP)			RemoveCallback((PFCALLBACK)&callbacks, CSTOP, (HWND)lParam);
			if(wParam & PLAYBACK_SEEK)			RemoveCallback((PFCALLBACK)&callbacks, CSEEK, (HWND)lParam);
			if(wParam & PLAYBACK_PAUSE)			RemoveCallback((PFCALLBACK)&callbacks, CPAUSE, (HWND)lParam);
			if(wParam & PLAYBACK_EDITED)			RemoveCallback((PFCALLBACK)&callbacks, CEDITED, (HWND)lParam);
			if(wParam & PLAYBACK_DYNAMIC_INFO) 		RemoveCallback((PFCALLBACK)&callbacks, CDYNAMIC_INFO, (HWND)lParam);
			if(wParam & PLAYBACK_DYNAMIC_INFO_TRACK)	RemoveCallback((PFCALLBACK)&callbacks, CDYNAMIC_INFO_TRACK, (HWND)lParam);
			if(wParam & PLAYBACK_TIME)			RemoveCallback((PFCALLBACK)&callbacks, CTIME, (HWND)lParam);
			if(wParam & PLAYBACK_VOLUME_CHANGE)		RemoveCallback((PFCALLBACK)&callbacks, CVOLUME_CHANGE, (HWND)lParam);
			return 0;

		default:		return DefWindowProc(hWnd, message, wParam, lParam);
	}
}
Пример #11
0
void gp2x_poll_input(void)
{
    static int stats_button;
    static int prefs_button;
    static int vkeyb_button;
    static int joy_time = 0;
    static unsigned int a_held = 0;
    static unsigned int x_held = 0;
    unsigned int i;

    unsigned int joy_state = gp2x_joystick_read(0);

    /* start */
    if (joy_state&GP2X_START) {
        input_start = 1;
    }

    /* prefs */
    if (!(joy_state & GP2X_SELECT)) {
        prefs_button = 0;
    }
    if (joy_state & GP2X_SELECT && !prefs_button) {
        prefs_open = ~prefs_open;
        prefs_button = 1;
    }

    /* vkeyb */
    if (!(joy_state & GP2X_L)) {
        vkeyb_button = 0;
    }
    if (joy_state & GP2X_L && !vkeyb_button) {
        vkeyb_open = ~vkeyb_open;
        vkeyb_button = 1;
    }

    if (prefs_open || vkeyb_open) {
        int rrate;
        resources_get_int("RefreshRate", &rrate);
        if (!rrate) {
            rrate++;
        }
        if (joy_state & (GP2X_UP | GP2X_DOWN | GP2X_LEFT | GP2X_RIGHT)) {
            joy_time += rrate;
        } else {
            joy_time = 0;
        }
        if (joy_time == rrate || (joy_time > 6)) {
            if (joy_time > 4) {
                joy_time = rrate;
            }
            input_up = joy_state & GP2X_UP;
            input_down = joy_state & GP2X_DOWN;
            input_select = joy_state & GP2X_SELECT;
            input_left = joy_state & GP2X_LEFT;
            input_right = joy_state & GP2X_RIGHT;
        }

        /* B button */
        if ((joy_state & (GP2X_B | GP2X_PUSH)) != input_b_last) {
            input_b = joy_state & (GP2X_B | GP2X_PUSH);
            input_b_last = input_b;
        }

        /* A button */
        if ((joy_state & GP2X_A) != input_a_last) {
            input_a = joy_state & GP2X_A;
            input_a_last = input_a;
        }

        /* X button */
        if ((joy_state & GP2X_X) != input_x_last) {
            input_x = joy_state & GP2X_X;
            input_x_last = input_x;
        }
        /* Y button */
        if (!(joy_state & GP2X_Y)) {
            input_y = 0;
        }
        if ((joy_state & GP2X_Y) && !input_y) {
            input_y = 1;
        }
    }

    /* stats */
    if (!(joy_state & GP2X_R)) {
        stats_button = 0;
    }
    if (joy_state & GP2X_R && !stats_button) {
        stats_open = ~stats_open;
        stats_button = 1;
    }

    /* A */
    if (mapped_key_a) {
        if ((joy_state & GP2X_A) && (!a_held)) {
            a_held = 1;
            keyboard_set_keyarr(mapped_key_a_row, mapped_key_a_col, 1);
        } else if (a_held && (!(joy_state & GP2X_A))) {
            a_held = 0;
            keyboard_set_keyarr(mapped_key_a_row, mapped_key_a_col, 0);
        }
    }

    /* X */
    if (mapped_key_x) {
        if ((joy_state & GP2X_X) && (!x_held)) {
            x_held = 1;
            keyboard_set_keyarr(mapped_key_x_row, mapped_key_x_col, 1);
        } else if (x_held && (!(joy_state & GP2X_X))) {
            x_held = 0;
            keyboard_set_keyarr(mapped_key_x_row, mapped_key_x_col, 0);
        }
    }

    //volume
    if (gp2x_joystick_read(0) & GP2X_VOL_UP) {
        volume_up();
    } else if (gp2x_joystick_read(0) & GP2X_VOL_DOWN) {
        volume_down();
    }

    if (prefs_open || vkeyb_open) {
        return;
    }

    //gp2x joystick
    BYTE j = joystick_value[cur_port];

    if (joy_state & GP2X_UP) {
        j |= 0x01;
    } else {
        j &= ~0x01;
    }
    if (joy_state & GP2X_DOWN) {
        j |= 0x02;
    } else {
        j &= ~0x02;
    }
    if (joy_state & GP2X_LEFT) {
        j |= 0x04;
    } else {
        j &=~ 0x04;
    }
    if (joy_state & GP2X_RIGHT) {
        j |= 0x08;
    } else {
        j &= ~0x08;
    }
    if (joy_state & (GP2X_B | GP2X_PUSH)) {
        j |= 0x10;
    } else {
        j &= ~0x10;
    }
    joystick_value[cur_port] = j;

    //mapped
    if (mapped_up) {
        if (joy_state & mapped_up) {
            j |= 0x01;
            joystick_value[cur_port] = j;
        }
    }
    if (mapped_down) {
        if (joy_state & mapped_down) {
            j |= 0x02;
            joystick_value[cur_port] = j;
        }
    }
    if (mapped_left) {
        if (joy_state & mapped_left) {
            j |= 0x04;
            joystick_value[cur_port] = j;
        }
    }
    if (mapped_right) {
        if (joy_state&mapped_right) {
            j |= 0x08;
            joystick_value[cur_port] = j;
        }
    }

    gp2x_poll_usb_input();
}
Пример #12
0
int execcmd(const char * cmd, char * reply) {
	char arg[1024], * ptr;
	unsigned ncmd;
	const char * known [] = {
		"play",
		"love",
		"ban",
		"skip",
		"quit",
		"info",
		"pause",
		"discovery",
		"tag-artist",
		"tag-album",
		"tag-track",
		"artist-tags",
		"album-tags",
		"track-tags",
		"stop",
		"volume-up",
		"volume-down",
		"volume",
		"rtp",
		"status",
		"unlove",
		"detach"
	};

	memset(arg, 0, sizeof(arg));
	memset(reply, 0, BUFSIZE);

	for(ncmd = 0; ncmd < (sizeof(known) / sizeof(char *)); ++ncmd) {
		if(!strncmp(known[ncmd], cmd, strlen(known[ncmd])))
			break;
	}

	switch(ncmd) {
		case (sizeof(known) / sizeof(char *)):
			strncpy(reply, "ERROR", BUFSIZE);
			break;

		/* "play lastfm://station" */
		case 0:
			if(sscanf(cmd, "play %128[a-zA-Z0-9:/_ %,*.+-]", arg) == 1) {
				char * url;
				decode(arg, & url);
				station(url);
				free(url);
			}
			break;

		/* Love currently played track. */
		case 1:
			rate("L");
			break;

		/* Ban currently played track. */
		case 2:
			rate("B");
			break;

		/* Skip track. */
		case 3:
			rate("S");
			break;

		/* Kill Shell.FM. */
		case 4:
			quit();

		/* "info FORMAT" - returns the format string with the meta data filled in. */
		case 5:
			if(* (cmd + 5))
				strncpy(reply, meta(cmd + 5, 0, & track), BUFSIZE);
			else if(haskey(& rc, "np-file-format"))
				strncpy(
					reply,
					meta(value(& rc, "np-file-format"), 0, & track),
					BUFSIZE
				);

			break;

		/* Pause playback. */
		case 6:
			if(playfork) {
				if(pausetime) {
					kill(playfork, SIGCONT);
				}
				else {
					time(& pausetime);
					kill(playfork, SIGSTOP);
				}
			}
			break;

		/* Toggle discovery mode. Returns "DISCOVERY <ON|OFF>" */
		case 7:
			toggle(DISCOVERY);
			snprintf(
				reply,
				BUFSIZE,
				"DISCOVERY %s",
				enabled(DISCOVERY) ? "ON" : "OFF"
			);
			break;

		/* "tag-artist tag1,tag2,..." - tag the artist of the current track. */
		case 8:
			if(sscanf(cmd, "tag-artist %128s", arg) == 1)
				sendtag('a', arg, track);
			break;

		/* "tag-album tag1,tag2,..." - tag the album of the current track. */
		case 9:
			if(sscanf(cmd, "tag-album %128s", arg) == 1)
				sendtag('l', arg, track);
			break;

		/* "tag-track tag1,tag2,..." - tag the current track. */
		case 10:
			if(sscanf(cmd, "tag-track %128s", arg) == 1)
				sendtag('t', arg, track);
			break;

		/* Return comma-separated list of the current artists tags. */
		case 11:
			if((ptr = oldtags('a', track)) != NULL) {
				strncpy(reply, ptr, BUFSIZE);
				free(ptr);
				ptr = NULL;
			}
			break;

		/* Return comma-separated list of the current albums tags. */
		case 12:
			if((ptr = oldtags('l', track)) != NULL) {
				strncpy(reply, ptr, BUFSIZE);
				free(ptr);
				ptr = NULL;
			}
			break;

		/* Return comma-separated list of the current tracks tags. */
		case 13:
			if((ptr = oldtags('t', track)) != NULL) {
				strncpy(reply, ptr, BUFSIZE);
				free(ptr);
				ptr = NULL;
			}
			break;


		/* Stop playback. */
		case 14:
			if(playfork) {
				enable(STOPPED);
				kill(playfork, SIGUSR1);
			}
			break;

		/* Increase absolute volume (0-64) by 1. */
		case 15:
			volume_up();
			break;

		/* Decrease absolute volume (0-64) by 1. */
		case 16:
			volume_down();
			break;

		/*
			Set volume.
			"volume 32" - set absolute volume (0-64) to 32 (50%).
			"volume %50" - same, but using percentual volume.
			"volume +1" - same as "volume_up".
			"volume -1" - same as "volume_down".

			Returns absolute volume ("VOLUME 32").
		*/
		case 17:
			parse_volume(cmd);
			snprintf(reply, BUFSIZE, "VOLUME %d", volume);
			break;

		/* Toggle RTP (report to profile, "scrobbling"). Returns "RTP <ON|OFF>". */
		case 18:
			/* RTP on/off */
			toggle(RTP);
			snprintf(reply, BUFSIZE, "RTP %s", enabled(RTP) ? "ON" : "OFF");
			break;

		/* Get current status. Returns on of "PAUSE", "PLAYING" and "STOPPED". */
		case 19:
			strncpy(reply, PLAYBACK_STATUS, BUFSIZE);
			break;

		/* Unlove currently played track. */
		case 20:
			rate("U");
			break;
		
		/* Detach from network interface. */
		case 21:
			return 1;	
	}

	return 0;
}