Пример #1
0
void CABL::stop_cabl() {
    LOGD_IF(mDebug, "Stop_CABL E");
    void *ret;
    pthread_mutex_lock(&mCABLCtrlLock);
    pthread_mutex_lock(&mCABLLock);
    if (eStatus == CABL_OFF) {
        LOGD("CABL is already off!");
        pthread_mutex_unlock(&mCABLLock);
        pthread_mutex_unlock(&mCABLCtrlLock);
        return;
    }
    /* stop the threads */
    eStatus = CABL_OFF;
    pthread_mutex_unlock(&mCABLLock);
    pthread_cond_signal(&mCABLCond);
    /* signal the worker for exit */
    pthread_join(mWorkerThreadID, &ret);
    LOGD_IF(mDebug, "CABL Threads teminated, cleaning up resources");
    pthread_mutex_lock(&mCABLLock);
    mHistStatus = 0;
    pthread_mutex_unlock(&mCABLLock);
    set_backlight_scale(BL_SCALE_MAX, mOEMParams.bl_min_level); //Restore BL to 100%
    ScreenRefresher::deleteInstance();
    mRefresher = NULL;
    LOGD_IF(mDebug, "Stop_CABL X");
    pthread_mutex_unlock(&mCABLCtrlLock);
}
void SensorService::cleanupConnection(SensorEventConnection* c)
{
    Mutex::Autolock _l(mLock);
    const wp<SensorEventConnection> connection(c);
    size_t size = mActiveSensors.size();
    LOGD_IF(DEBUG_CONNECTIONS, "%d active sensors", size);
    for (size_t i=0 ; i<size ; ) {
        int handle = mActiveSensors.keyAt(i);
        if (c->hasSensor(handle)) {
            LOGD_IF(DEBUG_CONNECTIONS, "%i: disabling handle=0x%08x", i, handle);
            SensorInterface* sensor = mSensorMap.valueFor( handle );
            LOGE_IF(!sensor, "mSensorMap[handle=0x%08x] is null!", handle);
            if (sensor) {
                sensor->activate(c, false);
            }
        }
        SensorRecord* rec = mActiveSensors.valueAt(i);
        LOGE_IF(!rec, "mActiveSensors[%d] is null (handle=0x%08x)!", i, handle);
        LOGD_IF(DEBUG_CONNECTIONS,
                "removing connection %p for sensor[%d].handle=0x%08x",
                c, i, handle);

        if (rec && rec->removeConnection(connection)) {
            LOGD_IF(DEBUG_CONNECTIONS, "... and it was the last connection");
            mActiveSensors.removeItemsAt(i, 1);
            mActiveVirtualSensors.removeItem(handle);
            delete rec;
            size--;
        } else {
            i++;
        }
    }
    mActiveConnections.remove(connection);
}
Пример #3
0
int CABL::Notify(uint32_t notification_type) {
    int32_t ret = 0;
    LOGD_IF(mDebug, "Starting %s ", __func__);
    pthread_mutex_lock(&mCABLLock);
    if (mHistStatus == 0 && (notification_type == NOTIFY_TYPE_BL_UPDATE || notification_type == NOTIFY_TYPE_UPDATE)) {
        uint32_t level = get_backlight_level();
        if (level <= mOEMParams.bl_min_level) {
            LOGE_IF(mDebug, "New BL level %d lower than min level %u,"
                    " Skip this update for calc",
                    level, mOEMParams.bl_min_level);
            if (mPrevNotify == NOTIFY_TYPE_SUSPEND)
                ret = -1;
            goto exit_early;
        }
        if (eStatus == CABL_OFF) {
            pthread_mutex_unlock(&mCABLLock);
            return ret;
        }
        LOGD_IF(mDebug, "Start notification received, start histogram");
        ret = startHistogram();
        if (0 == ret) {
            mHistStatus = 1;
            pthread_cond_signal(&mCABLCond);
        }
    } else if (mHistStatus == 1 &&
        (notification_type == NOTIFY_TYPE_SUSPEND ||
        notification_type == NOTIFY_TYPE_NO_UPDATE)) {
        LOGD_IF(mDebug, "Stop notification received, stop histogram");
        if(!stopHistogram(mHistStatus))
            mHistStatus = 0;
        if (notification_type == NOTIFY_TYPE_SUSPEND)
            abl_reset_history();

    }

    if (notification_type == NOTIFY_TYPE_BL_UPDATE) {
        if (mRefresher) {
            mRefresher->Control(1);
            LOGE_IF(mDebug, "Calling refresh()");
            mRefresher->Refresh(1, 16);
            mRefresher->Control(0);
        }
    }
exit_early:
    mPrevNotify = notification_type;
    pthread_mutex_unlock(&mCABLLock);
    return ret;
}
Пример #4
0
int BladeLight::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_LIGHT) {
                LOGD_IF(DEBUG,"Light value=%i",event->value);
                mPendingEvents.light = event->value;
            }
        } else if (type == EV_SYN) {
             int64_t time = timevalToNano(event->time);
             if (mEnabled) {
                 *data++ = mPendingEvents;
                 mPendingEvents.timestamp=time;
                 count--;
                 numEventReceived++;
             }
        } else {
            LOGE("BladeLight: unknown event (type=%d, code=%d)",type, event->code);
        }
        mInputReader.next();
    }
    return numEventReceived;
}
Пример #5
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 v4l2_overlay_init(int fd, uint32_t w, uint32_t h, uint32_t fmt)
{
    LOG_FUNCTION_NAME

    struct v4l2_format format;
    int ret;

    format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
    ret = v4l2_overlay_ioctl(fd, VIDIOC_G_FMT, &format, "get format");
    if (ret)
        return ret;
    LOGV("v4l2_overlay_init:: w=%d h=%d", format.fmt.pix.width, format.fmt.pix.height);

    format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
    ret = configure_pixfmt(&format.fmt.pix, fmt, w, h);
    if (ret)
        return ret;
    LOGV("v4l2_overlay_init set:: w=%d h=%d fmt=%d", format.fmt.pix.width, format.fmt.pix.height, format.fmt.pix.pixelformat);
    ret = v4l2_overlay_ioctl(fd, VIDIOC_S_FMT, &format, "set output format");

    format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
    ret = v4l2_overlay_ioctl(fd, VIDIOC_G_FMT, &format, "get output format");
    LOGV("v4l2_overlay_init get:: w=%d h=%d fmt=%d", format.fmt.pix.width, format.fmt.pix.height, format.fmt.pix.pixelformat);

    char value[PROPERTY_VALUE_MAX];
    property_get("debug.video.rotateoverlay", value, "0");
    mRotateOverlay = atoi(value);
    LOGD_IF(mRotateOverlay, "overlay rotation enabled");

    return ret;
}
status_t SensorFusion::activate(void* ident, bool enabled) {

    LOGD_IF(DEBUG_CONNECTIONS,
            "SensorFusion::activate(ident=%p, enabled=%d)",
            ident, enabled);

    const ssize_t idx = mClients.indexOf(ident);
    if (enabled) {
        if (idx < 0) {
            mClients.add(ident);
        }
    } else {
        if (idx >= 0) {
            mClients.removeItemsAt(idx);
        }
    }

    mSensorDevice.activate(ident, mAcc.getHandle(), enabled);
    mSensorDevice.activate(ident, mMag.getHandle(), enabled);
    mSensorDevice.activate(ident, mGyro.getHandle(), enabled);

    const bool newState = mClients.size() != 0;
    if (newState != mEnabled) {
        mEnabled = newState;
        if (newState) {
            mFusion.init();
            mGyroTime = 0;
        }
    }
    return NO_ERROR;
}
ssize_t SharedBufferClient::dequeue()
{
    SharedBufferStack& stack( *mSharedStack );

    if (stack.head == tail && stack.available == mNumBuffers) {
        LOGW("dequeue: tail=%d, head=%d, avail=%d, queued=%d",
                tail, stack.head, stack.available, stack.queued);
    }

    RWLock::AutoRLock _rd(mLock);

    const nsecs_t dequeueTime = systemTime(SYSTEM_TIME_THREAD);

    //LOGD("[%d] about to dequeue a buffer",
    //        mSharedStack->identity);
    DequeueCondition condition(this);
    status_t err = waitForCondition(condition);
    if (err != NO_ERROR)
        return ssize_t(err);

    DequeueUpdate update(this);
    updateCondition( update );

    int dequeued = stack.index[tail];
    tail = ((tail+1 >= mNumBuffers) ? 0 : tail+1);
    LOGD_IF(DEBUG_ATOMICS, "dequeued=%d, tail++=%d, %s",
            dequeued, tail, dump("").string());

    mDequeueTime[dequeued] = dequeueTime; 

    return dequeued;
}
Пример #9
0
uint32_t Layer::doTransaction(uint32_t flags)
{
    const Layer::State& front(drawingState());
    const Layer::State& temp(currentState());

    const bool sizeChanged = (front.requested_w != temp.requested_w) ||
            (front.requested_h != temp.requested_h);

    if (sizeChanged) {
        // the size changed, we need to ask our client to request a new buffer
        LOGD_IF(DEBUG_RESIZE,
                "doTransaction: "
                "resize (layer=%p), requested (%dx%d), drawing (%d,%d), "
                "scalingMode=%d",
                this,
                int(temp.requested_w), int(temp.requested_h),
                int(front.requested_w), int(front.requested_h),
                mCurrentScalingMode);

        if (!isFixedSize()) {
            // this will make sure LayerBase::doTransaction doesn't update
            // the drawing state's size
            Layer::State& editDraw(mDrawingState);
            editDraw.requested_w = temp.requested_w;
            editDraw.requested_h = temp.requested_h;
        }

        // record the new size, form this point on, when the client request
        // a buffer, it'll get the new size.
        mSurfaceTexture->setDefaultBufferSize(temp.requested_w,
                temp.requested_h);
    }

    return LayerBase::doTransaction(flags);
}
Пример #10
0
bool HeadSetDetect::threadLoop()
{ 
    int state = detect(); //do not hold lock;
    Mutex::Autolock _l(mLock);
    if(mActive == false)
    {
       if(mFd >=0)
       {
           close(mFd); //close socket
           mFd = -1;
       }
       LOGD("thread to exit");
       return false;
    }
    //SXLOGV("threadLoop:state=%d",state);
    if(state != -1)
    {
        bool on= headsetConnect(state);
        if(mOn != on )
        {  
            mCblk(mObserver,on);
            mOn = on; 
        }
    }
    LOGD_IF(state == -1,"detect other event");
  return true;
}
Пример #11
0
 int getMaxFiles()
 {
     const std::string files = getEnv("LOG_MAXFILES");
     LOGD_IF(!files.empty()) << "ENV.LOG_MAXFILES:" << files;
     LOGW_IF(files.empty()) << "ENV.LOG_MAXFILES:" << "NULL";
     return files.empty() ? 0 : std::atoi(files.c_str());
 }
