ToneAlarm_Disco.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. Copyright (C) 2016 Mathieu Othacehe. All rights reserved.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <AP_HAL/AP_HAL.h>
  15. #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
  16. #include <AP_HAL_Linux/RCOutput_Bebop.h>
  17. #include <AP_HAL_Linux/RCOutput_Disco.h>
  18. #include "ToneAlarm_Disco.h"
  19. #include <AP_Math/AP_Math.h>
  20. extern const AP_HAL::HAL &hal;
  21. using namespace Linux;
  22. ToneAlarm_Disco::ToneAlarm_Disco(){}
  23. bool ToneAlarm_Disco::init()
  24. {
  25. bebop_out = RCOutput_Disco::from(hal.rcout);
  26. return true;
  27. }
  28. void ToneAlarm_Disco::set_buzzer_tone(float frequency, float volume, uint32_t duration_ms)
  29. {
  30. if (is_zero(frequency) || is_zero(volume)) {
  31. bebop_out->play_note(0, 0, 0);
  32. } else {
  33. bebop_out->play_note(TONEALARM_PWM_POWER, (uint16_t)roundf(frequency), duration_ms);
  34. }
  35. }
  36. #endif