@Override public void onUEvent(UEventObserver.UEvent event) { String sensorName; int sensorTemp, errorVal, eventType = -1; ThermalZone zone; if (mThermalSensors == null) return; // Name of the sensor and current temperature are mandatory parameters of an UEvent sensorName = event.get("NAME"); sensorTemp = Integer.parseInt(event.get("TEMP")); // eventType is an optional parameter. so, check for null case if (event.get("EVENT") != null) eventType = Integer.parseInt(event.get("EVENT")); if (sensorName != null) { Log.i(TAG, "UEvent received for sensor:" + sensorName + " temp:" + sensorTemp); // check the name against the first sensor ThermalSensor sensor = mThermalSensors.get(0); if (sensor != null && sensor.getSensorName() != null && sensor.getSensorName().equalsIgnoreCase(sensorName)) { // Adjust the sensor temperature based on the 'error correction' temperature. // For 'LOW' event, debounce interval will take care of this. errorVal = sensor.getErrorCorrectionTemp(); if (eventType == ThermalManager.THERMAL_HIGH_EVENT) sensorTemp += errorVal; if (isZoneStateChanged(sensor, sensorTemp)) { sendThermalEvent(); // reprogram threshold programThresholds(sensor); } } } }
public void programThresholds(ThermalSensor s) { if (s == null) return; int zoneState = getZoneState(); if (zoneState == ThermalManager.THERMAL_STATE_OFF) return; int lowerTripPoint = ThermalUtils.getLowerThresholdTemp(zoneState, getZoneTempThreshold()); int upperTripPoint = ThermalUtils.getUpperThresholdTemp(zoneState, getZoneTempThreshold()); if (lowerTripPoint != ThermalManager.INVALID_TEMP && upperTripPoint != ThermalManager.INVALID_TEMP) { if (ThermalUtils.writeSysfs(s.getSensorLowTempPath(), lowerTripPoint) == -1) { Log.i( TAG, "error while programming lower trip point:" + lowerTripPoint + "for sensor:" + s.getSensorName()); } if (ThermalUtils.writeSysfs(s.getSensorHighTempPath(), upperTripPoint) == -1) { Log.i( TAG, "error while programming upper trip point:" + upperTripPoint + "for sensor:" + s.getSensorName()); } } }
/** * Function that calculates the state of the Thermal Zone after reading temperatures of all * sensors in the zone. This function is used when a zone operates in polling mode. */ public boolean isZoneStateChanged() { for (ThermalSensor ts : mThermalSensors) { if (ts.getSensorActiveStatus()) { ts.updateSensorTemp(); } } return updateZoneParams(); }
private void printSensors() { if (mThermalSensors == null) return; StringBuilder s = new StringBuilder(); for (ThermalSensor ts : mThermalSensors) { if (ts != null) { s.append(ts.getSensorName()); s.append(","); } } Log.i(TAG, "zoneID: " + mZoneID + " sensors mapped:" + s.toString()); }
public void registerUevent() { int indx; if (mThermalSensors == null) return; if (mThermalSensors.size() > 1) { Log.i(TAG, "for zone:" + getZoneName() + " in uevent mode only first sensor used!"); } ThermalSensor sensor = mThermalSensors.get(0); if (sensor == null) return; String path = sensor.getUEventDevPath(); if (path.equalsIgnoreCase("invalid")) return; // first time update of sensor temp and zone temp sensor.updateSensorTemp(); setZoneTemp(sensor.getCurrTemp()); if (updateZoneParams()) { // first intent after initialization sendThermalEvent(); } mUEventObserver.startObserving(path); programThresholds(sensor); }
@Override public void onResume() { super.onResume(); OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback); for (int i = 0; i < 480; i++) { for (int j = 0; j < 640; j++) { data[i][j] = (float) -5000.0; } } if (mThermal.start(this)) { hasThermal = true; } else { hasThermal = false; } }
public Mat onCameraFrame(Mat inputFrame) { if (takeScanBase) { if (scanBase != null) { scanBase.release(); } scanBase = new Mat(); scanningMat = new Mat(); Imgproc.cvtColor(inputFrame, scanBase, Imgproc.COLOR_RGB2GRAY); Imgproc.cvtColor(scanBase, scanningMat, Imgproc.COLOR_GRAY2RGB); scanBase.release(); hasScanBase = true; takeScanBase = false; } if (hasScanBase) { Mat ret; Point p = findLaser(inputFrame); inputFrame.release(); if (p != null) { if (hasThermal) { double temp = mThermal.read(); data[(int) p.y][(int) p.x] = (float) temp; Core.circle(scanningMat, p, 3, new Scalar(255, 0, 0), -3); } else { // Log.v(TAG, "No thermal!"); } } return scanningMat; } else return inputFrame; }
@Override public void onPause() { if (hasThermal) mThermal.stop(); if (mOpenCvCameraView != null) mOpenCvCameraView.disableView(); super.onPause(); }
/** * Function that calculates the state of the Thermal Zone after reading temperatures of all * sensors in the zone. This is an overloaded function used when a zone supports UEvent * notifications from kernel. When a sensor sends an UEvent, it also sends its current temperature * as a parameter of the UEvent. */ public boolean isZoneStateChanged(ThermalSensor s, int temp) { if (s == null) return false; s.setCurrTemp(temp); setZoneTemp(temp); return updateZoneParams(); }
public void computeZoneActiveStatus() { // init again. needed because of a profile change mIsZoneActive = false; if (mSupportsUEvent) { // Zone de-activated when any threshold for that zone is // above the allowed Max threshold. if (mMaxThreshExceeded == true) { Log.i( TAG, "deactivate zone:" + mZoneName + ". Zone Threshold exceeds max trip temp:" + mTripMax); mIsZoneActive = false; return; } } if (mZoneTempThresholds == null) { Log.i(TAG, "deactivate zone:" + getZoneName() + " threshold list is NULL! "); mIsZoneActive = false; return; } // 1. minimum number of states supported must be DEFAULT NUM STATES // 2. if sensor list null disable zone if (mMaxStates < ThermalManager.DEFAULT_NUM_ZONE_STATES) { // substract by 1 since TOFF is transparent to USER int minStateSupport = ThermalManager.DEFAULT_NUM_ZONE_STATES - 1; Log.i(TAG, "deactivate zone:" + getZoneName() + " supports < " + minStateSupport + " states"); mIsZoneActive = false; return; } if (mThermalSensors == null) { Log.i(TAG, "deactivate zone:" + getZoneName() + " sensor list null! "); mIsZoneActive = false; return; } if (mSupportsUEvent) { // if uevent just check the first sensor ThermalSensor s = mThermalSensors.get(0); if (s != null && s.getSensorActiveStatus()) { mIsZoneActive = true; return; } } else { if (mPollDelay == null) { Log.i(TAG, "deactivate zone:" + getZoneName() + " polldelay list null in poll mode! "); mIsZoneActive = false; return; } if (mZoneTempThresholds.length != mPollDelay.length) { Log.i( TAG, "deactivate zone:" + getZoneName() + " mismatch of polldelay and threshold list in polling mode!"); mIsZoneActive = false; return; } for (ThermalSensor ts : mThermalSensors) { if (ts != null && ts.getSensorActiveStatus()) { mIsZoneActive = true; return; } } } }