SINT send_nxtcam_command(U8 port_id, U8 command) { while (i2c_busy(port_id) != 0) ; nxtcambuffer[0] = command; /* write Single shot command */ SINT ret = i2c_start_transaction(port_id, ADDRESS, 0x41, 1, nxtcambuffer, 1, 1); return ret; }
int nxtrike_get_sonic_sensor(void) { return ev3_ultrasonic_sensor_get_distance(SONIC_SENSOR); #if 0 U8 distance; if (!i2c_busy(SONIC_SENSOR)) { i2c_start_transaction(SONIC_SENSOR, 1, 0x42, 1, &distance, 1, 0); return (int)distance; } return NXTRIKE_ERROR; #endif }
/* * This is an implementation example of I2C sensor data acquisition for * mindsensor acceleration sensor. mindsensor acceleration sensor returns * tilt data and acceleration data in three axes. * * This API implementation for I2C communication might be different from * I2C sensor communication examples in other NXT programming languages. * Others use a wait until data transaction is finished after sending a request. * However, it might not be acceptable for real-time control application. So we * introduce one sampling delay to avoid waiting for the completion of the data acqusition. */ void get_mindsensor_accel_sensor(U8 port_id, S16 *buf) { int i,j; static S16 tilt_state[3]; static S16 accel_state[3]; static U8 data[9] = {0,0,0,0,0,0,0,0,0}; /* * Data spec. of mindsensor acceleration sensor * * 0x42 data[0]: X axis Tilt data * 0x43 data[1]: Y axis Tilt data * 0x44 data[2]: Z axis Tilt data * 0x45 data[3]: X axis Accel LSB * 0x46 data[4]: X axis Accel MSB * 0x47 data[5]: Y axis Accel LSB * 0x48 data[6]: Y axis Accel MSB * 0x49 data[7]: Z axis Accel LSB * 0x4A data[8]: Z axis Accel MSB */ if (i2c_busy(port_id) == 0) /* check the status of I2C comm. */ { j=0; for (i=0; i<8; i++) { if (i<3) { tilt_state[i] = (S16)data[i]; } else { accel_state[j++] = ((S16)data[i+1]<<8) + (S16)data[i]; i++; } } /* i2c_start_transaction just triggers an I2C transaction, * actual data transaction between ARM7 and an Acceleration * Sensor is done by an ISR after this, so there is one execution cycle * delay for consistent data acquistion */ i2c_start_transaction(port_id,1,0x42,1,data,9,0); } for (i=0; i<3; i++) { buf[i] = tilt_state[i]; buf[i+3] = accel_state[i]; } }
int request(U8 port_id) { if (i2c_busy(port_id) == 0) /* check the status of I2C comm. */ { /* i2c_start_transaction just triggers an I2C transaction, * actual data transaction between ARM7 and an NxtCam is done * by an ISR after this, so there is one execution cycle * delay for consistent data acquistion */ SINT ret = i2c_start_transaction(port_id, ADDRESS, 0x42, 1, nxtcamdata, 41, 0); if (ret == 0) nxtcamtransaccounter++; } return nxtcamtransaccounter; }