int TaosProximity::setInitialState() {
    struct input_absinfo absinfo;
    if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_PROXIMITY), &absinfo)) {
        mPendingEvents.distance = indexToValue(absinfo.value);
    }
    return 0;
}
int TaosProximity::readEvents(sensors_event_t* data, int count)
{
    if (count < 1)
        return -EINVAL;

    ssize_t n = mInputReader.fill(data_fd);
    if (n < 0)
        return n;

    int numEventReceived = 0;
    input_event const* event;
    while (count && mInputReader.readEvent(&event)) {
        int type = event->type;
        if (type == EV_ABS) {
            if (event->code == EVENT_TYPE_PROXIMITY) {
                LOGD_IF(DEBUG,"Prox value=%i",event->value);
                mPendingEvents.distance = indexToValue(event->value);
            }

        } else if (type == EV_SYN) {
            int64_t time = timevalToNano(event->time);
            if (mEnabled){
                *data++ = mPendingEvents;
                mPendingEvents.timestamp=time;
                count--;
                numEventReceived++;
            }
        } else {
            LOGE("TaosSensor: unknown event (type=%d, code=%d)",type, event->code);
        }
        mInputReader.next();
    }
    return numEventReceived;
}
int LightSensor::setInitialState() {
    struct input_absinfo absinfo;
    if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_LIGHT), &absinfo)) {
        mPendingEvent.light = indexToValue(absinfo.value);
        mHasPendingEvent = true;
    }
    return 0;
}
int ProximitySensor::readEvents(sensors_event_t* data, int count)
{
    if (count < 1)
        return -EINVAL;

    if (mHasPendingEvent) {
        mHasPendingEvent = false;
        mPendingEvent.timestamp = getTimestamp();
        *data = mPendingEvent;
        return mEnabled ? 1 : 0;
    }

    ssize_t n = mInputReader.fill(data_fd);
    if (n < 0)
        return n;

    int numEventReceived = 0;
    input_event const* event;

    while (count && mInputReader.readEvent(&event)) {
        int type = event->type;
        if (type == EV_ABS) {
            if (event->code == EVENT_TYPE_PROXIMITY) {
                if (event->value != -1) {
                    // FIXME: not sure why we're getting -1 sometimes
                    mPendingEvent.distance = indexToValue(event->value);
                }
            }
        } else if (type == EV_SYN) {
                switch ( event->code ) {
                        case SYN_TIME_SEC:
                                mUseAbsTimeStamp = true;
                                report_time = event->value * 1000000000LL;
                                break;
                        case SYN_TIME_NSEC:
                                mUseAbsTimeStamp = true;
                                mPendingEvent.timestamp = report_time + event->value;
                                break;
                        case SYN_REPORT:
                                if(mUseAbsTimeStamp != true) {
                                        mPendingEvent.timestamp = timevalToNano(event->time);
                                }
                                if (mEnabled) {
                                        *data++ = mPendingEvent;
                                        count--;
                                        numEventReceived++;
                                }
                                break;
                }
        } else {
            ALOGE("ProximitySensor: unknown event (type=%d, code=%d)",
                    type, event->code);
        }
        mInputReader.next();
    }

    return numEventReceived;
}
int ProximitySensor::setInitialState() {
    struct input_absinfo absinfo;
    if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_PROXIMITY), &absinfo)) {
        // make sure to report an event immediately
        mHasPendingEvent = true;
        mPendingEvent.distance = indexToValue(absinfo.value);
    }
    return 0;
}
Exemple #6
0
		bool setName(const char* name, uint8* const value)
		{
			const char index = indexOf(name, names, count);
			if (index)
			{
				*value |= static_cast<uint8>(indexToValue(index));
				return true;
			}
			return false;
		}
