Beispiel #1
0
int atlsci_deinit()
{
    mraa_i2c_stop(i2c_context);
    i2c_context = NULL;

    return ATLSCI_SUCCESS;
}
Beispiel #2
0
void bno055_close(bno055_context dev)
{
    assert(dev != NULL);

    bno055_uninstall_isr(dev);

    if (dev->i2c)
        mraa_i2c_stop(dev->i2c);

    free(dev);
}
Beispiel #3
0
void ecezo_close(ecezo_context dev)
{
    assert(dev != NULL);

    if (dev->uart)
        mraa_uart_stop(dev->uart);
    if (dev->i2c)
        mraa_i2c_stop(dev->i2c);

    free(dev);
}
Beispiel #4
0
void kx122_close(kx122_context dev)
{
  assert(dev != NULL);
  kx122_uninstall_isr(dev,INT1);
  kx122_uninstall_isr(dev,INT2);

  if(dev->i2c){
    mraa_i2c_stop(dev->i2c);
  }
  if(dev->spi){
    mraa_spi_stop(dev->spi);
  }
  if(dev->chip_select){
    mraa_gpio_close(dev->chip_select);
  }
  free(dev);
}
Beispiel #5
0
void lcm1602_close(lcm1602_context dev)
{
    assert(dev != NULL);

    if (dev->i2c)
        mraa_i2c_stop(dev->i2c);

    if (dev->gpioRS)
        mraa_gpio_close(dev->gpioRS);
    if (dev->gpioEN)
        mraa_gpio_close(dev->gpioEN);
    if (dev->gpioD0)
        mraa_gpio_close(dev->gpioD0);
    if (dev->gpioD1)
        mraa_gpio_close(dev->gpioD1);
    if (dev->gpioD2)
        mraa_gpio_close(dev->gpioD2);
    if (dev->gpioD3)
        mraa_gpio_close(dev->gpioD3);

    free(dev);
}
Beispiel #6
0
void
lis3dh_close(lis3dh_context dev)
{
    assert(dev != NULL);

    lis3dh_uninstall_isr(dev, LIS3DH_INTERRUPT_INT1);
    lis3dh_uninstall_isr(dev, LIS3DH_INTERRUPT_INT2);

    if (dev->i2c) {
        mraa_i2c_stop(dev->i2c);
    }

    if (dev->spi) {
        mraa_spi_stop(dev->spi);
    }

    if (dev->gpioCS) {
        mraa_gpio_close(dev->gpioCS);
    }

    free(dev);
}
Beispiel #7
0
mraa_result_t
i2c_set(int bus, uint8_t device_address, uint8_t register_address, uint8_t data)
{
    mraa_result_t status = MRAA_SUCCESS;
    mraa_i2c_context i2c = mraa_i2c_init(bus);
    if (i2c == NULL) {
        return MRAA_ERROR_NO_RESOURCES;
    }
    status = mraa_i2c_address(i2c, device_address);
    if (status != MRAA_SUCCESS) {
        fprintf(stderr, "Could not set i2c device address\n");
        goto i2c_set_exit;
    }
    status = mraa_i2c_write_byte_data(i2c, data, register_address);
    if (status != MRAA_SUCCESS) {
        fprintf(stderr, "Could not write to i2c register. Status = %d\n", status);
        goto i2c_set_exit;
    }
i2c_set_exit:
    mraa_i2c_stop(i2c);
    return status;
}
Beispiel #8
0
mraa_result_t
i2c_get(int bus, uint8_t device_address, uint8_t register_address, uint8_t* data)
{
    mraa_result_t status = MRAA_SUCCESS;
    mraa_i2c_context i2c = mraa_i2c_init(bus);
    if (i2c == NULL) {
        return MRAA_ERROR_NO_RESOURCES;
    }
    status = mraa_i2c_address(i2c, device_address);
    if (status != MRAA_SUCCESS) {
        goto i2c_get_exit;
    }
    status = mraa_i2c_write_byte(i2c, register_address);
    if (status != MRAA_SUCCESS) {
        goto i2c_get_exit;
    }
    status = mraa_i2c_read(i2c, data, 1) == 1 ? MRAA_SUCCESS : MRAA_ERROR_UNSPECIFIED;
    if (status != MRAA_SUCCESS) {
        goto i2c_get_exit;
    }
i2c_get_exit:
    mraa_i2c_stop(i2c);
    return status;
}
int main()
{
	uint8_t event_type;
	int exit_code;

	mraa_init();

	//Declaring opaque pointer to the internal struct_i2c
	mraa_i2c_context i2c;
	i2c = mraa_i2c_init(0);

	//If no i2c connection is detected
	if (i2c == NULL)
	{
		system("echo $(date) No I2C connection detected. >> log.txt");
		return 0;
	}

	//Setting the i2c context address
	mraa_i2c_address(i2c, I2C_ADDRESS);

	//Reading a single byte from the i2c context.
	event_type = mraa_i2c_read_byte(i2c);

	if (event_type != -1)
	{
		if (event_type == 'A')
		{
			system("echo Entered event A >> log.txt");
		}
		else if (event_type == 'B')
		{
			system("echo Entered event B >> log.txt");
		}
		else
		{
			system("echo $(date) Wrong wake-up character received. >> log.txt");
		}

		//Waiting for one second to ensure program stability
		sleep(1);

		//Writing a single byte back to the i2c context
		mraa_i2c_write_byte(i2c, 1);

		//De-initializing the mraa_i2c_context device.
		mraa_i2c_stop(i2c);
	}

	if (event_type == 'A' || event_type == 'B')
	{
		//Shutdown intel edison if program ran successfully.
		system("shutdown -h now");
	}
	else
	{
		system("echo $(date) No data received!!!!! >> log.txt");
		//De-initialize the mraa_i2c_context device
		mraa_i2c_stop(i2c);
	}

	return 0;

}
Beispiel #10
0
 /**
  * Closes the I2c Bus used. This does not guarrantee the bus will not
  * be usable by anyone else or communicates this disconnect to any
  * slaves.
  */
 ~I2c() {
     mraa_i2c_stop(m_i2c);
 }
Beispiel #11
0
static void
i2c_close(mrb_state *mrb, void *p){
    if (p != NULL){
        mraa_i2c_stop((mraa_i2c_context)p);
    }
}