@@ -164,7 +164,7 @@ void AP_Relay::convert_params()
164
164
const bool have_default = AP_Param::get_param_by_index (this , 4 , AP_PARAM_INT8, &default_state);
165
165
166
166
// grab the old values if they were set
167
- for (uint8_t i = 0 ; i < MIN (AP_RELAY_NUM_RELAYS, 6 ); i++) {
167
+ for (uint8_t i = 0 ; i < MIN (ARRAY_SIZE (_params), 6U ); i++) {
168
168
if (_params[i].function .configured ()) {
169
169
// Conversion already done, or user has configured manually
170
170
continue ;
@@ -235,7 +235,7 @@ void AP_Relay::set_defaults() {
235
235
RELAY5_PIN_DEFAULT,
236
236
RELAY6_PIN_DEFAULT };
237
237
238
- for (uint8_t i = 0 ; i < MIN (uint8_t (AP_RELAY_NUM_RELAYS ), ARRAY_SIZE (pins)); i++) {
238
+ for (uint8_t i = 0 ; i < MIN (ARRAY_SIZE (_params ), ARRAY_SIZE (pins)); i++) {
239
239
// set the default
240
240
if (pins[i] != -1 ) {
241
241
_params[i].pin .set_default (pins[i]);
@@ -250,7 +250,7 @@ void AP_Relay::init()
250
250
convert_params ();
251
251
252
252
// setup the actual default values of all the pins
253
- for (uint8_t instance = 0 ; instance < AP_RELAY_NUM_RELAYS ; instance++) {
253
+ for (uint8_t instance = 0 ; instance < ARRAY_SIZE (_params) ; instance++) {
254
254
const int8_t pin = _params[instance].pin ;
255
255
if (pin == -1 ) {
256
256
// no valid pin to set it on, skip it
@@ -285,7 +285,7 @@ void AP_Relay::set(const AP_Relay_Params::FUNCTION function, const bool value) {
285
285
return ;
286
286
}
287
287
288
- for (uint8_t instance = 0 ; instance < AP_RELAY_NUM_RELAYS ; instance++) {
288
+ for (uint8_t instance = 0 ; instance < ARRAY_SIZE (_params) ; instance++) {
289
289
if (function != _params[instance].function ) {
290
290
continue ;
291
291
}
@@ -324,7 +324,7 @@ void AP_Relay::set_pin_by_instance(uint8_t instance, bool value)
324
324
325
325
void AP_Relay::set (const uint8_t instance, const bool value)
326
326
{
327
- if (instance >= AP_RELAY_NUM_RELAYS ) {
327
+ if (instance >= ARRAY_SIZE (_params) ) {
328
328
return ;
329
329
}
330
330
@@ -337,15 +337,15 @@ void AP_Relay::set(const uint8_t instance, const bool value)
337
337
338
338
void AP_Relay::toggle (uint8_t instance)
339
339
{
340
- if (instance < AP_RELAY_NUM_RELAYS ) {
340
+ if (instance < ARRAY_SIZE (_params) ) {
341
341
set (instance, !get (instance));
342
342
}
343
343
}
344
344
345
345
// check settings are valid
346
346
bool AP_Relay::arming_checks (size_t buflen, char *buffer) const
347
347
{
348
- for (uint8_t i=0 ; i<AP_RELAY_NUM_RELAYS ; i++) {
348
+ for (uint8_t i=0 ; i<ARRAY_SIZE (_params) ; i++) {
349
349
const int8_t pin = _params[i].pin .get ();
350
350
if (pin != -1 && !hal.gpio ->valid_pin (pin)) {
351
351
char param_name_buf[14 ];
@@ -364,7 +364,7 @@ bool AP_Relay::arming_checks(size_t buflen, char *buffer) const
364
364
365
365
bool AP_Relay::get (uint8_t instance) const
366
366
{
367
- if (instance >= AP_RELAY_NUM_RELAYS ) {
367
+ if (instance >= ARRAY_SIZE (_params) ) {
368
368
// invalid instance
369
369
return false ;
370
370
}
@@ -383,13 +383,13 @@ bool AP_Relay::get(uint8_t instance) const
383
383
bool AP_Relay::enabled (uint8_t instance) const
384
384
{
385
385
// Must be a valid instance with function relay and pin set
386
- return (instance < AP_RELAY_NUM_RELAYS ) && (_params[instance].pin != -1 ) && (_params[instance].function == AP_Relay_Params::FUNCTION::RELAY);
386
+ return (instance < ARRAY_SIZE (_params) ) && (_params[instance].pin != -1 ) && (_params[instance].function == AP_Relay_Params::FUNCTION::RELAY);
387
387
}
388
388
389
389
// see if the relay is enabled
390
390
bool AP_Relay::enabled (AP_Relay_Params::FUNCTION function) const
391
391
{
392
- for (uint8_t instance = 0 ; instance < AP_RELAY_NUM_RELAYS ; instance++) {
392
+ for (uint8_t instance = 0 ; instance < ARRAY_SIZE (_params) ; instance++) {
393
393
if ((_params[instance].function == function) && (_params[instance].pin != -1 )) {
394
394
return true ;
395
395
}
@@ -408,7 +408,7 @@ bool AP_Relay::send_relay_status(const GCS_MAVLINK &link) const
408
408
409
409
uint16_t present_mask = 0 ;
410
410
uint16_t on_mask = 0 ;
411
- for (auto i=0 ; i<AP_RELAY_NUM_RELAYS ; i++) {
411
+ for (uint8_t i=0 ; i<ARRAY_SIZE (_params) ; i++) {
412
412
if (!enabled (i)) {
413
413
continue ;
414
414
}
0 commit comments