Exemple #7
0
static std::string indexToTwoLetters(int index) //e.g. "Qs" is queen of spades
{
  if(index < 0 || index > 51) return "?";

  std::string result = "  ";
  result[0] = valueToSymbol(indexToValue(index));
  result[1] = suitToChar(indexToSuit(index));

  return result;
}
Exemple #8
0
int TSL2771Sensor::readEvents(sensors_event_t* data, int count)
{
    if (count < 1)
        return -EINVAL;

    ssize_t n = mInputReader.fill(data_fd);
    if (n < 0)
        return n;

    int numEventReceived = 0;
    input_event const* event;

    while (count && mInputReader.readEvent(&event)) {
        int type = event->type;
        if (type == EV_LED) {
            if (event->code == EVENT_TYPE_LIGHT) {
                mPendingEvents[light].light = event->value;
                mPendingMask |= 1 << light;
                mInputReader.next();
#ifdef DEBUG_TSL2771
                ALOGD("TSL2771Sensor: Received LUX value=%d", event->value);
#endif
            }
        } else if (type == EV_ABS) {
            if (event->code == EVENT_TYPE_PROXIMITY) {
                mPendingEvents[proximity].distance = indexToValue(event->value);
                mPendingMask |= 1 << proximity;
                mInputReader.next();
#ifdef DEBUG_TSL2771
                ALOGD("TSL2771Sensor: Received Proximity value=%d", event->value);
#endif
            }
        } else if (type == EV_SYN) {
           int64_t time = timevalToNano(event->time);
            for (int j=0 ; count && mPendingMask && j<numSensors ; j++) {
              if (mPendingMask & (1 << j)) {
                    mPendingMask &= ~(1 << j);
                    mPendingEvents[j].timestamp = time;
                    *data++ = mPendingEvents[j];
                        count--;
                        numEventReceived++;
              }
            }
            if (!mPendingMask) {
                mInputReader.next();
            }
        } else {
            ALOGE("TSL2771Sensor: unknown event (type=%d, code=%d)",
                    type, event->code);
        }
    }

    return numEventReceived;
}
bool LightSensor::handleEvent(input_event const *event) {
    if (event->value == -1) {
        return false;
    }
    mPendingEvent.light = indexToValue(event->value);
    if (mPendingEvent.light != mPreviousLight) {
        mPreviousLight = mPendingEvent.light;
        return true;
    }
    return false;
}
Exemple #10
0
static std::string indexToName(int index) //e.g. "Qs" is queen of spades
{
  if(index < 0 || index > 51) return "Unknown";

  std::string result;
  result += valueToName(indexToValue(index));
  result += " of ";
  result += suitToName(indexToSuit(index));

  return result;
}
Exemple #11
0
		bool setNames(std::vector<std::string>& new_names, uint8* const value)
		{
			std::vector<char> indices;
			for (std::vector<std::string>::iterator name = new_names.begin(); name != new_names.end(); ++name)
			{
				const char index = indexOf(name->c_str(), names, count);
				if (index) indices.push_back(index);
			}

			if (indices.size() != new_names.size()) return false;

			uint8 new_values = 0;
			std::vector<char>::iterator index = indices.begin();
			for (; index != indices.end(); ++index) new_values |= static_cast<uint8>(indexToValue(*index));
			*value |= new_values;
			return true;
		}
