예제 #1
0
파일: tws_abs_eg.c 프로젝트: bbl232/gpio
int main (){
	/*We need to call this function at the beginning of all out programs that use the library*/
	RPi_init();

	/*The pins that the switch is connected to*/
	int pin1 = 13;
	int pin2 = 15;

	int position=-1;

	/*We need a switch, and we're going to want to make sure it got created*/
	TWS * sw = RPi_TWS_open(pin1,pin2);
	if(sw==NULL){
		printf("Error: %s\n",RPi_errorstr(RPi_errorno()));
		return 1;
	}

	/*Lets see if its light or dark out there*/
	if(0!=RPi_TWS_readPosition(sw,&position)){
		printf("Error: %s\n", RPi_errorstr(RPi_errorno()));
		return 1;
	}

	/*Tell the world what we have discovered!*/
	printf("The switch is in position %d.\n",position);

	/*Close our connection to the photoresistor*/
	if(0!=RPi_TWS_close(sw)){
		printf("Error: %s\n", RPi_errorstr(RPi_errorno()));
		return 1;
	}

	return 0;
}
예제 #2
0
파일: led_abs_eg.c 프로젝트: bbl232/gpio
int main (){
	/*We need to call this function at the beginning of all out programs that use the library*/
	RPi_init();
	/*These are the pins that the LEDs are hooked up to.
	These can change depending on how everything is wired up*/
	int pin1 = 9;
	int pin2 = 10;

	/*These variables are how we will interact with those LEDs.*/
	LED * led1 = RPi_LED_open(pin1);
	
	/*We should check that these pins actually got created before we start using them.*/
	if(led1==NULL){
		printf("Error creating LED: %s\n",RPi_errorstr(RPi_errorno()));
		return 1;
	}
	
	LED * led2 = RPi_LED_open(pin2);
	/*Again, check to make sure the pin was created.*/
	if(led2==NULL){
		printf("Error creating LED: %s\n",RPi_errorstr(RPi_errorno()));
		return 1;
	}
	
	/*If this function does not return 0, we know something has gone wrong.
	We can look up what happened.*/
	if(0!=RPi_LED_toggle(led1)){
		printf("Error: %s\n",RPi_errorstr(RPi_errorno()));
	}

	/*This prints a message to the screen and waits for any character input, the input is ignored.*/
	printf("Press enter to toggle the LEDs\n");
	getchar();

    if(0!=RPi_LED_toggle(led2)){
        printf("Error: %s\n",RPi_errorstr(RPi_errorno()));
    }
	
    if(0!=RPi_LED_toggle(led1)){
        printf("Error: %s\n",RPi_errorstr(RPi_errorno()));
    }

	printf("Press enter to terminate\n");
	getchar();


    if(0!=RPi_LED_off(led2)){
        printf("Error: %s\n",RPi_errorstr(RPi_errorno()));
    }

	if (0!=RPi_LED_close(led1)){
		printf("Error closing LED: %s\n",RPi_errorstr(RPi_errorno()));
	}
	if (0!=RPi_LED_close(led2)){
		printf("Error closing LED: %s\n",RPi_errorstr(RPi_errorno()));
	}
	return 0;
}
예제 #3
0
int
main (void)
{

  /*****************************************************************************
   *
   * initialize and register all modules
   *
   *****************************************************************************/

  init_modules();

#ifdef ENABLE_DIO
  register_module((uint16_t**)gpio_Mod_Info);
#endif

#ifdef ENABLE_ADC
  register_module((uint16_t**)ADC_Mod_Info);
#endif

#ifdef ENABLE_PWM
  register_module((uint16_t**)pwm_Mod_Info);
#endif


  /*****************************************************************************
   *
   * initilaize 1ms timer-interrupt and enable interrupts globaly
   *
   *****************************************************************************/

  init_SysTimer ();
  DebugTick = request_SysTimer ();
  ProcTick = request_SysTimer ();

  /*****************************************************************************
   *
   * initilaize spi-communication and data-structures
   *
   *****************************************************************************/

  RPi_init (MAX(sizeof(OMap_t), sizeof(IMap_t)), 20, &RPi);

  /*****************************************************************************
   *
   * register SPI-commands from all modules
   *
   *****************************************************************************/

  register_mod_spi_commands();

  sps_init ();

#ifdef ENABLE_XCOM
  /*****************************************************************************
   *
   * check if slave present and enable it
   *
   *****************************************************************************/

  if (Xcom_init ())
    {
      Features |= SP_BIT;
      SlaveTick = request_SysTimer();
    }
#endif

  RPi_start ();	// Finaly start SPI-communication

  DDRD |= ((1 << PD4) | (1 << PD5));

  DEBUGTICK = 0;

  /*****************************************************************************
   *
   * main loop starts her
   *
   *****************************************************************************/

  while (1)
    {

      /*****************************************************************************
       *
       * call the components workers
       *
       *****************************************************************************/

      RPi_worker ();
      sps_worker ();

/*	  switch (RPi.Status)
	    {
	    case RPI_STAT_IDLE:
	      PORTD |= ((1 << PD4) | (1 << PD5)); // 1 1;
	      break;
	    case RPI_STAT_RUN:
	      PORTD = PORTB & ~((1 << PD4) | (1 << PD5));	// 0 0
	      break;
	    case RPI_STAT_AUTO:
	      PORTD &= ~(1 << PD4);
	      PORTD |= (1 << PD5);	// 0 1
	      break;
	    case RPI_STAT_CRC16_ERROR:
	      PORTD &= ~(1 << PD5);
	      PORTD |= (1 << PD4);	// 1 0
	      break;
	    case RPI_STAT_MAN:
	    case RPI_STAT_MAN_UNKNOWN:
	      break;
	    }
	    */

      /*****************************************************************************
       *
       * some debugging helper
       *
       *****************************************************************************/

/*      if (DEBUGTICK == 2)
	{
	      DEBUGTICK = 0;
	}
*/

#ifdef ENABLE_XCOMM
      if (SLAVE_PRESENT)
	{
	  Xcom_worker ();
	  if (SL_TICK == 3)
	    {
/*	      if (make_crc16 (sizeof(SMap_t), (uint8_t *) &XcomRxBuffer.buf)
		  == XcomRxBuffer.rio.crc16)
		{
		  memcpy((void *)&SlaveMap,&XcomRxBuffer.rio.io,sizeof(SMap_t));
		}
*/
	      Xcom_ack ();
	      Xcom_cmd (XCMD_INPUT, 15, &RealOutput);
//	      Xcom_cmd (XCMD_INPUT, sizeof(IMap_t), &InputMap);
	      SL_TICK++;
	    }
	  if (SL_TICK == 16)
	    {
	      Xcom_ack ();
	      Xcom_cmd (XCMD_OUTPUT, sizeof(OMap_t), RPi.tx);
	      SL_TICK++;
	    }
	  if (SL_TICK >= 25)
	    {
	      SL_TICK = 0;
	    }

	}
#endif

      /*****************************************************************************
       *
       * main loop ends here
       *
       *****************************************************************************/

    }

}