/**
 * Sets the given LED to the given state.
 *
 * @param num LED to change.
 * @param state State to set.
 */
void user_Set_LED(char num, char state)
{
    switch (num)
    {
        case LED_CLEAR:
            if (!state) setPinMode(MODE_HIGH, LED_1_PORT, LED_1_PIN);
            else setPinMode(MODE_LOW, LED_1_PORT, LED_1_PIN);
            break;
        case LED_STOP:
            if (!state) setPinMode(MODE_HIGH, LED_2_PORT, LED_2_PIN);
            else setPinMode(MODE_LOW, LED_2_PORT, LED_2_PIN);
            break;
        case LED_START:
            if (!state) setPinMode(MODE_HIGH, LED_3_PORT, LED_3_PIN);
            else setPinMode(MODE_LOW, LED_3_PORT, LED_3_PIN);
            break;
        case LED_POWER:
            if (!state) setPinMode(MODE_HIGH, LED_POWER_PORT, LED_POWER_PIN);
            else setPinMode(MODE_LOW, LED_POWER_PORT, LED_POWER_PIN);
            break;
        case LED_GPS:
            if (!state) setPinMode(MODE_HIGH, LED_GPS_PORT, LED_GPS_PIN);
            else setPinMode(MODE_LOW, LED_GPS_PORT, LED_GPS_PIN);
            break;

    }
}
Beispiel #2
0
int initWiringPi (void){

	if (wiringPiSetup () < 0){
		timestamp();
		printf ( "Error unable to setup wiringPi: %s\n", strerror (errno));
		return 1 ;
	}
	
	setPinMode (21,1,1);	//SMOKE
	setPinMode (22,1,1);	//SMOKE
	//setPinMode (23,1,1);	//DOOR
	setPinMode (24,1,1);	//MAINS
  
	return 0;
}
Beispiel #3
0
void resetPinModeHardwarePWM(int pin)
{
    if (pin >= 0 && pin < NUM_DIGITAL_PINS) {
        int port = digitalPinToPort(pin);
        if (port == NOT_A_PIN) {
            return;
        }
        switch (pin) {
        case PIN_IO1:
            setPinMode(pin, PinModeInput);
            //stopModule(MstpIdTPU3);
            break;
        case PIN_IO0:
            setPinMode(pin, PinModeInput);
            //stopModule(MstpIdMTU1);
            break;
        case PIN_IO28:
            setPinMode(pin, PinModeInput);
            //stopModule(MstpIdTPU3);
            break;
        case PIN_IO29:
            setPinMode(pin, PinModeInput);
            //stopModule(MstpIdTPU3);
            break;
        case PIN_IO32:
            setPinMode(pin, PinModeInput);
            //stopModule(MstpIdMTU4);
            break;
        case PIN_IO5:
            setPinMode(pin, PinModeInput);
            setPinMode(PIN_IO23, PinModeInput); // for multiple connection
            //stopModule(MstpIdTPU4);
            break;
        case PIN_IO7:
            setPinMode(pin, PinModeInput);
            //stopModule(MstpIdTPU0);
            break;
        case PIN_IO8:
            setPinMode(pin, PinModeInput);
            //stopModule(MstpIdTPU0);
            break;
        case PIN_IO11:
            setPinMode(pin, PinModeInput);
            //stopModule(MstpIdMTU1);
            break;
        }
    }
}
Beispiel #4
0
int intSetup (void){
	unsigned int i;
	
	setPinMode();

	/*for (i=0 ; i < INT_PORTS ; i++)
		wiringPiISR (intPorts[i], INT_EDGE_FALLING, &func);*/
	wiringPiISR (doorPorts, INT_EDGE_BOTH, &func);

	return 0;
} 
/**
 * Initializes the button and LED port settings.
 */
