当前位置: 首页>>代码示例>>C++>>正文


C++ Gpio类代码示例

本文整理汇总了C++中Gpio的典型用法代码示例。如果您正苦于以下问题:C++ Gpio类的具体用法?C++ Gpio怎么用?C++ Gpio使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Gpio类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

// Exemple : Blink diode pin 4
int main(int argc, char *argv[]) {
	Gpio gpio;	// The GPIO
	struct sigaction sigactionStruct;
	sigactionStruct.sa_handler = sigHandler;
	sigactionStruct.sa_flags = 0;
	sigemptyset(&sigactionStruct.sa_mask);

	if(sigaction(SIGINT, &sigactionStruct, NULL) == -1) {
		cerr << "SIGACTION FAILED : " << string(strerror(errno)) << endl;
		return(EXIT_FAILURE);
	}
	gpio.addPin(4, OUT);	// ADD PIN 4 (OUT)
	while(true) {
		gpio.setValueOf(4, HIGH);	// WRITE 1 IN PIN 4
		sleep(1);
		gpio.setValueOf(4, LOW);	// WRITE 0 IN PIN 4
		sleep(1);
		if(interceptedInteruption) {
			cout << "\nInteruption : the GPIO is going to be deleted" << endl;
			gpio.~Gpio();	//Delete the GPIO
			break;
		}
	}
	return(EXIT_SUCCESS);
}
开发者ID:Djeef,项目名称:Raspberry-Pi-GPIO,代码行数:26,代码来源:main_tst_GPIO.cpp

示例2: dispatch

bool dispatch(Msg& msg) {
	PT_BEGIN()
	_gpio.init();
	_gpio.setMode(Gpio::OUTPUT_PP);
	while (true) {
		timeout(_msecInterval);
		PT_YIELD_UNTIL(
				msg.is(_mqtt, SIG_CONNECTED) || msg.is(_mqtt, SIG_DISCONNECTED)
						|| timeout());
		switch (msg.signal) {
		case SIG_TICK: {
			_gpio.write(_isOn);
			_isOn = !_isOn;
			break;
		}
		case SIG_CONNECTED: {
			_msecInterval = 500;
			break;
		}
		case SIG_DISCONNECTED: {
			_msecInterval = 100;
			break;
		}
		default: {
		}
		}

	}
PT_END()
;
}
开发者ID:vortex314,项目名称:projects,代码行数:31,代码来源:Topics.cpp

示例3: fprintf

/**
 * Start a thread to constantly monitor all the input pins we are
 * interested in. When a state change is detected we store the
 * time of the change.  This creates a buffer so we can still see
 * changes that happened a short time ago (so we don't miss any).
 *
 * It also writes PWM outputs and is responsible for writing random
 * data, sine waves etc. to these outputs. 
 */
bool Gpio::startMonitor()
{
	if (!mInit){
		fprintf(stderr, "GPIO not initialised\n");
		return false;
	}

	// Do we have anything to monitor?
	if (mMonitorList.size() == 0)
		return true;

	bool usingPwm = false;
	for (auto iter = mMonitorList.begin(); iter != mMonitorList.end(); iter++)
	{
		Gpio *obj = *iter;
		int pin = obj->getPin();

		if (obj->getType() == PWM){
			// Don't start outputting PWM until we execute a relevant command
			mMonType[pin] = INACTIVE;
			mMonMutex[pin] = PTHREAD_MUTEX_INITIALIZER;

			// Set to full range initially (range map is in millis)
			mRangeMapMin[pin] = 0;
			mRangeMapMax[pin] = 100000;
			usingPwm = true;
		}
		else {
			// Input pins are always monitored
			initMonitorInput(pin);
		}
	}

	if (usingPwm){
		// Start ServoBlaster. We use this instead of hardware
		// PWM as there is only one hardware PWM pin on the Pi
		// and hardware PWM interferes with analog audio.
		if (!startServoBlaster())
			return false;
	}

	// Start monitor thread
	if (pthread_create(&mMonitorId, NULL, monitor, NULL) != 0){
		fprintf(stderr, "** Failed to start gpio monitor\n");
		return false;
	}

	// Wait for monitor to start
	for (int retries = 0; retries < 15; retries++){
		if (mMonitorRunning)
			return true;

		Engine::sleep(200);
	}

	printf("** Failed to start gpio monitor\n");
	return false;
}
开发者ID:scott-vincent,项目名称:pioscript,代码行数:67,代码来源:gpio.cpp

示例4: main

