예제 #1
1
파일: ad8232.c 프로젝트: g-vidal/upm
upm_result_t ad8232_get_value(ad8232_context dev, int* value) {
    int reading = 0;

    if (mraa_gpio_read(dev->gpio_lo_minus) ||
        mraa_gpio_read(dev->gpio_lo_plus)) {
        reading = 0;
    }
    else {
        reading = mraa_aio_read(dev->aio);
    }

    *value = reading;

    return UPM_SUCCESS;
}
예제 #2
0
파일: pwm.c 프로젝트: nage-son/pi-test
void get_data(mraa_gpio_context gpio, int* readData) {
    mraa_gpio_dir(gpio, MRAA_GPIO_OUT);
    mraa_gpio_write(gpio, 1);
    mraa_gpio_write(gpio, 0);

    usleep(18000);

    mraa_gpio_write(gpio, 1);

    usleep(30);

    mraa_gpio_dir(gpio, MRAA_GPIO_IN);

    *readData = mraa_gpio_read(gpio);

    usleep(80);

    printf("first readData >>> %d\n", *readData);

    *readData = mraa_gpio_read(gpio);

    usleep(80);

    printf("second readData >>> %d\n", *readData);

    int i;

    for (i = 0; i < 40; i++) {
        *readData = mraa_gpio_read(gpio);

        printf("[%d] >>> %d\n", i, *readData);
    }
}
예제 #3
0
int main(int argc, char **argv)  
{  
	int i, j, output, outputArray[n_reads], i_reads, tmp;
 
    mraa_gpio_context clk = mraa_gpio_init(4); 
    mraa_gpio_context dat = mraa_gpio_init(2);
    mraa_gpio_dir(clk, MRAA_GPIO_OUT); 
    mraa_gpio_dir(dat, MRAA_GPIO_IN); 
  
    mraa_gpio_use_mmaped(clk, 1);

    i_reads = n_reads;

    while (i_reads > 0) { 

        while(mraa_gpio_read(dat)) {}

    	output = 0; 
        for(i = 0; i < 24; i++) {
        	mraa_gpio_write(clk, 1);
        	fuckDelay(2000);
        	output |= (mraa_gpio_read(dat)<< (23-i));
        	mraa_gpio_write(clk, 0);
        	fuckDelay(2000);
        }
        mraa_gpio_write(clk, 1);
        fuckDelay(2000);
        mraa_gpio_write(clk, 0);

        if(output < 16777215) {
        	//fprintf(stdout, "%d\n", output);
            outputArray[i_reads-1] = output;
            i_reads--; // decrement only if the valid read
        }
    } 


    //sorting the array
    for(i = 1; i < n_reads; i++){
        j = i;
        while ((j > 0) && (outputArray[j-1]>outputArray[j])) {
            tmp = outputArray[j];
            outputArray[j] = outputArray[j-1];
            outputArray[j-1] = tmp;
            j--;
        }
    } 

    fprintf(stdout, "%d\n", outputArray[5]);

} 
예제 #4
0
파일: main.c 프로젝트: TerrenceC/Pet-Camera
int main(int argc, char** argv)
{

    mraa_gpio_context ir_gpio = NULL;

    //set ir io as input
    ir_gpio = mraa_gpio_init(7);
    if (ir_gpio == NULL) {
        fprintf(stdout, "Could not initilaize ir_gpio\n");
        return 1;
    }
    mraa_gpio_dir(ir_gpio, MRAA_GPIO_IN);

    //create take photo thread
    pthread_t t;
    pthread_create(&t,NULL,take_photo_thread,NULL);
    //pthread_join(t,NULL);


    //main loop
    for (;;) {
        if( ir_state != mraa_gpio_read(ir_gpio)) {
            ir_state = !ir_state;
            printf("%d\n",ir_state);
            sleep(1);
        }
    }

    return 0;
}
예제 #5
0
upm_result_t a110x_magnet_detected(a110x_context dev, bool* res){
    int val = mraa_gpio_read(dev->gpio);
    if (val == 0)
        *res = false;
    else
        *res = true;
    return UPM_SUCCESS;
}
예제 #6
0
int
main(int argc, char** argv)
{
    mraa_platform_t platform = mraa_get_platform_type();
    mraa_gpio_context gpio, gpio_in = NULL;
    const char* board_name = mraa_get_platform_name();
    int ledstate = 0;

    switch (platform) {
        case MRAA_INTEL_GALILEO_GEN1:
            gpio = mraa_gpio_init_raw(3);
            break;
        case MRAA_INTEL_MINNOWBOARD_MAX:
            // there is no onboard LED that we can flash on the minnowboard max
            // but on the calamari lure pin 21 is an LED. If you don't have the
            // lure put an LED on pin 21
            gpio = mraa_gpio_init(21);
            break;
        case MRAA_INTEL_JOULE_EXPANSION:
            gpio = mraa_gpio_init(101);
            break;
        default:
            gpio = mraa_gpio_init(13);
    }

    fprintf(stdout, "Welcome to libmraa\n Version: %s\n Running on %s\n", mraa_get_version(), board_name);


    if (gpio == NULL) {
        fprintf(stdout, "Could not initilaize gpio\n");
        return 1;
    }

    // on platforms with physical button use gpio_in
    if (platform == MRAA_INTEL_MINNOWBOARD_MAX) {
        gpio_in = mraa_gpio_init(14);
        if (gpio_in != NULL) {
            mraa_gpio_dir(gpio_in, MRAA_GPIO_IN);
            // S1 on minnowboardmax's calamari lure maps to pin 14, SW1 != S1
            fprintf(stdout, "Press and hold S1 to stop, Press SW1 to shutdown!\n");
        }
    }

    mraa_gpio_dir(gpio, MRAA_GPIO_OUT);

    for (;;) {
        if (gpio_in != NULL && mraa_gpio_read(gpio_in) == 0) {
            return 0;
        }
        ledstate = !ledstate;
        mraa_gpio_write(gpio, !ledstate);
        sleep(1);
    }

    return 0;
}
예제 #7
0
FskErr mraaDigitalRead(FskPinDigital pin, Boolean *value)
{
	mraaDigital md = (mraaDigital)pin;
	int result;

	result = mraa_gpio_read(md->context);
	if (-1 == result) return kFskErrOperationFailed;
	*value = result != 0;
	return kFskErrNone;
}
void tb6612::getShortBrake(bool* brakeA, bool* brakeB)
{
  if ( (mraa_gpio_read(_A1) == 1) && (mraa_gpio_read(_A2) == 1) )
  {
    *brakeA = true;
  }
  else
  {
    *brakeA = false;
  }
  if ( (mraa_gpio_read(_B1) == 1) && (mraa_gpio_read(_B2) == 1) )
  {
    *brakeB = true;
  }
  else
  {
    *brakeB = false;
  }
}
예제 #9
0
/*
  Checks the RDYN line and runs the SPI transfer if required.
*/
static void m_aci_event_check(void)
{
  hal_aci_data_t data_to_send;
  hal_aci_data_t received_data;

  // No room to store incoming messages
  if (aci_queue_is_full(&aci_rx_q))
  {
    return;
  }

  // If the ready line is disabled and we have pending messages outgoing we enable the request line
  if (HIGH == mraa_gpio_read (a_pins_local_ptr->m_rdy_ctx))
  // if (HIGH == digitalRead(a_pins_local_ptr->rdyn_pin))
  {
    if (!aci_queue_is_empty(&aci_tx_q))
    {
      m_aci_reqn_enable();
    }

    return;
  }

  // Receive from queue
  if (!aci_queue_dequeue(&aci_tx_q, &data_to_send))
  {
    /* queue was empty, nothing to send */
    data_to_send.status_byte = 0;
    data_to_send.buffer[0] = 0;
  }

  // Receive and/or transmit data
  m_aci_spi_transfer(&data_to_send, &received_data);

  /* If there are messages to transmit, and we can store the reply, we request a new transfer */
  if (!aci_queue_is_full(&aci_rx_q) && !aci_queue_is_empty(&aci_tx_q))
  {
    m_aci_reqn_enable();
  }

  // Check if we received data
  if (received_data.buffer[0] > 0)
  {
    if (!aci_queue_enqueue(&aci_rx_q, &received_data))
    {
      /* Receive Buffer full.
         Should never happen.
         Spin in a while loop.
      */
      while(1);
    }
  }

  return;
}
bool tb6612::getStandby()
{
  if (mraa_gpio_read(_standbyPin) == 0)
  {
    return true;
  }
  else
  {
    return false;
  }
}
예제 #11
0
upm_result_t mma7361_freefall(const mma7361_context dev, bool *freefall)
{
  assert(dev != NULL);

  if (!dev->gpio_freefall)
    return UPM_ERROR_NO_RESOURCES;

  *freefall = mraa_gpio_read(dev->gpio_freefall) ? true : false;

  return UPM_SUCCESS;
}
예제 #12
0
파일: lab4b.c 프로젝트: NaimAyat/UCLA_CS111
void * checkButton() {
	for (;;) {
		if (mraa_gpio_read(buttonSensor)) {
			char tarr[50];
			convertTime(tarr);
			if (logOpt)
				fprintf(myFile, "%s %s\n", tarr, "SHUTDOWN");
			exit(0);
		}
	}
	return 0;
}
예제 #13
0
파일: swspi.c 프로젝트: achilikin/edradio
uint16_t sw_spi_send_word(mraa_spi_sw_context spi, uint16_t data)
{
	uint16_t rx = 0;

	for(uint16_t i = 0x8000; i; i >>= 1) {
		mraa_gpio_write(spi->sdi, data & i);
		mraa_gpio_write(spi->sck, 1);
		rx = (rx << 1 ) | mraa_gpio_read(spi->sdo);
		mraa_gpio_write(spi->sck, 0);
	}

	return rx;
}
예제 #14
0
int
main(int argc, char **argv)
{
    mraa_platform_t platform = mraa_get_platform_type();
    mraa_gpio_context gpio, gpio_in = NULL;
    char* board_name = mraa_get_platform_name();
    int ledstate = 0;

    switch (platform) {
        case MRAA_INTEL_GALILEO_GEN1:
            gpio = mraa_gpio_init_raw(3);
            break;
        case MRAA_INTEL_MINNOWBOARD_MAX:
            gpio = mraa_gpio_init(21);
            break;
        default:
            gpio = mraa_gpio_init(13);
    }

    fprintf(stdout, "Welcome to libmraa\n Version: %s\n Running on %s\n",
        mraa_get_version(), board_name);


    if (gpio == NULL) {
        fprintf(stdout, "Could not initilaize gpio\n");
        return 1;
    }

    // on platforms with physical button use gpio_in
    if (platform == MRAA_INTEL_MINNOWBOARD_MAX) {
        gpio_in = mraa_gpio_init(14);
	if (gpio_in != NULL) {
            mraa_gpio_dir(gpio_in, MRAA_GPIO_IN);
            fprintf(stdout, "Press and hold S1 to stop\n");
        }
    }

    mraa_gpio_dir(gpio, MRAA_GPIO_OUT);

    for (;;) {
        if (gpio_in != NULL && mraa_gpio_read(gpio_in) == 0) {
            return 0;
        }
        ledstate = !ledstate;
        mraa_gpio_write(gpio, !ledstate);
        sleep(1);
    }

    return 0;
}
예제 #15
0
double get_distance(mraa_gpio_context trigger, mraa_gpio_context echo)
{
    struct timeval trigTime, startTime, endTime;
    double time_taken;
    double distance;

    gettimeofday(&trigTime, NULL);
    gettimeofday(&startTime, NULL);
    gettimeofday(&endTime, NULL);
    
    mraa_gpio_write(trigger, 0);
    usleep(5);
    mraa_gpio_write(trigger, 1);
    usleep(11);
    mraa_gpio_write(trigger, 0);
    while (mraa_gpio_read(echo) == 0)
    {
        gettimeofday(&startTime, NULL);
        if (1000000.0 * (startTime.tv_sec - trigTime.tv_sec) + startTime.tv_usec - trigTime.tv_usec >= 1500000.0)
            return -1.;
    }

    while (mraa_gpio_read(echo) == 1)
    {
        gettimeofday(&endTime, NULL);
        if (1000000.0 * (endTime.tv_sec - startTime.tv_sec) + endTime.tv_usec - startTime.tv_usec >= 500000.0)
            return -1.;
    }
    
    time_taken = 1000000.0 * (endTime.tv_sec - startTime.tv_sec) + endTime.tv_usec - startTime.tv_usec;
    distance = (time_taken + 0.00) / 58.82;
    while (time_taken < 30000 && time_taken > 0){
            gettimeofday(&endTime, NULL);
            time_taken = 1000000.0 * (endTime.tv_sec - startTime.tv_sec) + endTime.tv_usec - startTime.tv_usec;
    }
    return distance;
}
예제 #16
0
void interrupt_in(void *arg)
{
    mraa_gpio_context dev = (mraa_gpio_context)arg;
    if(mutex == 0){
        mutex = 1;
       system("clear"); 
       if(mraa_gpio_read(dev) == 1){
            mraa_gpio_write(out, 1);
            printf("Released\r\n");
        }else{
            mraa_gpio_write(out, 0);
            printf("Pressed\r\n");
        }
        mutex = 0;
    }
}
예제 #17
0
// Mimicking Arduino's pulseIn function
// return how long it takes a pin to go from HIGH to LOW or LOW to HIGH
static uint32_t ppd42ns_pulse_in(const ppd42ns_context dev,
                                 bool high_low_value)
{
    assert(dev != NULL);

    // we run for no more than 1 second at a time
    upm_clock_t max_time;
    upm_clock_t pulse_time;
    uint32_t total_pulse_time = 0;

    upm_clock_init(&max_time);
    bool pin_level;
    bool is_timing = false;

    do {
        pin_level = (bool)mraa_gpio_read(dev->gpio);

        if (!is_timing && pin_level == high_low_value)
        {
            // level is desired level, but not currently timing
            upm_clock_init(&pulse_time);
            is_timing = true;
        }
        else if (is_timing && pin_level != high_low_value)
        {
            // we started timing, but level changed
            total_pulse_time += upm_elapsed_us(&pulse_time);
            is_timing = false;
        }
        else
        {
            // not timing and/or level is not equal to desired level
            // so we "wait".
            upm_delay_us(10);
        }
    } while (upm_elapsed_ms(&max_time) < 1000); // 1 second

    if (is_timing)
    {
        // if we were still timing when the loop expired, add the
        // accumulated time.
        total_pulse_time += upm_elapsed_us(&pulse_time);
    }

    return total_pulse_time;
}
예제 #18
0
파일: swspi.c 프로젝트: achilikin/edradio
uint8_t *sw_spi_send_data(mraa_spi_sw_context spi, mraa_gpio_context ss, uint8_t *data, unsigned len)
{
	mraa_gpio_write(ss, 0);
	for(unsigned i = 0; i < len; i++) {
		uint8_t tr = data[i];
		for(uint8_t mask = 0x80; mask; mask >>= 1) {
			mraa_gpio_write(spi->sdi, tr & mask);
			tr &= ~mask;
			mraa_gpio_write(spi->sck, 1);
			if (mraa_gpio_read(spi->sdo))
				tr |= mask;
			mraa_gpio_write(spi->sck, 0);
		}
		data[i] = tr;
	}
	mraa_gpio_write(ss, 1);

	return data;
}
예제 #19
0
void edge (void * args) {
   if(!blockInterrupt){
	usleep(700);
	mraa_gpio_context* dev = (mraa_gpio_context*) args;
	if (mraa_gpio_read(*dev) == 1){
	    fprintf(stdout, "Wrote a One to buffer spot %d\n", bufSpot);
	    buf[bufSpot] = 1;
	    if (bufSpot >= 15)
		bufSpot = 0;
	    else
		bufSpot++;
	}
	else{
	    fprintf(stdout, "Self Shot", bufSpot);
            buf[bufSpot] = 0;       
	}
	if (bufSpot%8 == 0)
		bufferLoaded = true;
   }
}
int main(int ac, char **av)
{
    int iopin;
    mraa_result_t result;
    mraa_gpio_context gpio;
    int value;

    mraa_init();
    
    if (ac != 3) {
        fprintf(stderr, "Usage: %s pin_number\n"        \
               "\nExample: %s 7 -> Read pin 7\n"
               , av[0], av[0]);
        return -1;
    }

    iopin = atoi(av[1]);

    /* Initialisation of pin */
    gpio = mraa_gpio_init(iopin);
    if (gpio == NULL) {
        fprintf(stderr, "[-] Initialisation of pin %d failed. Is this pin exist on your platform?\n", iopin);
        return -1;
    }

    /* Set GPIO direction */
    result = mraa_gpio_dir(gpio, MRAA_GPIO_IN);
    if (result != MRAA_SUCCESS) {
        mraa_result_print(result);
        return -1;
    }

    value = mraa_gpio_read(gpio);
    if (result != MRAA_SUCCESS)
        mraa_result_print(result);
    printf("%d", value);
    return 0;
}
예제 #21
0
int readButton(void) {
    return (mraa_gpio_read(btnPin));
}
예제 #22
0
파일: gpio.hpp 프로젝트: jontrulson/mraa
 /**
  * Read value from Gpio
  *
  * @return Gpio value
  */
 int
 read()
 {
     return mraa_gpio_read(m_gpio);
 }
