Reputation: 1409
I want to turn the LED flash for the camera of an Android smartphone very fast on/off, and I was wondering if anyone knows about hardware/OS limitation specifications?
The flash light software I've used so far on my Samsung GT s7580 seemed to have pretty big latency when I tried to switch on and off, and the application I want to make needs to keep the light open for a 10th of a second...
Am I barking up the wrong tree?
Upvotes: 4
Views: 2864
Reputation: 172
I was wondering the same thing, and I got a time that varied between about 2.5 and 3 seconds for 50 on/off cycles in a Samsung Galaxy Ace 3 GT-S7275Y I used the deprecated Camera object and the code I used is pasted below:
Camera cam;
Camera.Parameters p;
public void turnOnFlashLight() {
if (cam != null) {
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
}
}
public void turnOffFlashLight() {
if (cam != null) {
p.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
cam.setParameters(p);
}
}
public void prepareCamera() {
if (cam == null) {
try {
cam = Camera.open();
p = cam.getParameters();
if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
p.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
cam.setParameters(p);
cam.startPreview();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getBaseContext(), "Exception throws in turning on flashlight.", Toast.LENGTH_SHORT).show();
}
}
}
public void flashSpeedTest(View v) {
prepareCamera();
long startTm = System.nanoTime();
for (int x = 0; x < 100; ++x) {
if (x % 2 == 0)
turnOnFlashLight();
else
turnOffFlashLight();
}
long elapsed = System.nanoTime() - startTm;
Misc.showMessage(this, String.format("%.3f seconds", elapsed/1e9));
}
Upvotes: 4
Reputation: 35950
I just tested LED Strobe app from the Google play, and at its fastest setting it's giving me a pretty rapid on/off cycle. I'd say it's close to 10 fps. Some flashes are bright, some are dimmer (but still visible) - it could be related to the power inefficiencies for such a fast cycle.
Anyway, I don't think you can guarantee 10 fps, it'd be dependent on any of the: phone model, LED module, power connection to the LED, battery power level. In my case, I tested it on Moto X 1st gen.
Upvotes: 1