int main(int argc, char *argv[])
{

   gpioInit();

   Gpio gpio;

   
   (argc == 1) ? gpio.laserOff() : gpio.laserOn();

   cout << "argc: " << argc << endl;
}
开发者ID:agawande,项目名称:RobotCode2016,代码行数:12,代码来源:laser.cpp

示例5: main

int main ()
{
	Gpio E (Gpio::E);
	E.setOutPin(led);

 
  while (1)
  {
	  E.ChangePinState(led);
	  delay_ms(1000);
  }
}
开发者ID:creator83,项目名称:MK10DX256VLQ10,代码行数:12,代码来源:use_gpio.cpp

示例6: main_remi

void main_remi() {
	char buf[27] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm' ,'n', 'o', 'p' ,'q'
	,'r', 's','t','u','v','w','x','y','z',' '};
	// Setup STM32 system (clock, PLL and Flash configuration)
	SystemInit();





	Gpio *gpioA = STM32F103::getGpioA();
	// Set default port behavior
	GpioConfiguration portConfig(Gpio::AF_PUSH_PULL_OUTPUT | Gpio::OUTPUT_SPEED_50MHZ);
	gpioA->configure(portConfig);

	Uart *uart1 = STM32F103::getUart1();
	UartConfiguration uart1Config;
	uart1Config.baudrate 		= 9600;
	uart1Config.stopBit 		= Uart::UART_1_STOPBIT;
	uart1Config.parityEnable 	= Uart::UART_PARITY_DISABLE;
	uart1Config.wordLenght		= Uart::UART_WORD_LENGTH_8BIT;
	uart1->configure(uart1Config);

	//Uart *uart2 = STM32F103::getUart2();
	// Uart2 config

	// Tag each Uart with their respective source
	uart1->setTag(Peripheral::Controller);
	//uart2->setTag(Peripheral::Drive);

	// Configure blinking led
	GpioPinConfiguration ledPinConfig;
	ledPinConfig.pin = Gpio::GP_PUSH_PULL_OUTPUT | Gpio::OUTPUT_SPEED_50MHZ;
	gpioA->getPin(0)->configure(ledPinConfig);

	GpioPin *led = gpioA->getPin(0);

	// Blink led
	while(1) {
		led->setHigh();	// On
		for(uint32_t i=0; i<1000000; i++){
			uart1->poll();
		}

		uart1->write((char *)buf, 27);

		led->setLow();	// Off
		for(uint32_t i=0; i<1000000; i++){
			uart1->poll();
		}
	}
}
开发者ID:HalfHour,项目名称:usbarm,代码行数:52,代码来源:Application.cpp

示例7: main

int main()
{
	Gpio B (Gpio::B);
	B.settingPin (pin);



  while (1)
  {
		B.ChangePinState (pin);
		delay_ms (1000);
  }
}
开发者ID:creator83,项目名称:STM32F030K6,代码行数:13,代码来源:use_gpio.cpp

示例8: main

int main ()
{
	Buffer <uint8_t> val (5);
	Gpio * pins [2];

	Gpio D (Gpio::Port::D);
	D.settingPin(led);
	pins[0] = &D;
	pins[0]->setPin(led);
	while (1)
	{
		D.toglePin (led);
		delay_ms(1000);
	}
}
开发者ID:creator83,项目名称:MK02FN128,代码行数:15,代码来源:use_gpio.cpp

示例9: startPwmRange

bool Gpio::startPwmRange(MonitorType pwmType, int startPin, int endPin,
	int param1, int param2, int param3, int param4, int param5, bool loop)
{
	bool res = true;
	for (auto iter = mMonitorList.begin(); iter != mMonitorList.end(); iter++)
	{
		Gpio *obj = *iter;
		int pin = obj->getPin();
		if (mMonType[pin] != MON_IN && pin >= startPin && pin <= endPin){
			if (!obj->startPwm(pwmType, param1, param2, param3, param4,
					param5, loop))
			{
				res = false;
			}
		}
	}
	return res;
}
开发者ID:scott-vincent,项目名称:pioscript,代码行数:18,代码来源:gpio.cpp

示例10: findTag

void XmlReader::parseGpios() {
	std::string entries = findTag("gpios");

  if(entries.length() > 0) {
    std::vector<std::string> lines = Tools::explode(";", entries);

    for(int l=0; l<lines.size(); l++) {
      if(lines[l].length() > 0) {
        std::vector<std::string> words = Tools::explode(":", lines[l]);
        Gpio g;
        for(int w=0; w<words.size(); w++) {
          if(typeid(words.at(0))==typeid(std::string))  g.setName(words[0]);
          if(typeid(words.at(1))==typeid(std::string))  g.setGpio(atoi(words[1].c_str()));
        }
        gpios.push_back(g);
      }
    }
  }
}
开发者ID:bastardop,项目名称:autohome-pi,代码行数:19,代码来源:xmlreader.cpp