int LightSensor::readEvents(sensors_event_t* data, int count)
{
    if (count < 1)
        return -EINVAL;

    if (mHasPendingEvent) {
        mHasPendingEvent = false;
        mPendingEvent.timestamp = getTimestamp();
        *data = mPendingEvent;
        return mEnabled ? 1 : 0;
    }

    ssize_t n = mInputReader.fill(data_fd);
    if (n < 0)
        return n;

    int numEventReceived = 0;
    input_event const* event;

    while (count && mInputReader.readEvent(&event)) {
        int type = event->type;
        if (type == EV_ABS) {
            if (event->code == EVENT_TYPE_LIGHT) {
                mPendingEvent.light = indexToValue(event->value);
                if (mEventsSinceEnable < FIRST_GOOD_EVENT)
                    mEventsSinceEnable++;
            }
        } else if (type == EV_SYN) {
            mPendingEvent.timestamp = timevalToNano(event->time);
            if (mEnabled && (mPendingEvent.light != mPreviousLight) &&
                    mEventsSinceEnable >= FIRST_GOOD_EVENT) {
                *data++ = mPendingEvent;
                count--;
                numEventReceived++;
                mPreviousLight = mPendingEvent.light;
            }
        } else {
            LOGE("LightSensor: unknown event (type=%d, code=%d)",
                    type, event->code);
        }
        mInputReader.next();
    }

    return numEventReceived;
}
int LightSensor::readEvents(sensors_event_t* data, int count)
{
    if (count < 1)
        return -EINVAL;

    if (mHasPendingEvent) {
        mHasPendingEvent = false;
        mPendingEvent.timestamp = getTimestamp();
        *data = mPendingEvent;
        return mEnabled ? 1 : 0;
    }

    ssize_t n = mInputReader.fill(data_fd);
    if (n < 0)
        return n;

    int numEventReceived = 0;
    input_event const* event;

    while (count && mInputReader.readEvent(&event)) {
        int type = event->type;
        if (type == EV_ABS) {
            if (event->code == EVENT_TYPE_LIGHT) {
                if (event->value != -1) {
                    // FIXME: not sure why we're getting -1 sometimes
                    mPendingEvent.light = indexToValue(event->value);
                }
            }
        } else if (type == EV_SYN) {
            mPendingEvent.timestamp = timevalToNano(event->time);
            if (mEnabled) {
                *data++ = mPendingEvent;
                count--;
                numEventReceived++;
            }
        } else {
            LOGE("LightSensor: unknown event (type=%d, code=%d)",
                    type, event->code);
        }
        mInputReader.next();
    }

    return numEventReceived;
}
int LightSensor29023::readEvents(sensors_event_t* data, int count)
{
    if (count < 1)
        return -EINVAL;

    if (mHasPendingEvent) {
        mHasPendingEvent = false;
        mPendingEvent.timestamp = getTimestamp();
        *data = mPendingEvent;
        return mEnabled ? 1 : 0;
    }

    ssize_t n = mInputReader.fill(data_fd);
    if (n < 0)
        return n;

    int numEventReceived = 0;
    input_event const* event;

    while (count && mInputReader.readEvent(&event)) {
        int type = event->type;
        if (type == EV_ABS) {
            if (event->code == EVENT_TYPE_LIGHT) {
                mPendingEvent.light = indexToValue(event->value);
                #if SENSOR_DEBUG
        		ALOGD_IF(SENSOR_DEBUG,"LightSensor29023::readEvents light =%f\n",mPendingEvent.light);
        		#endif
            }
        } else if (type == EV_SYN) {
            mPendingEvent.timestamp = timevalToNano(event->time);
            if (mEnabled) {
                *data++ = mPendingEvent;
                count--;
                numEventReceived++;
            }
        } else {            
            ALOGE("LightSensor29023: unknown event (type=%d, code=%d)",
                        type, event->code);
        }
        mInputReader.next();
    }

    return numEventReceived;
}
int ProximitySensor::readEvents(sensors_event_t* data, int count)
{
    if (count < 1)
        return -EINVAL;

    if (mHasPendingEvent) {
        mHasPendingEvent = false;
        mPendingEvent.timestamp = getTimestamp();
        *data = mPendingEvent;
        return mEnabled ? 1 : 0;
    }

    ssize_t n = mInputReader.fill(data_fd);
    if (n < 0)
        return n;

    int numEventReceived = 0;
    input_event const* event;

    while (count && mInputReader.readEvent(&event)) {
        int type = event->type;
        if (type == EV_ABS) {
            if (event->code == EVENT_TYPE_PROXIMITY) {
                mPendingEvent.distance = indexToValue(event->value);
            }
        } else if (type == EV_SYN) {
            mPendingEvent.timestamp = timevalToNano(event->time);
            if (mEnabled) {
                *data++ = mPendingEvent;
                count--;
                numEventReceived++;
            }
        } else {
            LOGE("ProximitySensor: unknown event (type=%d, code=%d)",
                    type, event->code);
        }
        mInputReader.next();
    }

    return numEventReceived;
}
int CwMcuSensor::processEvent(uint8_t *event) {
    int sensorsid = 0;
    int16_t data[3];
    int16_t bias[3];
    int64_t time;

    sensorsid = (int)event[0];
    memcpy(data, &event[1], 6);
    memcpy(bias, &event[7], 6);
    memcpy(&time, &event[13], 8);

    mPendingEvents[sensorsid].timestamp = time * NS_PER_MS;

    switch (sensorsid) {
    case CW_ORIENTATION:
    case CW_ORIENTATION_W:
        mPendingMask.markBit(sensorsid);
        if ((sensorsid == CW_ORIENTATION) || (sensorsid == CW_ORIENTATION_W)) {
            mPendingEvents[sensorsid].orientation.status = bias[0];
        }
        mPendingEvents[sensorsid].data[0] = (float)data[0] * CONVERT_10;
        mPendingEvents[sensorsid].data[1] = (float)data[1] * CONVERT_10;
        mPendingEvents[sensorsid].data[2] = (float)data[2] * CONVERT_10;
        break;
    case CW_ACCELERATION:
    case CW_MAGNETIC:
    case CW_GYRO:
    case CW_LINEARACCELERATION:
    case CW_GRAVITY:
    case CW_ACCELERATION_W:
    case CW_MAGNETIC_W:
    case CW_GYRO_W:
    case CW_LINEARACCELERATION_W:
    case CW_GRAVITY_W:
        mPendingMask.markBit(sensorsid);
        if ((sensorsid == CW_MAGNETIC) || (sensorsid == CW_MAGNETIC_W)) {
            mPendingEvents[sensorsid].magnetic.status = bias[0];
            ALOGV("CwMcuSensor::processEvent: magnetic accuracy = %d\n",
                  mPendingEvents[sensorsid].magnetic.status);
        }
        mPendingEvents[sensorsid].data[0] = (float)data[0] * CONVERT_100;
        mPendingEvents[sensorsid].data[1] = (float)data[1] * CONVERT_100;
        mPendingEvents[sensorsid].data[2] = (float)data[2] * CONVERT_100;
        break;
    case CW_PRESSURE:
    case CW_PRESSURE_W:
        mPendingMask.markBit(sensorsid);
        // .pressure is data[0] and the unit is hectopascal (hPa)
        mPendingEvents[sensorsid].pressure = ((float)*(int32_t *)(&data[0])) * CONVERT_100;
        // data[1] is not used, and data[2] is the temperature
        mPendingEvents[sensorsid].data[2] = ((float)data[2]) * CONVERT_100;
        break;
    case CW_ROTATIONVECTOR:
    case CW_GAME_ROTATION_VECTOR:
    case CW_GEOMAGNETIC_ROTATION_VECTOR:
    case CW_ROTATIONVECTOR_W:
    case CW_GAME_ROTATION_VECTOR_W:
    case CW_GEOMAGNETIC_ROTATION_VECTOR_W:
        mPendingMask.markBit(sensorsid);
        mPendingEvents[sensorsid].data[0] = (float)data[0] * CONVERT_10000;
        mPendingEvents[sensorsid].data[1] = (float)data[1] * CONVERT_10000;
        mPendingEvents[sensorsid].data[2] = (float)data[2] * CONVERT_10000;
        break;
    case CW_MAGNETIC_UNCALIBRATED:
    case CW_GYROSCOPE_UNCALIBRATED:
    case CW_MAGNETIC_UNCALIBRATED_W:
    case CW_GYROSCOPE_UNCALIBRATED_W:
        mPendingMask.markBit(sensorsid);
        mPendingEvents[sensorsid].data[0] = (float)data[0] * CONVERT_100;
        mPendingEvents[sensorsid].data[1] = (float)data[1] * CONVERT_100;
        mPendingEvents[sensorsid].data[2] = (float)data[2] * CONVERT_100;
        mPendingEvents[sensorsid].data[3] = (float)bias[0] * CONVERT_100;
        mPendingEvents[sensorsid].data[4] = (float)bias[1] * CONVERT_100;
        mPendingEvents[sensorsid].data[5] = (float)bias[2] * CONVERT_100;
        break;
    case CW_SIGNIFICANT_MOTION:
        mPendingMask.markBit(sensorsid);
        mPendingEvents[sensorsid].data[0] = 1.0;
        ALOGV("SIGNIFICANT timestamp = %" PRIu64 "\n", mPendingEvents[sensorsid].timestamp);
        break;
    case CW_LIGHT:
        mPendingMask.markBit(sensorsid);
        mPendingEvents[sensorsid].light = indexToValue(data[0]);
        break;
    case CW_STEP_DETECTOR:
    case CW_STEP_DETECTOR_W:
        mPendingMask.markBit(sensorsid);
        mPendingEvents[sensorsid].data[0] = data[0];
        ALOGV("STEP_DETECTOR, timestamp = %" PRIu64 "\n", mPendingEvents[sensorsid].timestamp);
        break;
    case CW_STEP_COUNTER:
    case CW_STEP_COUNTER_W:
        mPendingMask.markBit(sensorsid);
        // We use 4 bytes in SensorHUB
        mPendingEvents[sensorsid].u64.step_counter = *(uint32_t *)&data[0];
        mPendingEvents[sensorsid].u64.step_counter += 0x100000000LL * (*(uint32_t *)&bias[0]);
        ALOGV("processEvent: step counter = %" PRId64 "\n",
              mPendingEvents[sensorsid].u64.step_counter);
        break;
    case CW_META_DATA:
        mPendingEventsFlush.meta_data.what = META_DATA_FLUSH_COMPLETE;
        mPendingEventsFlush.meta_data.sensor = find_handle(data[0]);
        ALOGV("CW_META_DATA: meta_data.sensor = %d, data[0] = %d\n",
              mPendingEventsFlush.meta_data.sensor, data[0]);
        break;
    default:
        ALOGW("%s: Unknown sensorsid = %d\n", __func__, sensorsid);
        break;
    }

    return sensorsid;
}
Exemple #17
0
		Enum getEnum(const char* name) { return Enum(static_cast<uint8>(indexToValue((indexOf(name, names, count))))); }
Exemple #18
0
void Card::setIndex(int index)
{
  suit = indexToSuit(index);
  value = indexToValue(index);
}