Пример #12
0
 size_t getMaxFileSize()
 {
     const std::string size = getEnv("LOG_MAXFILESIZE");
     LOGD_IF(!size.empty()) << "ENV.LOG_MAXFILESIZE:" << size;
     LOGW_IF(size.empty()) << "ENV.LOG_MAXFILESIZE:" << "NULL";
     return size.empty() ? 0 : std::atoi(size.c_str());
 }
bool IntelDisplayDevice::isVideoPutInWindow(int output, hwc_layer_1_t *layer) {
    bool inWindow = false;

    if (mDrm == NULL) {
        ALOGE("mDrm is NULL!");
        return false;
    }

    drmModeFBPtr fbInfo = mDrm->getOutputFBInfo(output);
    if (fbInfo == NULL) {
        ALOGE("Get FB info failed!");
        return false;
    }

    int fbW = fbInfo->width;
    int fbH = fbInfo->height;

    int srcWidth = layer->sourceCrop.right - layer->sourceCrop.left;
    int srcHeight = layer->sourceCrop.bottom - layer->sourceCrop.top;
    uint32_t metadata_transform = 0;
    if (getMetaDataTransform(layer, metadata_transform) == -1) {
        ALOGE("Get meta data transform failed!");
        return false;
    }

    if (metadata_transform == HAL_TRANSFORM_ROT_90 ||
            metadata_transform == HAL_TRANSFORM_ROT_270) {
        int temp;
        temp = srcWidth; srcWidth = srcHeight; srcHeight = temp;
    }

    int dstWidth = layer->displayFrame.right - layer->displayFrame.left;
    int dstHeight = layer->displayFrame.bottom - layer->displayFrame.top;

    LOGD_IF(ALLOW_HWC_PRINT,
            "output:%d fbW:%d fbH:%d dst_w:%d dst_h:%d src_w:%d src_h:%d",
            output, fbW, fbH, dstWidth, dstHeight, srcWidth, srcHeight);
    /*
     * Check if the app put the video to a window
     * 1) Both dst width and height are smaller than FB w/h
     * 2) For device(e.g. phone), fbW < fbH:
     check if it is back to portait mode.
     * 3) For device(e.g. tablet, hdtv), fbW > fbH:
     check if it is back to portait mode.
     */
    if (dstWidth < fbW - 1 && dstHeight < fbH - 1) {
        inWindow = true;
    } else if (fbW < fbH) {
        if ((dstWidth > dstHeight && srcWidth >= srcHeight) ||
            (dstWidth < dstHeight && srcWidth <= srcHeight))
            inWindow = true;
    } else if (fbW > fbH) {
        if ((dstWidth > dstHeight && srcWidth <= srcHeight) ||
            (dstWidth < dstHeight && srcWidth >= srcHeight))
            inWindow = true;
    }

    return inWindow;
}
Пример #14
0
 plog::Severity getLevel()
 {
     const std::string level = getEnv("LOG_LEVEL");
     LOGD_IF(!level.empty()) << "ENV.LOG_LEVEL:" << level
                             << ":" << plog::severityFromString(level.c_str());
     LOGW_IF(level.empty()) << "ENV.LOG_LEVEL:" << "NULL";
     return level.empty() ? plog::debug : plog::severityFromString(level.c_str());
 }
