// Only used if power-saving is needed void board_power_down_devices(void) { #ifdef ENVIRONMENT_SENSOR #ifdef LED1 LED1 = 0; LED2 = 0; #endif #ifdef REPORT_TYPE_LIGHT light_sleep(); #endif #ifdef REPORT_TYPE_GYRO gyro_sleep(); #endif #ifdef REPORT_TYPE_ACCEL accel_sleep(); #endif #ifdef REPORT_TYPE_HUMID humid_sleep(); #endif pir_sleep(); datalink_sleep(); #endif }
uint8 accel_read_state(int *x, int *y, int *z) { struct i2c_msg msgs[2]; signed char values[6]; uint8 addr = 0x00; /* 10-bits read value */ uint8 result = 0; accel_wakeup(); while (!accel_ready()) delay_us(1000); msgs[0].addr = ACCEL_ADDR; msgs[0].length = sizeof(byte); msgs[0].data = &addr; msgs[0].flags = 0; msgs[1].addr = ACCEL_ADDR; msgs[1].length = sizeof(values); msgs[1].data = (uint8 *)values; msgs[1].flags = I2C_MSG_READ; if (switch_state(&back_switch)) result = i2c_master_xfer(i2c, msgs, 2, 1); if (x) *x = (values[1]<<2) | (values[0]); if (y) *y = (values[3]<<2) | (values[2]); if (z) *z = (values[5]<<2) | (values[4]); accel_sleep(); return result; }