void user_Init(void)
{
    //LEDs
    setPinMode(MODE_LOW, LED_POWER_PORT, LED_POWER_PIN);
    setPinMode(MODE_LOW, LED_GPS_PORT, LED_GPS_PIN);
    setPinMode(MODE_LOW, LED_1_PORT, LED_1_PIN);
    setPinMode(MODE_LOW, LED_2_PORT, LED_2_PIN);
    setPinMode(MODE_LOW, LED_3_PORT, LED_3_PIN);

    //Buttons
    setPinMode(MODE_INPUT_SRC, BUTTON_PORT, BUTTON_1_PIN);
    setPinMode(MODE_INPUT_SRC, BUTTON_PORT, BUTTON_2_PIN);
    setPinMode(MODE_INPUT_SRC, BUTTON_PORT, BUTTON_3_PIN);
}
Beispiel #6
0
Move::Move(int _stby, int _pwma, int _pwmb, int _ain1, int _ain2, int _bin1, int _bin2)
{
    // Set internal variables for Motor Controller
    STBY = _stby;
    PWMA = _pwma;
    PWMB = _pwmb;
    AIN1 = _ain1;
    AIN2 = _ain2;
    BIN1 = _bin1;
    BIN2 = _bin2;
  
    setPinMode();
}
void processTWIMessage()
{
  int i;
  if(g_twi_sr_recv_buffer[0] == TWIMSG_HEADER) {
    switch(g_twi_sr_recv_buffer[1]) {
      case TWIMSG_REGACCESS:
        g_current_register = g_twi_sr_recv_buffer[2];
        for(i = 3; i < g_twi_sr_recv_index; i++) {
          *g_current_register = g_twi_sr_recv_buffer[i];
          g_current_register++;
        }
        break;
      case TWIMSG_SET_PIN_MODE:
        setPinMode(g_twi_sr_recv_buffer[2], g_twi_sr_recv_buffer[3]);
        break;
      case TWIMSG_DIGITAL_WRITE_PIN:
        digitalWritePin(g_twi_sr_recv_buffer[2], g_twi_sr_recv_buffer[3]);
        break;
      case TWIMSG_DIGITAL_READ_PIN:
        digitalReadPin(g_twi_sr_recv_buffer[2]);
        break;
      case TWIMSG_ANALOG_WRITE_PIN:
        analogWritePin(g_twi_sr_recv_buffer[2], g_twi_sr_recv_buffer[3]);
        break;
      case TWIMSG_ANALOG_READ_PIN:
        analogReadPin(g_twi_sr_recv_buffer[2]);
        break;
      case TWIMSG_ANALOG_REF:
        analogSetRef(g_twi_sr_recv_buffer[2]);
        break;
    }
  } else {
    /* This message is probably a bluetooth comms message: forward it to the serial */
    /* No need to send zigbee portion of message, start at i=5 */
    if((g_mobotMode == 0) || (g_mobotMode == 1) ) {
      for(i = 5; (i-5) < g_twi_sr_recv_buffer[6] ; i++) {
        g_serialBufferOut[(g_serialBufferOutN + g_serialBufferOutIndex)%SERIAL_BUFFER_SIZE] = 
          g_twi_sr_recv_buffer[i];
        g_serialBufferOutN++;
      }
    } else {
      for(i = 0; i < g_twi_sr_recv_buffer[1] ; i++) {
        g_serialBufferOut[(g_serialBufferOutN + g_serialBufferOutIndex)%SERIAL_BUFFER_SIZE] = 
          g_twi_sr_recv_buffer[i];
        g_serialBufferOutN++;
      }
    }
  }
}
Beispiel #8
0
void analogWrite(uint8_t pin, int16_t val)
{
	uint8_t timer = 0xff;
	setPinMode(pin, OUTPUT);
	
	if ((val == 0) || (val <0))
	{
		digitalWrite(pin, LOW);

	}
	else if ((val > 255) || (val == 255))
	{
		digitalWrite(pin, HIGH);

	}
	else
	{
		timer = digitalPinToTimer(pin);
		initPwm(timer);
		setPwmDutyCycle((uint8_t)val, timer);

	}
	
}
Beispiel #9
0
void Bounce::attach(int pin, int mode){
    setPinMode(pin, mode);
    this->attach(pin);
}
Beispiel #10
0
void MCP23S17::initializeDevice() {
    pinMode(_cs, OUTPUT);
    digitalWrite(_cs, HIGH);
    _spi->begin();
    setRegister(0x0A, 0b00111000);


    setPinMode(0, OUTPUT);
    while(1) {
        setPin(0, HIGH);
        setPin(0, LOW);
    }


    setPinMode(_db0, OUTPUT);
    setPinMode(_db1, OUTPUT);
    setPinMode(_db2, OUTPUT);
    setPinMode(_db3, OUTPUT);
    setPinMode(_db4, OUTPUT);
    setPinMode(_db5, OUTPUT);
    setPinMode(_db6, OUTPUT);
    setPinMode(_db7, OUTPUT);
    setPinMode(_tcs, OUTPUT);
    setPinMode(_rs, OUTPUT);
    setPinMode(_enable, OUTPUT);
}
void setupOutput()
{
    for (unsigned int output = 0; output < OUTPUT_MAX; output++)
        setPinMode(output_pins[output], Device::PINMODE_OUTPUT);
}
Beispiel #12
0
int main(void)
{
  int i = 0;       // Loop iterator iterator

  //char inputBuffer = HIGH; // create and clear a buffer for data from pins

  char path[256]; // nice, long buffer to hold the path name for pin access

// This first loop does four things:
//   - initialize the file descriptors for the pin mode files
//   - initialize the file descriptors for the pin data files
//   - make the pins outputs
//   - set all the pins low

  int pinid,modeid;
for (i = 3; i < 4; i++)
  {
    // Clear the path variable...
    memset(path,0,sizeof(path));
    // ...then assemble the path variable for the current pin mode file...
    sprintf(path, "%s%s%d", GPIO_MODE_PATH, GPIO_FILENAME, i);
    // ...and create a file descriptor...
    modeid = open(path, O_RDWR);
    // ...then rinse, repeat, for the pin data files.
    memset(path,0,sizeof(path));
    sprintf(path, "%s%s%d", GPIO_PIN_PATH, GPIO_FILENAME, i);
    pinid = open(path, O_RDWR); 
    // Now that we have descriptors, make the pin an output, then set it low.
    setPinMode(modeid, OUTPUT);
    setPin(pinid, LOW);
    printf("Pin %d low\n", i);  // Print info to the command line.
    }

  int pin = 5;
  //gpio_set(pin,OUTPUT);

// Now, we're going to wait for a button connected to pin 2 to be pressed
//  before moving on with our demo.
setPinMode(modeid, OUTPUT);

  //gpio_set(2,OUTPUT);

//int modeid = openPinMode(2);
//int pinid = openPin(2);
 
//gpio_write(pin,LOW);
 setPin(pinid,1);
//printf(" value %c \n", getPin(pinid));
for (i = 0; i <= 100; i++)
  {
    //if(gpio_read(2) ==  LOW)
      //setPin(pinData[2], HIGH);
      //gpio_write(2,1);
    //printf("Pin %d HIGH\n", i);
    //else
      //setPin(pinData[2], LOW);
      //gpio_write(2,0);

    printf(" value %c \n", getPin(pinid));
    // printf("value %c \n", gpio_read(2));
    //if(gpio_read(pin) == LOW)
      if(getPin(pinid) == LOW)
	setPin(pinid,HIGH);
      //gpio_write(pin,HIGH);
    else
      setPin(pinid,LOW);
      //gpio_write(pin,LOW);
    
    usleep(250000);  
  }


closePin(pinid);
closePin(modeid);
}
Beispiel #13
0
int main(void)
{
  int res = 0;  // We can use this to monitor the results of any operation.

  // The very first thing we need to do is make sure that the pins are set
  //   to SPI mode, rather than, say, GPIO mode.
  char path[256];
  
  for (int i = 10; i<=13; i++)
  {
    // Clear the path variable...
    memset(path,0,sizeof(path));
    // ...then assemble the path variable for the current pin mode file...
    sprintf(path, "%s%s%d", GPIO_MODE_PATH, GPIO_FILENAME, i);
    // ...and create a file descriptor...
    int pinMode = open(path, O_RDWR);
    // ...which we then use to set the pin mode to SPI...
    setPinMode(pinMode, SPI);
    // ...and then, close the pinMode file.
    close(pinMode);
  }
    
  // As usual, we begin the relationship by establishing a file object which
  //   points to the SPI device.
  int spiDev = open(spi_name, O_RDWR);
  
  // We'll want to configure our SPI hardware before we do anything else. To do
  //   this, we use the ioctl() function. Calls to this function take the form
  //   of a file descriptor, a "command", and a value. The returned value is
  //   always the result of the operation; pass it a pointer to receive a value
  //   requested from the SPI peripheral.
  
  // Start by setting the mode. If we wanted to *get* the mode, we could
  //   use SPI_IOC_RD_MODE instead. In general, the "WR" can be replaced by
  //   "RD" to fetch rather than write. Also note the somewhat awkward
  //   setting a variable rather than passing the constant. *All* data sent
  //   via ioctl() must be passed by reference!
  int mode = SPI_MODE0;
  ioctl(spiDev, SPI_IOC_WR_MODE, &mode);
  
  // The maximum speed of the SPI bus can be fetched. You'll find that, on the
  // it's 12MHz.
  int maxSpeed = 0;
  ioctl(spiDev, SPI_IOC_RD_MAX_SPEED_HZ, &maxSpeed);
  printf("Max speed: %dHz\n", maxSpeed);
  
  // In rare cases, you may find that a device expects data least significant
  //   bit first; in that case, you'll need to set that up. Writing a 0
  //   indicates MSb first; anything else indicates LSb first.
  int lsb_setting = 0;
  ioctl(spiDev, SPI_IOC_WR_LSB_FIRST, &lsb_setting);
  
  // Some devices may require more than 8 bits of data per transfer word. The
  //   SPI_IOC_WR_BITS_PER_WORD command allows you to change this; the default,
  //   0, corresponds to 8 bits per word.
  int bits_per_word = 0;
  ioctl(spiDev, SPI_IOC_WR_BITS_PER_WORD, &bits_per_word);
  
  // Okay, now that we're all set up, we can start thinking about transferring
  //   data. This, too, is done through ioctl(); in this case, there's a special
  //   struct (spi_ioc_transfer) defined in spidev.h which holds the needful
  //   info for completing a transfer. Its members are:
  //    * tx_buf - a pointer to the data to be transferred
  //    * rx_buf - a pointer to storage for received data
  //    * len - length in bytes of tx and rx buffers
  //    * speed_hz - the clock speed, in Hz
  //    * delay_usecs - delay between last bit and deassertion of CS
  //    * bits_per_word - override global word length for this transfer
  //    * cs_change - strobe chip select between transfers?
  //    * pad - ??? leave it alone.
  
  // For this example, we'll be reading the address location of an ADXL362
  //   accelerometer, then writing a value to a register and reading it back.
  //   We'll do two transfers, for ease of data handling: the first will
  //   transfer the "read register" command (0x0B) and the address (0x02), the
  //   second will dump the response back into the same buffer.
#if 0
  struct spi_ioc_transfer xfer[2];
  memset(xfer, 0, sizeof(xfer));
  char dataBuffer[2];
  char rxBuffer;
  dataBuffer[0] = 0x0B;
  dataBuffer[1] = 0x02;
  xfer[0].tx_buf = (unsigned long)dataBuffer;
  xfer[0].len = 2;
  xfer[0].speed_hz = 500000;
  xfer[0].cs_change = 0;
  xfer[0].bits_per_word = 8;
  xfer[1].rx_buf = (unsigned long)&rxBuffer;
  xfer[1].len = 1;
  xfer[1].speed_hz = 500000;
  xfer[1].cs_change = 1;
  xfer[1].bits_per_word = 8;
  res = ioctl(spiDev, SPI_IOC_MESSAGE(2), xfer);
  printf("SPI result: %d\n", res);
  printf("Device ID: 0x%x\n", rxBuffer);

#else
  struct spi_ioc_transfer xfer;
  memset(&xfer, 0, sizeof(xfer));
  char dataBuffer[3];
  char rxBuffer[3];
  dataBuffer[0] = 0x0B;
  dataBuffer[1] = 0x02;
  dataBuffer[2] = 0x00;
  xfer.tx_buf = (unsigned long)dataBuffer;
  xfer.rx_buf = (unsigned long)rxBuffer;
  xfer.len = 3;
  xfer.speed_hz = 500000;
  xfer.cs_change = 1;
  xfer.bits_per_word = 8;
  res = ioctl(spiDev, SPI_IOC_MESSAGE(1), &xfer);
  printf("SPI result: %d\n", res);
  printf("Device ID: 0x%x, 0x%x 0x%x\n", rxBuffer[2], rxBuffer[1], rxBuffer[0]);

#endif
}
void HD7279A::setPin(int CS_PIN, int CLK_PIN, int DATA_PIN) {
	csPin = CS_PIN;
	clkPin = CLK_PIN;
	dataPin = DATA_PIN;
	setPinMode();
}
HD7279A::HD7279A(int CS_PIN, int CLK_PIN, int DATA_PIN) :
		csPin(CS_PIN), clkPin(CLK_PIN), dataPin(DATA_PIN), numOfDigit(8) {
	setPinMode();
}
void setupInput()
{
    for (unsigned int input = 0; input < INPUT_MAX; input++)
        setPinMode(input_pins[input], Device::PINMODE_INPUT);
}
Beispiel #17
0
void setUnusedPinsAsOutput()
{
	setPinMode(22,OUTPUT);
	for (int16_t i =25;i<35;i++)
	setPinMode(i,OUTPUT);
}
ParkingShield::Button::Button(Device::pin_t button_pin) : repeatInterval(0), pinNumber(button_pin)
{
    setPinMode(button_pin, Device::PINMODE_INPUT);
}