コード例 #1
0
ファイル: wiringPiI2C.c プロジェクト: UtahDARCLab/wiringPi
int wiringPiI2CSetupInterface (const char *device, int devId)
{
  int fd ;

  if ((fd = open (device, O_RDWR)) < 0)
    return wiringPiFailure (WPI_ALMOST, "Unable to open I2C device: %s\n", strerror (errno)) ;

  if (ioctl (fd, I2C_SLAVE, devId) < 0)
    return wiringPiFailure (WPI_ALMOST, "Unable to select I2C device: %s\n", strerror (errno)) ;

  return fd ;
}
コード例 #2
0
int drcSetup (const int pinBase, const int numPins, const char *device)
{
  int fd ;
  int ok, tries ;
  time_t then ;
  struct wiringPiNodeStruct *node ;

  if ((fd = serialOpen (device, 115200)) < 0)
    return wiringPiFailure (WPI_ALMOST, "Unable to open DRC device (%s): %s", device, strerror (errno)) ;

  delay (10) ;	// May need longer if it's an Uno that reboots on the open...

// Flush any pending input

  while (serialDataAvail (fd))
    (void)serialGetchar (fd) ;

  ok = FALSE ;
  for (tries = 1 ; tries < 5 ; ++tries)
  {
    serialPutchar (fd, '@') ;
    then = time (NULL) + 2 ;
    while (time (NULL) < then)
      if (serialDataAvail (fd))
      {
        if (serialGetchar (fd) == '@')
        {
          ok = TRUE ;
          break ;
        }
      }
    if (ok)
      break ;
  }

  if (!ok)
  {
    serialClose (fd) ;
    return wiringPiFailure (WPI_FATAL, "Unable to communidate with DRC device") ;
  }

  node = wiringPiNewNode (pinBase, numPins) ;

  node->fd              = fd ;
  node->pinMode         = myPinMode ;
  node->pullUpDnControl = myPullUpDnControl ;
  node->analogRead      = myAnalogRead ;
  node->digitalRead     = myDigitalRead ;
  node->digitalWrite    = myDigitalWrite ;
  node->pwmWrite        = myPwmWrite ;

  return 0 ;
}
コード例 #3
0
ファイル: wiringPiSPI.c プロジェクト: GalenRhodes/wiringPi
int wiringPiSPISetup (int channel, int speed)
{
    int fd ;
    int model, rev, mem, maker, overVolted ;

    piBoardId (&model, &rev, &mem, &maker, &overVolted) ;

    channel &= 1 ;

    if (model == PI_MODEL_ODROIDXU_34)    {
        if (channel)
            return wiringPiFailure (WPI_ALMOST, "ODROID-XU3/4 cannot support spi-channel 1.\n") ;

        if ((fd = open (spiDev0_XU, O_RDWR)) < 0)
            return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ;
    }
    else if (model == PI_MODEL_ODROIDC)  {
        if (channel)
            return wiringPiFailure (WPI_ALMOST, "ODROID-C1/C1+ cannot support spi-channel 1.\n") ;

        if ((fd = open (spiDev0, O_RDWR)) < 0)
            return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ;
    }
    else if (model == PI_MODEL_ODROIDC2)	{
        return wiringPiFailure (WPI_ALMOST, "ODROID-C2 cannot support spi-channel\n") ;
    }
    else  {
        if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR)) < 0)
            return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ;
    }

    spiSpeeds [channel] = speed ;
    spiFds    [channel] = fd ;

// Set SPI parameters.
//	Why are we reading it afterwriting it? I've no idea, but for now I'm blindly
//	copying example code I've seen online...

    if (ioctl (fd, SPI_IOC_WR_MODE, &spiMode)         < 0)
        return wiringPiFailure (WPI_ALMOST, "SPI Mode Change failure: %s\n", strerror (errno)) ;

    if (ioctl (fd, SPI_IOC_WR_BITS_PER_WORD, &spiBPW) < 0)
        return wiringPiFailure (WPI_ALMOST, "SPI BPW Change failure: %s\n", strerror (errno)) ;

    if (ioctl (fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed)   < 0)
        return wiringPiFailure (WPI_ALMOST, "SPI Speed Change failure: %s\n", strerror (errno)) ;

    return fd ;
}
コード例 #4
0
ファイル: mruby_Pi.c プロジェクト: jbreeden/mruby-wiring-pi
/* wiringPiFailure
 *
 * Parameters:
 * - fatal: int
 * - message: const char *
 * Return Type: int
 */
mrb_value
mrb_Pi_wiringPiFailure(mrb_state* mrb, mrb_value self) {
  mrb_int native_fatal;
  char * native_message;

  /* Fetch the args */
  mrb_get_args(mrb, "iz", &native_fatal, &native_message);

  /* Invocation */
  int result = wiringPiFailure(native_fatal, native_message);

  /* Box the return value */
  mrb_value return_value = mrb_fixnum_value(result);

  return return_value;
}