Use permanentId for config, convert to boxId_e at init

This commit is contained in:
jflyper 2018-02-12 15:57:15 +09:00
parent 6557b161aa
commit 45c5d37693
2 changed files with 20 additions and 4 deletions

View File

@ -70,6 +70,7 @@
#include "pg/pg.h" #include "pg/pg.h"
#include "pg/pg_ids.h" #include "pg/pg_ids.h"
#include "pg/pinio.h" #include "pg/pinio.h"
#include "pg/piniobox.h"
#include "pg/rx_pwm.h" #include "pg/rx_pwm.h"
#include "pg/sdcard.h" #include "pg/sdcard.h"
#include "pg/vcd.h" #include "pg/vcd.h"
@ -869,7 +870,9 @@ const clivalue_t valueTable[] = {
// PG_PINIO_CONFIG // PG_PINIO_CONFIG
#ifdef USE_PINIO #ifdef USE_PINIO
{ "pinio_config", VAR_UINT8 | MASTER_VALUE | MODE_ARRAY, .config.array.length = PINIO_COUNT, PG_PINIO_CONFIG, offsetof(pinioConfig_t, config) }, { "pinio_config", VAR_UINT8 | MASTER_VALUE | MODE_ARRAY, .config.array.length = PINIO_COUNT, PG_PINIO_CONFIG, offsetof(pinioConfig_t, config) },
{ "piniobox_config", VAR_INT8 | MASTER_VALUE | MODE_ARRAY, .config.array.length = PINIO_COUNT, PG_PINIOBOX_CONFIG, offsetof(pinioBoxConfig_t, boxId) }, #ifdef USE_PINIOBOX
{ "pinio_box", VAR_INT8 | MASTER_VALUE | MODE_ARRAY, .config.array.length = PINIO_COUNT, PG_PINIOBOX_CONFIG, offsetof(pinioBoxConfig_t, boxId) },
#endif
#endif #endif
}; };

View File

@ -33,11 +33,22 @@
#include "piniobox.h" #include "piniobox.h"
static const pinioBoxConfig_t *config; static pinioBoxConfig_t pinioBoxRuntimeConfig;
void pinioBoxInit(const pinioBoxConfig_t *pinioBoxConfig) void pinioBoxInit(const pinioBoxConfig_t *pinioBoxConfig)
{ {
config = 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;
}
}
}
} }
void pinioBoxUpdate(timeUs_t currentTimeUs) void pinioBoxUpdate(timeUs_t currentTimeUs)
@ -45,7 +56,9 @@ void pinioBoxUpdate(timeUs_t currentTimeUs)
UNUSED(currentTimeUs); UNUSED(currentTimeUs);
for (int i = 0; i < PINIO_COUNT; i++) { for (int i = 0; i < PINIO_COUNT; i++) {
pinioSet(i, getBoxIdState(config->boxId[i])); if (pinioBoxRuntimeConfig.boxId[i] >= 0) {
pinioSet(i, getBoxIdState(pinioBoxRuntimeConfig.boxId[i]));
}
} }
} }