int GetNode::OpenINA231() { if (open_sensor(DEV_SENSOR_ARM, &sensor[SENSOR_ARM]) < 0) return -1; if (open_sensor(DEV_SENSOR_MEM, &sensor[SENSOR_MEM]) < 0) return -1; if (open_sensor(DEV_SENSOR_KFC, &sensor[SENSOR_KFC]) < 0) return -1; if (open_sensor(DEV_SENSOR_G3D, &sensor[SENSOR_G3D]) < 0) return -1; if (read_sensor_status(&sensor[SENSOR_ARM])) return -1; if (read_sensor_status(&sensor[SENSOR_MEM])) return -1; if (read_sensor_status(&sensor[SENSOR_KFC])) return -1; if (read_sensor_status(&sensor[SENSOR_G3D])) return -1; if (!sensor[SENSOR_ARM].data.enable) enable_sensor(&sensor[SENSOR_ARM], 1); if (!sensor[SENSOR_MEM].data.enable) enable_sensor(&sensor[SENSOR_MEM], 1); if (!sensor[SENSOR_KFC].data.enable) enable_sensor(&sensor[SENSOR_KFC], 1); if (!sensor[SENSOR_G3D].data.enable) enable_sensor(&sensor[SENSOR_G3D], 1); return 0; }
int PressSensor::setEnable(int32_t handle, int en) { int err = 0; int what = press; switch(handle){ case ID_P : what = press; break; case ID_T : what = temperature; break; } if(en) mEnabled[what]++; else mEnabled[what]--; if(mEnabled[what] < 0) mEnabled[what] = 0; if(mEnabled[press] > 0 || mEnabled[temperature] > 0) err = enable_sensor(); else err = disable_sensor(); if (!err) { update_delay(what); } ALOGD("PressSensor mEnabled %d, Temperature mEnabled %d\n",mEnabled[press],mEnabled[temperature]); return err; }
void GetNode::CloseINA231() { if (sensor[SENSOR_ARM].data.enable) enable_sensor(&sensor[SENSOR_ARM], 0); if (sensor[SENSOR_MEM].data.enable) enable_sensor(&sensor[SENSOR_MEM], 0); if (sensor[SENSOR_KFC].data.enable) enable_sensor(&sensor[SENSOR_KFC], 0); if (sensor[SENSOR_G3D].data.enable) enable_sensor(&sensor[SENSOR_G3D], 0); close_sensor(&sensor[SENSOR_ARM]); close_sensor(&sensor[SENSOR_MEM]); close_sensor(&sensor[SENSOR_KFC]); close_sensor(&sensor[SENSOR_G3D]); }
void start_r3d2(void) { if (!is_motor_powered()) { start_motor(); } enable_sensor(); }
int main() { int dev_fd = open(DEVICE_NAME, O_RDONLY); if (dev_fd >= 0) { if (!get_status(dev_fd)) enable_sensor(dev_fd, 1); } else { printf("Light sensor swith has not found.\n"); } double sum_light = 0; int count_light = 0; char * device = get_device("lightsensor-level"); if (device) { printf("devices: %s\n", device); char one_dev[128] = "/dev/input/"; char * read_pos = device; while (read_pos < (device + strlen(device))) { char * end_pos = read_pos; while ( *end_pos != 0 && *end_pos != ' ') end_pos ++; strncpy(one_dev + strlen("/dev/input/"), read_pos, min_value(127, end_pos - read_pos)); one_dev[strlen("/dev/input/") + min_value(127, end_pos - read_pos) - 1] = 0; read_pos = end_pos + 1; int input_fd = open(one_dev, O_RDONLY); if (input_fd >= 0) { printf("Try use:'%s'\n", one_dev); sum_light += get_abs_value(input_fd); count_light ++; } else { printf("Cant access to '%s'\n", one_dev); } } free(device); } else { printf("Light sensor has not found.\n"); } int cam_value = v4l_cam_value("/dev/video0"); if (cam_value >= 0) { printf("v4l value = %d\n", cam_value); sum_light += cam_value; count_light ++; } if (count_light) { sum_light = sum_light / count_light; } printf("Light value = %d lux\n", cam_value); update_lights(sum_light); // flashlight // /sys/class/leds/flashlight/brightness // 0 - none // 1 - bottom // 2 - top // 3 - both }
/*---------------------------------------------------------------------------*/ static void initialise(void *not_used) { /* Configure the accelerometer range */ if((elements & MPU_9250_SENSOR_TYPE_ACC) != 0) { acc_set_range(MPU_9250_SENSOR_ACC_RANGE); } enable_sensor(elements & MPU_9250_SENSOR_TYPE_ALL); ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, notify_ready, NULL); }
int AccelSensor::setEnable(int32_t handle, int en) { int err = 0; //ALOGD("enable: handle: %ld, en: %d", handle, en); if(handle != ID_A && handle != ID_O && handle != ID_M) return -1; if(en) mUser++; else{ mUser--; if(mUser < 0) mUser = 0; } if(mUser > 0) err = enable_sensor(); else err = disable_sensor(); if(handle == ID_A ) { if(en) mEnabled++; else mEnabled--; if(mEnabled < 0) mEnabled = 0; } //update_delay(); #ifdef DEBUG_SENSOR ALOGD("AccelSensor enable %d ,usercount %d, handle %d ,mEnabled %d, err %d", en, mUser, handle, mEnabled, err); #endif return 0; }
uint8_t enable_external_temperature_sensor_B() { return enable_sensor(external_temperature_sensor_B); }
// ENABLE TEMPERATURE uint8_t enable_internal_temperature_sensor() { return enable_sensor(internal_temperature_sensor); }
uint8_t enable_light_sensor_B() { return enable_sensor(light_sensor_B); }
// ENABLE LIGHT uint8_t enable_light_sensor_A() { return enable_sensor(light_sensor_A); }
void init_sensor(void) { int1_init(); enable_sensor(); }