APM:Libraries
ToneAlarm_Disco.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 Mathieu Othacehe. All rights reserved.
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <AP_HAL/AP_HAL.h>
19 #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
22 #include "ToneAlarm_Disco.h"
23 
24 extern const AP_HAL::HAL &hal;
25 
26 using namespace Linux;
27 
29 {
30  // initialy no tune to play
31  tune_num = -1;
32  tune_pos = 0;
33 }
34 
36 {
37  // play startup tune
38  tune_num = 0;
39 
41 
42  return true;
43 }
44 
46 {
47  bebop_out->play_note(0, 0, 0);
48 }
49 
51 {
52  uint32_t cur_time = AP_HAL::millis();
53 
54  if (tune_num != prev_tune_num){
55  tune_changed = true;
56  return true;
57  }
58 
59  if (cur_note != 0){
61  cur_note = 0;
62  prev_time = cur_time;
63  }
64 
65  if ((cur_time - prev_time) > duration){
66  stop();
67  if (tune[tune_num][tune_pos] == '\0'){
68  if (!tune_repeat[tune_num]){
69  tune_num = -1;
70  }
71 
72  tune_pos = 0;
73  tune_comp = true;
74  return false;
75  }
76  return true;
77  }
78 
79  return false;
80 }
81 
82 #endif
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
Definition: AC_PID_test.cpp:14
int32_t prev_tune_num
Definition: ToneAlarm.h:135
uint16_t duration
Definition: ToneAlarm.h:134
static bool tune_repeat[TONE_NUMBER_OF_TUNES]
Definition: ToneAlarm.h:127
RCOutput_Bebop * bebop_out
static RCOutput_Bebop * from(AP_HAL::RCOutput *rcoutput)
uint32_t millis()
Definition: system.cpp:157
uint8_t tune_pos
Definition: ToneAlarm.h:138
uint16_t cur_note
Definition: ToneAlarm.h:133
static const char * tune[TONE_NUMBER_OF_TUNES]
Definition: ToneAlarm.h:126
uint32_t prev_time
Definition: ToneAlarm.h:136
AP_HAL::RCOutput * rcout
Definition: HAL.h:113
void play_note(uint8_t pwm, uint16_t period_us, uint16_t duration_ms)
#define TONEALARM_PWM_POWER