int main(int argc, char *argv[]) {
    
    // Initialization
    volatile int irSig = 0 ;
    // values stores the number of 0's or the number of 1's
    unsigned int values[100];
    
    volatile unsigned int i = 0, j = 0, k = 0;
    volatile unsigned int num_values = 0;
    volatile unsigned int l = 0;
    volatile unsigned int received_bit_count = 0;
    int bit = -1;
    int all_received_bits[25];
    int preamble_relaxed_detection ;
    
    mraa_gpio_context gpio;
    gpio = mraa_gpio_init(4);
    mraa_gpio_dir(gpio, MRAA_GPIO_IN);
    
    
    // Part 1: Raw Data Sampling
    // Detect the value received as either 1 or 0
    // Store in raw_data[]
    printf("Part 1: Raw Data Sampling\n");
    printf("Beginning Sample Collection\n");
    // raw_data stores 0 or 1 dep on what was received
    int raw_data[TOTAL_SAMPLES] ;
    unsigned int samples_remaining = TOTAL_SAMPLES;
    i = 0;
    while(samples_remaining > 0 ) {
        irSig = mraa_gpio_read(gpio);
        raw_data[i] = irSig ;
        printf("%d", raw_data[i]);
        for (j = 0 ; j < SAMPLING_RATE ; j++);
        i++;
        samples_remaining--;
    }//end while loop
    i = 0;
    
    
    printf("\nSample Collection Complete\n");
    
    // Part 2: Consolidating the bits
    // Count the sequence of 1 or 0 received in a row
    // Store in values[]
    
    printf("\nPart 2: Consolidating the bits");
    unsigned int counting_high_or_low = raw_data[0];
    unsigned int high_duration = 0;
    unsigned int low_duration = 0;
    
    printf("\nThe first bit we received was raw_data[0] = %u\n", raw_data[0]);
    printf("Therefore we are counting a stream of digits of: %u", counting_high_or_low);
    if (raw_data[0] == 0) {
        low_duration = 1;
    }
    else if (raw_data[0] == 1) {
        high_duration = 1;
    }
    int count = 1;
    while( count < TOTAL_SAMPLES )
    {
        //printf("count = %d\n", count);
        //printf("raw_data[count] = %d\n", raw_data[count]);
        
        if ( raw_data[count] == 0 )
        {
            if (counting_high_or_low == 1)
            {
                counting_high_or_low = 0;
                low_duration = 1;
                values[i] = high_duration;
                i++;
            }
            else
            {
                low_duration++;
                //continue;
            }
        }
        else if (raw_data[count] == 1)
        {
            if ( counting_high_or_low == 0 )
            {
                counting_high_or_low = 1;
                high_duration = 1;
                values[i] = low_duration;
                i++;
            }
            else
            {
                high_duration++;
                //continue;
            }
        }
        else {
            printf("\nraw_data[count] error\n");
            printf("count = %d\n", count);
            printf("raw_data[count] = %d\n", raw_data[count]);
            
        }
        count++;
    }/*end of while loop */
    
    printf("\nNow we print the values[] array, which stores the result of what we counted.\n");
    num_values = i ;
    printf("num_values = %u\n", num_values);
    for (i = 0 ; i < num_values; i++ ) {
        printf("%u \n", values[i]);
    }
    
    // Part 3: Bit Decoding FSM
    // Search values[] for sequences of preamble and 4 bits
    // Store in all_received_bits[]
    i = 0;
    j = 0;
    k = 0;
    unsigned int fsm_state = 0 ;
    unsigned int preamble_found = 1 ;
    printf("\nPart 3: Bit Decoding FSM\n");
    printf("Begin Decoding\n");
    
    while (i < num_values)
    {
        printf("Iteration %u out of %u\n", i, num_values) ;
        preamble_relaxed_detection = 0 ;
        for (j = i; j < ( i + PREAMBLE_DURATION*2 ); j++)
        {
            printf("Inspecting j = %u with the if statement\n", values[j]);
            
            if (values[j] < LOWERBOUND_PREAMBLE || values[j] > UPPERBOUND_PREAMBLE)
            {
                if (values[j] > LOWERBOUND_PREAMBLE - 5 && values[j] < UPPERBOUND_PREAMBLE + 5 )
                {
                    if ( preamble_relaxed_detection < PREAMBLE_RELAXED_DETECTION_THRESHOLD )
                    {
                        preamble_relaxed_detection++ ;
                        continue ;
                    }
                }
                printf("Did not find preamble \n" );
                preamble_found = 0;
                break;
            }
        }
        if (preamble_found == 1)
        {
            printf("We found the preamble, now we need to skip PREAMBLE_DURATION * 2 values.\n");
            for(l = 0; l < PREAMBLE_DURATION * 2; l ++) {
                printf("Skipping i = %u, values[i] = %u\n", i, values[i]);
                i++;
            }
            printf("Now we are at the first of the 8 values for the 4 bits.\n");
            for(k = 1 ; k <= 4 ; k++)
            {
                printf("Constituents of the bit %u %u \n ", values[i],values[i+1]);
                
                bit = -1;
                
                if( values[i]>=LOWERBOUND_HIGHVALUE && values[i] <= UPPERBOUND_HIGHVALUE && values[i+1] >=LOWERBOUND_LOWVALUE && values[i+1] <= UPPERBOUND_LOWVALUE )
                {
                    bit = 1;
                }
                
                if( values[i]>=LOWERBOUND_LOWVALUE && values[i] <= UPPERBOUND_LOWVALUE && values[i+1] >=LOWERBOUND_HIGHVALUE && values[i+1] <= UPPERBOUND_HIGHVALUE)
                {
                    bit = 0;
                }
                
                i += 2;
                printf("bit = %d\n", bit);
                
                all_received_bits[received_bit_count] = bit;
                received_bit_count++;
            }
            printf("\n");
        }
        else {
            i++;
            preamble_found = 1;
        }
    }
    
    printf("FSM Complete\n\n\n\n");
    int messages = received_bit_count/4;
    printf("Identified %d bits\n", received_bit_count);
    printf("This corresponds to %d messages\n", messages);
    
    
    printf("\nNow we print the all_received_bits[] array.\n");
    num_values = i ;
    for (i = 0 ; i < received_bit_count; i++ ) {
        printf("all_received_bits[%u] = %d\n", i, all_received_bits[i]);
    }
    
    
    // Part 4: Bit Verifier
    // Inspect all_received_bits[]
    // Store in TEMP
    printf("\nPart 4: Bit Verifier\n");
    printf("Begin Bit Inspection\n");
    i = 0;
    j = 0;
    
    int valid_sequence = 1;
    int location[6] = {0, 0, 0, 0, 0, 0};
    int messages_to_process = 0;
    if (messages < 6) {
        messages_to_process = messages;
    }
    else {
        messages_to_process = 6;
    }
    // we process at most 6 messages, at minimum 0
    
    for(i = 0; i < messages_to_process * 4; i += 4) {
        printf("\nReceiving EdisonID/LEDID Unit\n");
        for (j = 0; j < 4; j++) {
            printf("message[%u] = %d\n", j, all_received_bits[i+j]);
            if (all_received_bits[i+j] == -1)
            {
                valid_sequence = 0;
            }
        }
        if (valid_sequence == 1) {
            location[i/4] =  all_received_bits[i+3]* 1 + all_received_bits[i+2]* 2 + all_received_bits[i+1] * 4 + all_received_bits[i+0] * 8;
            // locations go from 1-16
            printf("\ni = %d, location[i] is : %d", i, location[i/4]);
            location[i/4] = location[i/4] + 1;
            printf("\nReceived a location: %d\n", location[i/4]);
        }
        else {
            printf("Received an invalid sequence\n");
            valid_sequence = 1;
        }
    }
    
    printf("Done Bit Inspection\n");
    if (messages_to_process > 0) {
        printf("Messages Correspond to Locations:\n");
        for (i = 0 ; i < messages_to_process; i++ ) {
            printf("%d \n", location[i]);
        }
        
        // Part 5: Valid Sequence Verifier
        // if we find a total of 3 matching
        // bit sequences (out of 5), return
        printf("\nPart 5: Valid Sequence Verifier\n");
        printf("Begin Counting Matching Bits\n");
        int match_counter = 0;
        for(i = 0; i < messages_to_process; i++) {
            for (j = 0; j < 4; j++) {
                if (location[i] == location[j]) {
                    match_counter++;
                }
                if (match_counter >= LOCATION_DETECTION_THRESHOLD && location[i] != 0 ) {
                    printf("Done Counting Matching Bits\n");
                    printf("\nReturning location[i] = %d\n", location[i]);
                    return location[i];
                }
            }
            match_counter = 0;
        }
    }
    printf("\nReturning Zero Location");
    printf("Not Enough Bits Matching, Return 0\n");	
    return 0;
}//end main
예제 #24
0
int inputPin( mraa_gpio_context gpio ) {

	return mraa_gpio_read( gpio );

}
예제 #25
0
bool bouton_touch::get_val(){
  valeur = (bool)mraa_gpio_read(gpio_in);
  return valeur;
}
int main(int argc, char** argv)
{
    mraa_platform_t platform;                /* Type of platform we are on */
    mraa_gpio_context gpio_led = NULL;       /* LED GPIO descriptor */
    mraa_gpio_context gpio_button = NULL;    /* BUTTON GPIO descriptor */
    mraa_aio_context adc_a0 = NULL;          /* Analog-Digital descriptor */
    uint32_t adc_val;                       /* ADC value */
    float delay;                             /* Delay between blinks */
    int ledstate = 0;                        /* LED state, 0=off, 1=on */


    /*
     * Print banner.
     */
     platform = mraa_get_platform_type();
     fprintf(stdout, "MRAA C Demonstration\n");
     fprintf(stdout, "LIBMRAA Version: %s\n", mraa_get_version());
     fprintf(stdout, "Board: %s\n", mraa_get_platform_name());

     /*
      * Check that we are running on the correct board
      */
     platform = mraa_get_platform_type();
     if (platform != MRAA_INTEL_GALILEO_GEN2)
        {
        fprintf(stderr, "ERROR: This program is for a Intel Galileo Gen 2 Board\n");
        exit (-1);
        }

    /*
     * Initialize the LED gpio pin and set it as an output
     */
    gpio_led = mraa_gpio_init(LED);
    if (gpio_led == NULL)
        {
        fprintf(stderr, "Could not initialize LED gpio\n");
        exit (-1);
        }
    mraa_gpio_dir(gpio_led, MRAA_GPIO_OUT);

    /*
     * Initialize the Button gpio pin and set it as an input
     */
     gpio_button = mraa_gpio_init(BUTTON);
     if (gpio_button == NULL)
         {
         fprintf(stderr, "Could not initialize BUTTON gpio\n");
         }
    mraa_gpio_dir(gpio_button, MRAA_GPIO_IN);

    /*
     * Initialize the Analog-Digital converter channel 0
     */

    adc_a0 = mraa_aio_init(0);
    if (adc_a0 == NULL)
        {
        fprintf(stderr, "Failed to initalize ADC channel A0\n");
        exit (-1);
        }

    printf("Vary the rate of blink by turning the poteniometer on A0\n");
    printf("Exit the program by pressing the button on D%d\n\n", BUTTON);

    /*
     * Run the loop until the BUTTON is held down.
     * Each time through the loop, read the potentiometer on A0 and
     * adjust the blink rate.
     */
    while (1)
        {
        if (mraa_gpio_read(gpio_button) == 1)
            break;

        if (adc_a0 != NULL)
            {
            adc_val = mraa_aio_read(adc_a0);
            /* fprintf(stdout, "ADC A0 = %d\n", adc_val); */
            if (adc_val != 0)
                delay = 1000000 * ((float)adc_val/1024);
            else
                delay = 1000000 * (1/1024);
            }

        ledstate = !ledstate;

        mraa_gpio_write(gpio_led, ledstate);

        usleep((long)delay);
        }

    /*
     * Clean up and exit
     */
    (void)mraa_gpio_close(gpio_led);
    (void)mraa_gpio_close(gpio_button);
    (void)mraa_aio_close(adc_a0);

    exit(0);
}