示例11: blinky

void blinky() {
	// Setup STM32 system (clock, PLL and Flash configuration)
	SystemInit();

	Gpio *gpioA = STM32F103::getGpioA();

	// Configure blinking led
	GpioPinConfiguration ledPinConfig;
	ledPinConfig.pin = Gpio::GP_PUSH_PULL_OUTPUT | Gpio::OUTPUT_SPEED_50MHZ;
	gpioA->getPin(0)->configure(ledPinConfig);

	GpioPin *led = gpioA->getPin(0);

	while(1) {
		led->setHigh();	// On
		for(uint32_t i=0; i<1000000; i++);
		led->setLow();	// Off
		for(uint32_t i=0; i<1000000; i++);
	}
}
开发者ID:HalfHour,项目名称:usbarm,代码行数:20,代码来源:Application.cpp

示例12: while

/**
 * Runs in a separate thread
 */
void *Gpio::monitor(void *arg)
{
	mMonitorRunning = true;
	while (mMonitorRunning){
		double now = Engine::timeNow();
		for (auto iter = mMonitorList.begin(); iter != mMonitorList.end(); iter++)
		{
			Gpio *obj = *iter;
			int pin = obj->getPin();

			switch (mMonType[pin]) {
				case INACTIVE:
					break;

				case MON_IN:
					monitorInput(pin, now);
					break;

				case PWM_RANDOM:
					monitorPwmRandom(pin, now);
					break;

				case PWM_LINEAR:
					monitorPwmLinear(pin, now);
					break;

				case PWM_SINE:
					monitorPwmSine(pin, now);
					break;

				default:
					printf("Unknown monitor pin type\n", mMonType[pin]);
					mMonitorRunning = false;
					pthread_exit(NULL);
			}
		}
		Engine::sleep(10);
	}
	pthread_exit(NULL);
}
开发者ID:scott-vincent,项目名称:pioscript,代码行数:43,代码来源:gpio.cpp

示例13: main_francois

void main_francois() {
	// Setup STM32 system (clock, PLL and Flash configuration)
	SystemInit();

	Gpio *gpioA = STM32F103::getGpioA();
	Gpio *gpioB = STM32F103::getGpioB();
	Gpio *gpioC = STM32F103::getGpioC();

	// Set default port behavior
	GpioConfiguration portConfig(Gpio::FLOATING_INPUT);
	gpioA->configure(portConfig);

	// Configure blinking led
	GpioPinConfiguration ledPinConfig;
	ledPinConfig.pin = Gpio::GP_PUSH_PULL_OUTPUT | Gpio::OUTPUT_SPEED_50MHZ;
	gpioA->getPin(0)->configure(ledPinConfig);

	GpioPin *led = gpioA->getPin(0);

	// Create the usb port
	Usb* usb = STM32F103::getUsb();

	// Create a new NES controller interface
	AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_DISABLE;	// JTAG remap
	NesControllerInterface* nesInterface = new NesControllerInterface(gpioB->getPin(3), gpioB->getPin(4), gpioC->getPin(5));
	usb->addEventListener(nesInterface);

	usb->listenForDevice();

	while(!usb->deviceDetected());

	//debug
	// Blink led fast
	led->setHigh();	// On
	for(uint32_t i=0; i<100000; i++);
	led->setLow();	// Off
	for(uint32_t i=0; i<100000; i++);

	usb->enumerateDevice();

	// Blink led
	while(1) {

		//if(usb->deviceDetected()) {
			/*led->setHigh();	// On
			for(uint32_t i=0; i<100000; i++);
			led->setLow();	// Off
			for(uint32_t i=0; i<100000; i++);*/

			//if(!usb->deviceEnumerated()) {

				//debug
				// Blink led fast
				/*GPIOA->BSRR |= 0x01;	// On
				for(uint32_t i=0; i<100000; i++);
				GPIOA->BRR |= 0x01;	// Off
				for(uint32_t i=0; i<100000; i++);

				usb->enumerateDevice();*/
			//}
			//else {
				usb->serviceHid();
			//}
		//}

		/*
		led->setHigh();	// On
		for(uint32_t i=0; i<1000000; i++);

		led->setLow();	// Off
		for(uint32_t i=0; i<1000000; i++);
		*/

		// Simulate an external interrupt
		//EXTI->SWIER |= EXTI_SWIER_SWIER1;
	}
}
开发者ID:HalfHour,项目名称:usbarm,代码行数:77,代码来源:Application.cpp

