Example #1
0
int ir_send(unsigned ir_out,unsigned long* data,int len)
{
  register int cnt = 0;

  puts("----- IR SEDN MODE -----");

  for (cnt = 0; cnt < len; cnt++) 
  {
    printf("%lu,",data[cnt]);
  }
  digitalWrite(ir_out,0);
  puts("start.");
//  pwmNSOut(1,25600,8400);  //39khz
  pwmNSOut(1,26300,8800);  //38khz
//  pwmNSOut(1,25600,8600);  //39khz
 // pwmNSOut(1,25000,8400);  //40khz
 // pwmNSOut(1,24400,8100);  //41khz
 // pwmNSOut(1,27000,9000);  //37khz
 // pwmNSOut(1,27800,9300);  //36khz
 // pwmNSOut(1,28600,9500);  //35khz
 // pwmNSOut(1,29400,9800);  //34khz
 // pwmNSOut(1,30300,10100); //33khz
 // pwmNSOut(1,31300,10400); //32khz
 // pwmNSOut(1,32300,10800); //31khz

  for (cnt = 0; cnt < len; cnt++) 
  {
    digitalWrite(ir_out,1-(cnt&1));
    usleep(data[cnt] );
  }
  digitalWrite(ir_out,0);
  pwmRun(1,0);

  puts("ok");
  puts("----- SEND DONE ------");
  
  return 1;
}
Example #2
0
int main(int argc, char* argv[])
{
	int 		status;
	int 		ch;

	const char 	*progname;
	char*		val 	= new char[255];
	
	gpioSetup* 	setup 	= new gpioSetup;

	// reset gpio setup and set defaults
	initGpioSetup(setup);

	setup->verbose 		= FASTGPIO_DEFAULT_VERBOSITY;
	setup->debug 		= FASTGPIO_DEFAULT_DEBUG;

	// save the program name
	progname = argv[0];	


	//// parse the option arguments
	while ((ch = getopt(argc, argv, "vqud")) != -1) {
		switch (ch) {
		case 'v':
			// verbose output
			setup->verbose = FASTGPIO_VERBOSITY_ALL;
			break;
		case 'q':
			// quiet output
			setup->verbose = FASTGPIO_VERBOSITY_QUIET;
			break;
		case 'u':
			// ubus output
			setup->verbose = FASTGPIO_VERBOSITY_JSON;
			break;
		case 'd':
			// debug mode
			setup->debug 	= 1;
			break;
		default:
			usage(progname);
			return 0;
		}
	}

	// advance past the option arguments
	argc 	-= optind;
	argv	+= optind;

	// parse the arguments
	if (parseArguments(progname, argc, argv, setup) == EXIT_FAILURE) {
		return EXIT_FAILURE;
	}


	// check for any pwm processes already running on this pin
	status = checkOldProcess(setup);


	// run the command
	if (setup->cmd != GPIO_CMD_PWM) {
		// single gpio command
		status = gpioRun(setup);
	}
	else {
		//// continuous gpio commands, need another process

		// create the new process
		pid_t pid = fork();

		if (pid == 0) {
			// child process, run the pwm
			status = pwmRun(setup);
		}
		else {
			// parent process
			if (FASTGPIO_VERBOSE > 0) printf("Launched child pwm process, pid: %d \n", pid);
			noteChildPid(setup->pinNumber, pid);

			if ( setup->verbose == FASTGPIO_VERBOSITY_JSON ) {
				sprintf(val, "%dHz with %d%% duty", setup->pwmFreq, setup->pwmDuty);
				printf(FASTGPIO_JSON_STRING, setup->cmdString, setup->pinNumber, val);
			}
		}
	}


	// clean-up
	delete 	val;
	delete 	setup;

	return 0;
}