From 18d5a373c08ffed5d632fc4821393280bde33f79 Mon Sep 17 00:00:00 2001 From: jflyper Date: Fri, 16 Feb 2018 10:22:50 +0900 Subject: [PATCH] Separation of boxId and permanentId. --- src/main/fc/rc_modes.h | 2 ++ src/main/interface/msp_box.c | 23 ++++++++++++++--------- src/main/interface/msp_box.h | 2 ++ src/main/interface/settings.c | 2 +- src/main/io/piniobox.c | 19 +++++++++---------- src/main/pg/piniobox.c | 5 +++-- src/main/pg/piniobox.h | 4 +--- 7 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/main/fc/rc_modes.h b/src/main/fc/rc_modes.h index 12b2966f2..45380d00c 100644 --- a/src/main/fc/rc_modes.h +++ b/src/main/fc/rc_modes.h @@ -21,6 +21,8 @@ #include "pg/pg.h" +#define BOXID_NONE 255 + typedef enum { // ARM flag BOXARM = 0, diff --git a/src/main/interface/msp_box.c b/src/main/interface/msp_box.c index d515af525..b5b2c7e39 100644 --- a/src/main/interface/msp_box.c +++ b/src/main/interface/msp_box.c @@ -270,15 +270,20 @@ void initActiveBoxIds(void) // Turn BOXUSERx only if pinioBox facility monitors them, as the facility is the only BOXUSERx observer. // Note that pinioBoxConfig can be set to monitor any box. for (int i = 0; i < PINIO_COUNT; i++) { - switch(pinioBoxConfig()->boxId[i]) { - case BOXUSER1: - case BOXUSER2: - case BOXUSER3: - case BOXUSER4: - BME(pinioBoxConfig()->boxId[i]); - break; - default: - break; + if (pinioBoxConfig()->permanentId[i] != PERMANENT_ID_NONE) { + const box_t *box = findBoxByPermanentId(pinioBoxConfig()->permanentId[i]); + if (box) { + switch(box->boxId) { + case BOXUSER1: + case BOXUSER2: + case BOXUSER3: + case BOXUSER4: + BME(box->boxId); + break; + default: + break; + } + } } } #endif diff --git a/src/main/interface/msp_box.h b/src/main/interface/msp_box.h index 711f6ccb0..0a9025c12 100644 --- a/src/main/interface/msp_box.h +++ b/src/main/interface/msp_box.h @@ -25,6 +25,8 @@ typedef struct box_s { const uint8_t permanentId; // permanent ID used to identify BOX. This ID is unique for one function, DO NOT REUSE IT } box_t; +#define PERMANENT_ID_NONE 255 + const box_t *findBoxByBoxId(boxId_e boxId); const box_t *findBoxByPermanentId(uint8_t permanentId); diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index c4cd25c9f..038c97faf 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -874,7 +874,7 @@ const clivalue_t valueTable[] = { #ifdef USE_PINIO { "pinio_config", VAR_UINT8 | MASTER_VALUE | MODE_ARRAY, .config.array.length = PINIO_COUNT, PG_PINIO_CONFIG, offsetof(pinioConfig_t, config) }, #ifdef USE_PINIOBOX - { "pinio_box", VAR_INT8 | MASTER_VALUE | MODE_ARRAY, .config.array.length = PINIO_COUNT, PG_PINIOBOX_CONFIG, offsetof(pinioBoxConfig_t, boxId) }, + { "pinio_box", VAR_UINT8 | MASTER_VALUE | MODE_ARRAY, .config.array.length = PINIO_COUNT, PG_PINIOBOX_CONFIG, offsetof(pinioBoxConfig_t, permanentId) }, #endif #endif }; diff --git a/src/main/io/piniobox.c b/src/main/io/piniobox.c index eb1349ff1..36df31b07 100644 --- a/src/main/io/piniobox.c +++ b/src/main/io/piniobox.c @@ -33,21 +33,20 @@ #include "piniobox.h" -static pinioBoxConfig_t pinioBoxRuntimeConfig; +typedef struct pinioBoxRuntimeConfig_s { + uint8_t boxId[PINIO_COUNT]; +} pinioBoxRuntimeConfig_t; + +static pinioBoxRuntimeConfig_t pinioBoxRuntimeConfig; void pinioBoxInit(const pinioBoxConfig_t *pinioBoxConfig) { // Convert permanentId to boxId_e - pinioBoxRuntimeConfig = *pinioBoxConfig; - for (int i = 0; i < PINIO_COUNT; i++) { - if (pinioBoxRuntimeConfig.boxId[i] >= 0) { - const box_t *box = findBoxByPermanentId(pinioBoxRuntimeConfig.boxId[i]); - if (box) { - pinioBoxRuntimeConfig.boxId[i] = box->boxId; - } - } + const box_t *box = findBoxByPermanentId(pinioBoxConfig->permanentId[i]); + + pinioBoxRuntimeConfig.boxId[i] = box ? box->boxId : BOXID_NONE; } } @@ -56,7 +55,7 @@ void pinioBoxUpdate(timeUs_t currentTimeUs) UNUSED(currentTimeUs); for (int i = 0; i < PINIO_COUNT; i++) { - if (pinioBoxRuntimeConfig.boxId[i] >= 0) { + if (pinioBoxRuntimeConfig.boxId[i] != BOXID_NONE) { pinioSet(i, getBoxIdState(pinioBoxRuntimeConfig.boxId[i])); } } diff --git a/src/main/pg/piniobox.c b/src/main/pg/piniobox.c index b4ccf4de1..47919573c 100644 --- a/src/main/pg/piniobox.c +++ b/src/main/pg/piniobox.c @@ -22,10 +22,11 @@ #include "pg/pg_ids.h" #include "piniobox.h" #include "drivers/io.h" +#include "interface/msp_box.h" -PG_REGISTER_WITH_RESET_TEMPLATE(pinioBoxConfig_t, pinioBoxConfig, PG_PINIOBOX_CONFIG, 0); +PG_REGISTER_WITH_RESET_TEMPLATE(pinioBoxConfig_t, pinioBoxConfig, PG_PINIOBOX_CONFIG, 1); PG_RESET_TEMPLATE(pinioBoxConfig_t, pinioBoxConfig, - { BOXNONE, BOXNONE, BOXNONE, BOXNONE } + { PERMANENT_ID_NONE, PERMANENT_ID_NONE, PERMANENT_ID_NONE, PERMANENT_ID_NONE } ); #endif diff --git a/src/main/pg/piniobox.h b/src/main/pg/piniobox.h index 5782afda2..83b5cb06a 100644 --- a/src/main/pg/piniobox.h +++ b/src/main/pg/piniobox.h @@ -22,9 +22,7 @@ #include "pg/pg.h" typedef struct pinioBoxConfig_s { - int8_t boxId[PINIO_COUNT]; + uint8_t permanentId[PINIO_COUNT]; } pinioBoxConfig_t; PG_DECLARE(pinioBoxConfig_t, pinioBoxConfig); - -#define BOXNONE (-1)