示例14: do_test

int do_test()
{
	Gpio gpio;

	if (gpio.start() < 0) {
		return -1;
	}

	gpio.configgpio(LED_CNF | LED_pinR);
	gpio.configgpio(LED_CNF | LED_pinG);
	gpio.configgpio(LED_CNF | LED_pinB);


	gpio.gpiowrite(LED_pinR, LED_OFF);
	gpio.gpiowrite(LED_pinG, LED_OFF);
	gpio.gpiowrite(LED_pinB, LED_OFF);
	printf("off\n");
	sleep(2);

	gpio.gpiowrite(LED_pinR, LED_ON);
	gpio.gpiowrite(LED_pinG, LED_OFF);
	gpio.gpiowrite(LED_pinB, LED_OFF);
	printf("red\n");
	sleep(2);

	gpio.gpiowrite(LED_pinR, LED_OFF);
	gpio.gpiowrite(LED_pinG, LED_ON);
	gpio.gpiowrite(LED_pinB, LED_OFF);
	printf("green\n");
	sleep(2);

	gpio.gpiowrite(LED_pinR, LED_OFF);
	gpio.gpiowrite(LED_pinG, LED_OFF);
	gpio.gpiowrite(LED_pinB, LED_ON);
	printf("blue\n");
	sleep(2);

	gpio.gpiowrite(LED_pinR, LED_OFF);
	gpio.gpiowrite(LED_pinG, LED_OFF);
	gpio.gpiowrite(LED_pinB, LED_OFF);
	printf("off\n");
	gpio.stop();

	return 0;
}
开发者ID:2013-8-15,项目名称:Firmware,代码行数:45,代码来源:test.cpp

示例15: main

int main(int argc, char* argv[])
{
	int status	= 0;

	char 	*device;
	char	*function;
	char	*json;

	rapidjson::Document jsonDoc;

	ExpLed 	expLedObj;
	Gpio 	gpioObj;

	int 	verbosity 		= UBUS_INTF_VERBOSE;
	int 	debugLevel		= UBUS_INTF_DEBUG;


	//// initialization
	// allocate memory for the pointers
	device 		= new char[1024];
	function 	= new char[1024];
	json 		= new char[1024];

	
	
	// parse the command line arguments
	if (UBUS_INTF_VERBOSE) printf("Parsing arguments:\n");
	for (int i = 1; i < argc; i++) 	{
		if ( strcmp(argv[i], "-device") == 0 )	{
			// get the device name
			strcpy( device, argv[++i] );
			
			if (UBUS_INTF_VERBOSE) printf("\tparsing device: %s\n", device);
		}
		else if ( strcmp(argv[i], "-function") == 0 )	{
			// get the function name
			strcpy( function, argv[++i] );
			
			if (UBUS_INTF_VERBOSE) printf("\tparsing function: %s\n", function);
		}	
		else if ( strcmp(argv[i], "-json") == 0 )	{
			// get the json
			strcpy( json, argv[++i] );
			
			if (UBUS_INTF_VERBOSE) printf("\tparsing json: %s\n", json);
		}
		else if ( strcmp(argv[i], "-verbose") == 0 )	{
			// change the verbosity setting
			verbosity 	= 1;
		}
		else if ( strcmp(argv[i], "-debug") == 0 )	{
			// change the debug setting
			debugLevel 	= 1;
		}
	}


	// class initialization
	expLedObj.SetVerbosity(verbosity);
	expLedObj.SetDebugMode(debugLevel);

	gpioObj.SetVerbosity(verbosity);
	gpioObj.SetDebugMode(debugLevel);


	// check device against list of existing devices
	/* TODO: make this cleaner */
	if (UBUS_INTF_VERBOSE) printf("Running process on ");
	if (strcmp( device, "expled") == 0)	{
		if (UBUS_INTF_VERBOSE) printf("expLed Object:\n\n");
		expLedObj.Process(function, json);
	}
	else if (strcmp( device, "gpio") == 0)	{
		if (UBUS_INTF_VERBOSE) printf("gpio Object:\n\n");
		gpioObj.Process(function, json);
	}


	//// clean-up
	// free dynamically allocated memory
	delete[] device;
	delete[] function;
	delete[] json;


	return 0;
}
开发者ID:OnionIoT,项目名称:ubus-intf,代码行数:87,代码来源:ubus_intf.cpp


注:本文中的Gpio类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。