I'm currently working on a Visible Light Communication project and need some help to programm a fast blinking (>200Hz) LED Flashlight. My device is a HUAWEI CUN-L21 with firmware B115 and it is also rooted.
I already programmed an app using Android SDK that turns the Flashlight on and off with a specific delay using Thread.sleep(delay). The problem is, that even if I set the delay to just a few milliseconds, the max. frequency I get is around 35Hz which is too low.
I also tried to blink it fast via the timer trigger in shell. But the frequency was to low as well.
So here is my question: Is there any other way to get the LED to blink in a frequency of 200 Hz? Do I have to modify the LED driver in the kernelspace? And if so, how can I do that?
I managed to blink the LED via the timer trigger in shell with delay_on = 1ms and delay_off = 1 ms. So the frequency theoretically had to be 500 Hz. But somehow the LED doesn't blink constant. In the picture below, one can see, that after 10ms the LED stops to blink. To me it looks like some kind of PWM.
Measurement of the blinking frequency
So the LED is able to blink with a delay_on = delay_off = 1ms. But is there a way to get the LED of this smartphone to blink in this frequency for a longer period? Why does it stop after 10ms. Is there some kind of restriction, that is deeper than the LED driver in kernelspace?
Related
Imagine an Android device (possibly any device from any manufacturer) that is connected via bluetooth to a speaker (or any bluetooth audio device)... and there has been a "significant" amount of time where no audio has been played from the device.
At the moment audio resumes playing from this device, there is more often than not a "speaker is slowly waking up" phase where no audio is heard and the audio is late to become audible.
This is less obvious when the audio is being "kept alive" with constant audio, or only taking short breaks of silence, but what if you have an application that makes very short and intermittent sounds at unpredictable times... like an alarm that measures environmental conditions with a sensor?
I'm not sure if:
A) This behavior is some kind of power-saving feature of the output device and we would have no control over it other than to play some kind of fake audio/silence prior to our desired sound... or have a low-volume sound/white noise on a constant loop... in order to pre-empt/prevent the "warm up."
B) It's part of the bluetooth protocol/standard/definition
C) It's controllable in software with something like (on Android):
bluetooth.setMode(BluetoothMode.NO_NAPPING_ALLOWED);
I'm hoping the case is (C), and if so, then what is the proper code for this?
I'm sure there is a similar question out there that is asked in a different way, but I can't find it, and I have searched through the documentation for AudioManager and although bluetooth is mentioned in many places, I can't find this functionality.
For fun, I accessed developer options on my phone and picked the option to keep the device awake. I also tried to disable any battery optimization.
My SONY XB-900 headphones turned off after some minutes of silence, my cheapo Monster headphones did not turn off, and a cheapo Bluetooth Speaker did not turn off.
I repeated the same thing on Windows, exactly the same results.
Then I searched on some forums, using the keywords "Bluetooth" "prevent" "awake" "power saving" "standby" "disconnected" "annoying" and "silence".
This commenter told something interesting:
I read that sony SRS-X1 bluetooth speaker doesn't cut off bluetooth
audio connection after a period of inactivity. It just enters standby
mode which it takes about 0.1 second to exit when audio signals
arrive. So, you can lose 0.1 second of audio when audio is played
after a period of inactivity. However, you can prevent it from
entering standby mode by playing 20Hz noise continuously. Speakers
cannot react to 20Hz noise, so 20Hz noise is silent.
This makes me believe that is a pure playback device-side implementation, and the OS nor Bluetooth have anything to do with it. The fact that you did not find any documentation about it supports the theory. Looks like the solution is the one you already mentioned: Play a very low or very high frequency on loop to keep the device awake.
I am running a simple application that receives
and displays the values of Bluetooth Low Energy
advertisement packets in real time.
The Glass heats up in about 5 minutes and touch
commands stop working. The Glass is not super
hot, but warmer than feels comfortable.
Commenting out the Bluetooth stuff reduces the
heating considerably.
How can I make this application workable on the
Glass?
Without seeing the exact code you're using it is difficult to diagnose, but from your description we might be able to make a guess.
It sounds like you're using BluetoothAdapter.startLeScan() without setting up a timeout to stop the scan, and then scanning for an extended period of time. The documentation at http://developer.android.com/guide/topics/connectivity/bluetooth-le.html#find points out:
Because scanning is battery-intensive, you should observe the
following guidelines:
As soon as you find the desired device, stop scanning.
Never scan on a
loop, and set a time limit on your scan. A device that was previously
available may have moved out of range, and continuing to scan drains
the battery.
Battery drains typically correspond to Glass overheating.
There isn't a lot you can do to solve the problem, but it may involve changing how you think about what you're doing.
If you're doing this in immersion mode, you may want to switch it to a live card instead. You may also not really want to scan "forever", but may want to try scanning for a fairly short period of time, then turning it off for a short period of time, and repeating this. Or you may want to turn it off for a period of time once a new packet is received. Your exact needs may dictate this, but given the characteristics of how often advertisement packets are sent out, you may not need to be constantly listening to get all of the packets.
As a current Glass developer myself, I've found that there isn't really any good way around this.
We're all facing this problem. There isn't much room, every is tightly packed, and what Glass is having to do is complicated. It will heat up if you are constantly scanning. Especially when you are taking videos - Glass will become very hot.
I found that lowering the screen brightness helps a bit, at least with the battery life, if nothing else.
This is how you set the screen brightness to its minimum, in case you do want to try it and see if it helps:
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 0f;
getWindow().setAttributes(lp);
I'm currently investigating workarounds for this heat problem as well. Glass overheats quickly when capturing previews and doing heavy calculations or image processing on it.
This paper is very informative:
http://arxiv.org/pdf/1404.1320v1.pdf
Title: "Draining our Glass: An Energy and Heat
Characterization of Google Glass"
How do you fire the iblazr programmatically?
No API I can find, they're not responding to inquiry.
I'm looking for a solution for iPhone and Android.
Since you have to enable the flash device with the media volume at max, I suspected it must have something to do with the volume output that triggers it.
So, I plugged it in, started my music player, and it started flashing to the music for the most part.
Turning down the volume stopped the flashing and turning it back up caused the LED to again start flashing.
Based on that I would assume you simply have to output a loud audio clip to turn it on while the media volume is set to max.
Update:
After experimenting on my theory, the device I have (iblazr compatible 16 LED Chinese version), the frequency of the tone is the key and determines the brightness. Using the Windows API Beep(frequency, duration) function, the light first turns on at a frequency of 6500 and gets brighter as the frequency increases. Seems like it is pretty bright at 7000!
They finally published it here:
https://github.com/ConcepterDev/iblazr-original-protocol
You can control the original iblazr by sending the specified tone for the specified duration to the headphone jack:
function frequency (Hz) duration
----------------------------------------------
wake iblazr 800 200±150ms
flash 15750 300ms (auto)
pre-flash 10000 until focused
constant light 2500-9500 infinite
Is it possible to make flash blink on ringtone, according to the beats of a song set as ringtone on phone in android.If yes then please give me a hint.
Yes and no. I've once written a FFT for acceleration sensor data of the devices. This was to find out what step frequence a user is running.
You can do FFT on an Android phone. I used the Apache Commons Math library for it.
Easiest starting point is to have WAV or FLAC Audio files as they do not have compressions or the like in it. You can straight do the FFT on them.
In my running app it takes about 1-2 seconds(!) to calculate one FFT for 512 input values, utilizing the CPU for 100% and draining the battery correspondingly. So I do the FFT only once a minute.
I can assume, that the user would see this, when the telephone rings:
No blinking light, just sound for the first view seconds (while you do the FFT)
The blinking light with the frequence of the beats but not in sync with them (you're showing the beats of a past time period)
But I must admit, that I really like the idea. Let me know, when you're out with your App :-)
I am trying to write a variable brightness flashlight app by using PWM (might use it for communication later). For that I need fast switching of the camera LED (say 100-200Hz), which is not possible through the Camera API's setParameters functionality (I guess the camera itself slows things down considerably).
Now – The LED is capable of switching rapidly and there are apps doing something similar (HTC flashlight for example, unfortunately couldn't find source code for it) so it all comes down to controlling the LED without the camera.
Any thoughts or ideas?
I know this is 4 years later, but you'd need a lot more than 100-200hz for PWM to work properly, without irritating the eye. You might get some control, but you won't be able to get 10% brightness without the pulses becoming noticeable, and even then, the duration of those pulses is too long to fool the eye. Typically PWM is handled at the microsecond level, around 100khz. I would like this to be possible as well. Except, if we could have say a 100khz carrier frequency in the flash, it would be possible to calculate distance to a subject with dedicated pixels in the sensor, as well as reject all ambient light through demodulation, if all pixels could be scanned fast enough. Sadly not possible though.
Normally to do that there'll be a PWM peripheral in the processor that handles the rapid switching for you, but that would need driver support; it won't be accessible to user applications. Here's a question which uses the driver to do it: Set brightness of flash in Android