cleanflight / cleanflight

Clean-code version of the baseflight flight controller firmware
http://cleanflight.com
GNU General Public License v3.0
2.6k stars 1.39k forks source link

Invert Buzzer pin output state via mode switch setting? Buzzer pin high at audio frequency? #822

Closed ctzsnooze closed 9 years ago

ctzsnooze commented 9 years ago

Hi

I was wondering if there could be an option in the Modes section titled 'inverse beeper', so that with a switch I could invert the logical output of the buzzer pin? And maybe also, the ability to (optionally) oscillate the beeper output at a user-defined frequency?

Originally I think the intention for buzzer pin was that high = alarm (LEDs flash, buzzer on) and low = normal (LEDs and buzzer off). And currently an active buzzer is required.

For many quad flyers, especially those who fly at night, in low light, or indoors, a very common usage is to invert the behaviour so that LEDs are normally on all the time, and that they flash when battery is low etc. Typically a small FET is used to ground the LEDs when the pin is high.

However there are times when a quad flyer prefers to be 'stealthy' i.e. have the inverse (traditional normal) operation back again, so that their LEDs are off all the time and only flash on when there is a problem. At the moment the user must set the hardware explicitly one way or the other. It would be great if the software could invert the buzzer pin function so it became hardware independent - and even better if the behaviour could be dynamically controlled via a Tx switch using a Mode range. That would be GREAT!

Additionally, while thinking about the buzzer pin, I was wondering if there could be a CLI option to oscillate it, when active, at a 50% duty cycle at user-specified frequency value set in the CLI?

This would allow the use of simple 'passive' piezo buzzers, which can be lighter and more compact than active buzzers. It would also allow strobing of the LEDs when active.... :-) With mode switches enabling or disabling these options a huge range of possibilities arise.

Passive piezos often have a natural oscillation frequency of 4kHz - very high, not always easy to hear - and output is very frequency dependent. Ideally the user can set the frequency in the CLI to whatever works best. If so, zero would mean fixed behaviour, but any integer value could then set the frequency in Hz up to say 4096 or something.

If the allowed frequency range was to include low frequencies, such as 2-10Hz for example, when active the LEDs could be configured to flash like a strobe, rather than be continuously on or off. This would actually be useful with LED only installations when flying in very low light. For example, if you rely on the LEDs to for LOS flying in such conditions, it can be disconcerting to have all LEDs off during 'alarm high' period - even though only off during the flashes, orientation information is greatly reduced. On the other hand, if the off time had a flashing behaviour at high frequency, you could still detect the alarm yet retain orientation.

Finally, if it was possible to flash the buzzer pin at a custom frequency as described above, it would be cool to include a Mode switch option to disable that flashing. Users could then experiment with whether or not the flashing was an advantage, or turn it on to enable visibility, or turn it on to enable/disable passive piezo buzzer functionality.

Just these three suggestions would enable passive piezo buzzers, LEDs normally on or normally off but with visual alarms either way, switches to have the LEDs flash fast for alarms, or buzz or not buzz for alarms, whatever.

So to summarise, I'd be really grateful for the following:

  1. An 'Invert Beeper' Mode switch (the most helpful thing imo)
  2. A buzzer_pin_frequency setting in CLI, default 0 (i.e. normal not flashing behaviour)
  3. If 2 is implemented, a a 'Beeper Constant' Mode switch ability to override the buzzer_pin_frequency (i.e. forces it to zero, disables it)

With these options people would suddenly have a huge amount of creative flexibility in their LED and buzzer implementations.

Thanks for thinking about this! If audio frequency cycling of the buzzer is difficult for timing reasons, that's OK, but maybe slower frequency cycling to strobe the buzzer might be possible.

Chris

hydra commented 9 years ago

feature requests should be consice and to the point, there are too many topics for one request in here which will result in fragmented discussion and an issue that is not easy to follow. They should request one thing and describe why the thing is needed.

I will close this issue with the following comments:

  1. yes that's posible, open a new issue for this.
  2. that requires the use of a timer on the pin the buzzer is connected to but there are no free timers for this. there may be other ways of doing it but not that would fit very well with the current code, so not possible at this time.
  3. an LED overhaul is due, it could work similar to how the current buzzer code works, you could open an issue for this.
ctzsnooze commented 9 years ago

OK cool thanks, good points, will do.