Пример #15
0
uint32_t Layer::doTransaction(uint32_t flags)
{
    const Layer::State& front(drawingState());
    const Layer::State& temp(currentState());

    const bool sizeChanged = (front.requested_w != temp.requested_w) ||
            (front.requested_h != temp.requested_h);

    if (sizeChanged) {
        // the size changed, we need to ask our client to request a new buffer
        LOGD_IF(DEBUG_RESIZE,
                "doTransaction: "
                "resize (layer=%p), requested (%dx%d), drawing (%d,%d), "
                "scalingMode=%d",
                this,
                int(temp.requested_w), int(temp.requested_h),
                int(front.requested_w), int(front.requested_h),
                mCurrentScalingMode);

        if (!isFixedSize()) {
            // we're being resized and there is a freeze display request,
            // acquire a freeze lock, so that the screen stays put
            // until we've redrawn at the new size; this is to avoid
            // glitches upon orientation changes.
            if (mFlinger->hasFreezeRequest()) {
                // if the surface is hidden, don't try to acquire the
                // freeze lock, since hidden surfaces may never redraw
                if (!(front.flags & ISurfaceComposer::eLayerHidden)) {
                    mFreezeLock = mFlinger->getFreezeLock();
                }
            }

            // this will make sure LayerBase::doTransaction doesn't update
            // the drawing state's size
            Layer::State& editDraw(mDrawingState);
            editDraw.requested_w = temp.requested_w;
            editDraw.requested_h = temp.requested_h;
        }

        // record the new size, form this point on, when the client request
        // a buffer, it'll get the new size.
        mSurfaceTexture->setDefaultBufferSize(temp.requested_w,
                temp.requested_h);
    }

    if (temp.sequence != front.sequence) {
        if (temp.flags & ISurfaceComposer::eLayerHidden || temp.alpha == 0) {
            // this surface is now hidden, so it shouldn't hold a freeze lock
            // (it may never redraw, which is fine if it is hidden)
            mFreezeLock.clear();
        }
    }
        
    return LayerBase::doTransaction(flags);
}
Пример #16
0
int32_t CABL::auto_adjust_quality_lvl(){
    int32_t result = 0;
    char lvl[MAX_CMD_LEN];
    char property[PROPERTY_VALUE_MAX];
    if (property_get(YUV_INPUT_STATE_PROP, property, NULL) > 0) {
        if ((atoi(property) == 1) && (mPowerSaveLevel != mOEMParams.video_quality_lvl)) {
            mPowerSaveLevel = mOEMParams.video_quality_lvl;
            LOGD_IF(mDebug, "Power saving level: %d", mPowerSaveLevel);
            pthread_mutex_lock(&mCABLLock);
            result = abl_change_quality_level(&mOEMParams, mPowerSaveLevel);
            pthread_mutex_unlock(&mCABLLock);
        }else if ((atoi(property) == 0) && (mPowerSaveLevel != mOEMParams.ui_quality_lvl)) {
            mPowerSaveLevel = mOEMParams.ui_quality_lvl;
            LOGD_IF(mDebug, "Power saving level: %d", mPowerSaveLevel);
            pthread_mutex_lock(&mCABLLock);
            result = abl_change_quality_level(&mOEMParams, mPowerSaveLevel);
            pthread_mutex_unlock(&mCABLLock);
        }
    }
    return result;
}
Пример #17
0
sp<MemoryDealer> GPUHardware::request(int pid)
{
    sp<MemoryDealer> dealer;
    Mutex::Autolock _l(mLock);
    Client* client;
    LOGD("pid %d requesting gpu surface (current owner = %d)", pid, mOwner);
    if (requestLocked(pid) == NO_ERROR) {
        dealer = mCurrentAllocator;
        LOGD_IF(dealer!=0, "gpu surface granted to pid %d", mOwner);
    }
    return dealer;
}
Пример #18
0
int BladeLight::enable(int32_t handle, int en) {

    if (handle != ID_L)
        return -EINVAL;

    int newState = en ? 1 : 0;
    int err = 0;

    if (uint32_t(newState) != mEnabled) {
        if (!mEnabled) {
            open_device();
        }
        int cmd;

	if (newState) {
            cmd = PS_ALS_IOCTL_ALS_ON;
            LOGD_IF(DEBUG,"ALS ON");
        } else {
            cmd = PS_ALS_IOCTL_ALS_OFF;
            LOGD_IF(DEBUG,"ALS OFF");
        }
        err = ioctl(dev_fd, cmd);
        err = err<0 ? -errno : 0;
        LOGE_IF(err, "PS_ALS_IOCTL_XXX failed (%s)", strerror(-err));
        if (!err) {
            if (en) {
                setInitialState();
                mEnabled = 1;
            }
            else
                mEnabled = 0;
        }
        if (!mEnabled) {
            LOGD_IF(DEBUG,"closing device");
            close_device();
        }
    }
    return err;
}
Пример #19
0
int is_backlight_modified(CABL *cabl, uint32_t *old_lvl)
{
    int ret;
    uint32_t temp_lvl = get_backlight_level();

    struct fb_cmap cmap;
    if (temp_lvl != *old_lvl) {
        ret = 1;
        LOGD_IF(cabl->mDebug, "The BL level changed,");
        *old_lvl = temp_lvl;
        LOGD_IF(cabl->mDebug, "The BL level changed to %u", temp_lvl);
        /* Reset the orig level only if > than the min level */
        if (temp_lvl >= cabl->mOEMParams.bl_min_level) {
            cabl->mOEMParams.orig_level = temp_lvl;
            abl_change_orig_bl_level(&cabl->mOEMParams);
            //set the new restore level
            cabl->mUserBLLevel = temp_lvl;
        }
    } else {
        ret = 0;
    }
    return ret;
}
ssize_t SharedBufferServer::retireAndLock()
{
    RWLock::AutoRLock _l(mLock);

    RetireUpdate update(this, mNumBuffers);
    ssize_t buf = updateCondition( update );
    if (buf >= 0) {
        if (uint32_t(buf) >= SharedBufferStack::NUM_BUFFER_MAX)
            return BAD_VALUE;
        SharedBufferStack& stack( *mSharedStack );
        buf = stack.index[buf];
        LOGD_IF(DEBUG_ATOMICS && buf>=0, "retire=%d, %s",
                int(buf), dump("").string());
    }
    return buf;
}
int get_events_val(ECOM_ValueTypeDef *data)
{
	struct input_event acc_event;
	struct input_event mag_event;
	int ret;

	while(1) {
		ret = read(acc_event_fd, &acc_event, sizeof(struct input_event));
		if (ret != sizeof(struct input_event))
			continue;

		if(acc_event.type == EV_ABS) {
			if(acc_event.code == ABS_X)
				data->ax = acc_event.value; 
			if(acc_event.code == ABS_Y)
				data->ay = acc_event.value;   
			if(acc_event.code == ABS_Z)
				data->az = acc_event.value;  
		}

		if(acc_event.type == 0)
			break;
	}

	while(1) {
		ret = read(mag_event_fd, &mag_event, sizeof(struct input_event));
		if (ret != sizeof(struct input_event))
			continue;

		if(mag_event.type == EV_ABS) {
			if(mag_event.code == ABS_X)
				data->mx = mag_event.value;  
			if(mag_event.code == ABS_Y)
				data->my = mag_event.value;   
			if(mag_event.code == ABS_Z)
				data->mz = mag_event.value;  
		}
		if(mag_event.type == 0)
			break;
	}

	data->time = data__now_ns()/1000000;

	LOGD_IF(0, "%s %d %d %d %d %d %d %d\n", __FUNCTION__, data->ax, data->ay, data->az, data->mx, data->my, data->mz, data->time);

	return 0;
}
status_t SharedBufferClient::queue(int buf)
{
    RWLock::AutoRLock _rd(mLock);

    SharedBufferStack& stack( *mSharedStack );

    queued_head = (queued_head + 1) % mNumBuffers;
    stack.index[queued_head] = buf;

    QueueUpdate update(this);
    status_t err = updateCondition( update );
    LOGD_IF(DEBUG_ATOMICS, "queued=%d, %s", buf, dump("").string());

    const nsecs_t now = systemTime(SYSTEM_TIME_THREAD);
    stack.stats.totalTime = ns2us(now - mDequeueTime[buf]);
    return err;
}
static jint native_addCustomFunction(JNIEnv* env, jobject object,
        jstring name, jint numArgs, jobject function)
{
    sqlite3 * handle = (sqlite3 *)env->GetIntField(object, offset_db_handle);
    char const *nameStr = env->GetStringUTFChars(name, NULL);
    jobject ref = env->NewGlobalRef(function);
    LOGD_IF(DEBUG_JNI, "native_addCustomFunction %s ref: %p", nameStr, ref);
    int err = sqlite3_create_function(handle, nameStr, numArgs, SQLITE_UTF8,
            (void *)ref, custom_function_callback, NULL, NULL);
    env->ReleaseStringUTFChars(name, nameStr);

    if (err == SQLITE_OK)
        return (int)ref;
    else {
        LOGE("sqlite3_create_function returned %d", err);
        env->DeleteGlobalRef(ref);
        throw_sqlite3_exception(env, handle);
        return 0;
     }
}
static int
pick_sensor(SensorData*      data,
	sensors_data_t*  values)
{
	uint32_t mask = SUPPORTED_SENSORS;
	while (mask) {
		uint32_t i = 31 - __builtin_clz(mask);
		mask &= ~(1<<i);
		if (data->pendingSensors & (1<<i)) {
			data->pendingSensors &= ~(1<<i);
			*values = data->sensors[i];
			values->sensor = (1<<i);
			LOGD_IF(0, "%s: %d [%f, %f, %f]", __FUNCTION__,
				(1<<i),
				values->vector.x,
				values->vector.y,
				values->vector.z);
			return i;
		}
	}
	LOGE("No sensor to return!!! pendingSensors=%08x", data->pendingSensors);
	return -1;
}
static int set_delay(int ms)
{
	int acc_fd, mag_fd;
	static int old_ms = 0;

	if (old_ms == ms)
		return 0;

	acc_fd = open("/dev/lsm303dlh_acc", O_RDONLY);
	mag_fd = open("/dev/lsm303dlh_mag", O_RDONLY);

	if ((acc_fd > 0) && (mag_fd > 0)) {
		LOGD_IF(1, "%s: ms=%d", __FUNCTION__, ms);
		ioctl(acc_fd, LSM303DLH_ACC_IOCTL_SET_DELAY, &ms);
		ioctl(mag_fd, LSM303DLH_MAG_IOCTL_SET_DELAY, &ms);
		close(acc_fd);
		close(mag_fd);
		old_ms = ms;
		return 0;
	} else {
		return -1;
	}
}
Пример #26
0
sp<IMemoryHeap> HeapCache::find_heap(const sp<IBinder>& binder) 
{
    Mutex::Autolock _l(mHeapCacheLock);
    ssize_t i = mHeapCache.indexOfKey(binder);
    if (i>=0) {
        heap_info_t& info = mHeapCache.editValueAt(i);
        LOGD_IF(VERBOSE,
                "found binder=%p, heap=%p, size=%d, fd=%d, count=%d", 
                binder.get(), info.heap.get(),
                static_cast<BpMemoryHeap*>(info.heap.get())->mSize,
                static_cast<BpMemoryHeap*>(info.heap.get())->mHeapId,
                info.count);
        android_atomic_inc(&info.count);
        return info.heap;
    } else {
        heap_info_t info;
        info.heap = interface_cast<IMemoryHeap>(binder);
        info.count = 1;
        //LOGD("adding binder=%p, heap=%p, count=%d",
        //      binder.get(), info.heap.get(), info.count);
        mHeapCache.add(binder, info);
        return info.heap;
    }
}
Пример #27
0
void HeapCache::free_heap(const wp<IBinder>& binder) 
{
    sp<IMemoryHeap> rel;
    {
        Mutex::Autolock _l(mHeapCacheLock);
        ssize_t i = mHeapCache.indexOfKey(binder);
        if (i>=0) {
            heap_info_t& info(mHeapCache.editValueAt(i));
            int32_t c = android_atomic_dec(&info.count);
            if (c == 1) {
                LOGD_IF(VERBOSE,
                        "removing binder=%p, heap=%p, size=%d, fd=%d, count=%d", 
                        binder.unsafe_get(), info.heap.get(),
                        static_cast<BpMemoryHeap*>(info.heap.get())->mSize,
                        static_cast<BpMemoryHeap*>(info.heap.get())->mHeapId,
                        info.count);
                rel = mHeapCache.valueAt(i).heap;
                mHeapCache.removeItemsAt(i);
            }
        } else {
            LOGE("free_heap binder=%p not found!!!", binder.unsafe_get());
        }
    }
}
static int
data__poll(struct sensors_data_device_t *dev, sensors_data_t* values)
{
	SensorData*  data = (void*)dev;
	static ECOM_ValueTypeDef event_val;
  
  //D("%s: dev=%p", __FUNCTION__, dev);
  
	// wait until we get a complete event for an enabled sensor
	uint32_t new_sensors = 0;
	if (acc_event_fd < 0 || mag_event_fd < 0)
		return -1;

	// there are pending sensors, returns them now...
	if (data->pendingSensors) {
		return pick_sensor(data, values);
	}

	get_events_val(&event_val); 

	new_sensors |= SENSORS_ACCELERATION;
	data->sensors[ID_ACCELERATION].acceleration.x = event_val.ay*GRAVITY_EARTH/1000.0f;  
	data->sensors[ID_ACCELERATION].acceleration.y = -event_val.ax*GRAVITY_EARTH/1000.0f;  
	data->sensors[ID_ACCELERATION].acceleration.z = -event_val.az*GRAVITY_EARTH/1000.0f;  

	/*
	 * For SystemServer process(active_sensors != 0, it only cares about acceleration
	 */
	if (active_sensors == 0) {   
    if(MEMSAlgLib_eCompass_IsCalibrated())
    {
      short MAGOFFX1,MAGOFFY1,MAGOFFZ1;
      MEMSAlgLib_eCompass_GetCalibration(&MAGOFFX1,&MAGOFFY1,&MAGOFFZ1); 
      new_sensors |= SENSORS_MAGNETIC_FIELD;
      data->sensors[ID_MAGNETIC_FIELD].magnetic.x = (event_val.my-MAGOFFY1)*(1.0f/1000.0f)*100.0f;          
      data->sensors[ID_MAGNETIC_FIELD].magnetic.y = -(event_val.mx-MAGOFFX1)*(1.0f/1000.0f)*100.0f;          
      data->sensors[ID_MAGNETIC_FIELD].magnetic.z = -(event_val.mz-MAGOFFZ1)*(1.0f/1000.0f)*100.0f;          
      LOGD_IF(0, "%s cal: %d %d %d\n", __FUNCTION__, MAGOFFX1, MAGOFFY1, MAGOFFZ1);
    }
	}

	if (active_sensors == 0) {
		short MAGOFFX1,MAGOFFY1,MAGOFFZ1;
		short MAGOFFX2,MAGOFFY2,MAGOFFZ2;

		//get old calibration data
		MEMSAlgLib_eCompass_GetCalibration(&MAGOFFX1,&MAGOFFY1,&MAGOFFZ1);

    LOGD_IF(1, "mmx=%d,mmy=%d,mmz=%d,ax=%d,ay=%d,az=%d,time=%d,cx=%d,cy=%d,cz=%d\n\r", 	event_val.mx,event_val.my,event_val.mz,event_val.ax,event_val.ay,event_val.az,event_val.time,MAGOFFX1,MAGOFFY1,MAGOFFZ1);
    
		//Azimuth
		MEMSAlgLib_eCompass_Update(&event_val);

		if(MEMSAlgLib_eCompass_IsCalibrated()) {
			new_sensors |= SENSORS_ORIENTATION;
			data->sensors[ID_ORIENTATION].orientation.azimuth = MEMSAlgLib_eCompass_Get_Azimuth();  
			MEMSAlgLib_eCompass_GetCalibration(&MAGOFFX2,&MAGOFFY2,&MAGOFFZ2);

			if( (MAGOFFX1!=MAGOFFX2) || (MAGOFFY1!=MAGOFFY2) || (MAGOFFZ1!=MAGOFFZ2) ) 
      {
        LOGD_IF(1, "CALIBRATION: %d %d %d %d %d %d\n", MAGOFFX1, MAGOFFY1, MAGOFFZ1,MAGOFFX2, MAGOFFY2, MAGOFFZ2);
				write_sensor_calibration_data(MAGOFFX2, MAGOFFY2, MAGOFFZ2);//platform related API
			}
		}

		data->sensors[ID_ORIENTATION].orientation.pitch = MEMSAlgLib_eCompass_Get_Pitch();  
		data->sensors[ID_ORIENTATION].orientation.roll = -MEMSAlgLib_eCompass_Get_Roll();   

		if(MEMSAlgLib_eCompass_IsCalibrated())
			set_delay(25);  
		else
			set_delay(100);
	}

	if (new_sensors) {
		data->pendingSensors = new_sensors;
		return pick_sensor(data, values);
	}

	return -1;
}
static void native_releaseCustomFunction(JNIEnv* env, jobject object, jint ref)
{
    LOGD_IF(DEBUG_JNI, "native_releaseCustomFunction %d", ref);
    env->DeleteGlobalRef((jobject)ref);
}
Пример #30
0
sp<GraphicBuffer> Layer::requestBuffer(int index,
        uint32_t reqWidth, uint32_t reqHeight, uint32_t reqFormat,
        uint32_t usage)
{
    sp<GraphicBuffer> buffer;

    if (int32_t(reqWidth | reqHeight | reqFormat) < 0)
        return buffer;

    if ((!reqWidth && reqHeight) || (reqWidth && !reqHeight))
        return buffer;

    // this ensures our client doesn't go away while we're accessing
    // the shared area.
    ClientRef::Access sharedClient(mUserClientRef);
    SharedBufferServer* lcblk(sharedClient.get());
    if (!lcblk) {
        // oops, the client is already gone
        return buffer;
    }

    /*
     * This is called from the client's Surface::dequeue(). This can happen
     * at any time, especially while we're in the middle of using the
     * buffer 'index' as our front buffer.
     */

    status_t err = NO_ERROR;
    uint32_t w, h, f;
    { // scope for the lock
        Mutex::Autolock _l(mLock);

        // zero means default
        if (!reqFormat) reqFormat = mFormat;
        if (!reqWidth)  reqWidth = mWidth;
        if (!reqHeight) reqHeight = mHeight;

        w = reqWidth;
        h = reqHeight;
        f = reqFormat;

        if ((reqWidth != mReqWidth) || (reqHeight != mReqHeight) ||
                (reqFormat != mReqFormat)) {
            mReqWidth  = reqWidth;
            mReqHeight = reqHeight;
            mReqFormat = reqFormat;

            lcblk->reallocateAllExcept(index);
        }
    }

    // here we have to reallocate a new buffer because the buffer could be
    // used as the front buffer, or by a client in our process
    // (eg: status bar), and we can't release the handle under its feet.
    const uint32_t effectiveUsage = getEffectiveUsage(usage);
    buffer = new GraphicBuffer(w, h, f, effectiveUsage);
    err = buffer->initCheck();

    if (err || buffer->handle == 0) {
        LOGE_IF(err || buffer->handle == 0,
                "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d failed (%s)",
                this, index, w, h, strerror(-err));
    } else {
        LOGD_IF(DEBUG_RESIZE,
                "Layer::requestBuffer(this=%p), index=%d, w=%d, h=%d, handle=%p",
                this, index, w, h, buffer->handle);
    }

    if (err == NO_ERROR && buffer->handle != 0) {
        Mutex::Autolock _l(mLock);
        mBufferManager.attachBuffer(index, buffer);
    }
    return buffer;
}