mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-26 01:35:35 +03:00
New feature: digital output for controlling lighting
This commit is contained in:
parent
5515401867
commit
cbada755b1
9 changed files with 153 additions and 1 deletions
1
Makefile
1
Makefile
|
@ -620,6 +620,7 @@ COMMON_SRC = \
|
||||||
flight/pid_autotune.c \
|
flight/pid_autotune.c \
|
||||||
flight/servos.c \
|
flight/servos.c \
|
||||||
io/beeper.c \
|
io/beeper.c \
|
||||||
|
io/lights.c \
|
||||||
io/pwmdriver_i2c.c \
|
io/pwmdriver_i2c.c \
|
||||||
io/serial.c \
|
io/serial.c \
|
||||||
io/serial_4way.c \
|
io/serial_4way.c \
|
||||||
|
|
|
@ -92,6 +92,7 @@
|
||||||
|
|
||||||
#include "io/asyncfatfs/asyncfatfs.h"
|
#include "io/asyncfatfs/asyncfatfs.h"
|
||||||
#include "io/beeper.h"
|
#include "io/beeper.h"
|
||||||
|
#include "io/lights.h"
|
||||||
#include "io/dashboard.h"
|
#include "io/dashboard.h"
|
||||||
#include "io/displayport_msp.h"
|
#include "io/displayport_msp.h"
|
||||||
#include "io/displayport_max7456.h"
|
#include "io/displayport_max7456.h"
|
||||||
|
@ -374,6 +375,9 @@ void init(void)
|
||||||
|
|
||||||
beeperInit(&beeperDevConfig);
|
beeperInit(&beeperDevConfig);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef LIGHTS
|
||||||
|
lightsInit();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_INVERTER
|
#ifdef USE_INVERTER
|
||||||
initInverters();
|
initInverters();
|
||||||
|
|
|
@ -70,6 +70,7 @@ static const box_t boxes[CHECKBOX_ITEM_COUNT + 1] = {
|
||||||
{ BOXCAMERA1, "CAMERA CONTROL 1;", 39 },
|
{ BOXCAMERA1, "CAMERA CONTROL 1;", 39 },
|
||||||
{ BOXCAMERA2, "CAMERA CONTROL 2;", 40 },
|
{ BOXCAMERA2, "CAMERA CONTROL 2;", 40 },
|
||||||
{ BOXCAMERA3, "CAMERA CONTROL 3;", 41 },
|
{ BOXCAMERA3, "CAMERA CONTROL 3;", 41 },
|
||||||
|
{ BOXLIGHTS, "LIGHTS;", 42 },
|
||||||
{ CHECKBOX_ITEM_COUNT, NULL, 0xFF }
|
{ CHECKBOX_ITEM_COUNT, NULL, 0xFF }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -233,6 +234,9 @@ void initActiveBoxIds(void)
|
||||||
activeBoxIds[activeBoxIdCount++] = BOXCAMERA2;
|
activeBoxIds[activeBoxIdCount++] = BOXCAMERA2;
|
||||||
activeBoxIds[activeBoxIdCount++] = BOXCAMERA3;
|
activeBoxIds[activeBoxIdCount++] = BOXCAMERA3;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef LIGHTS
|
||||||
|
activeBoxIds[activeBoxIdCount++] = BOXLIGHTS;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#define IS_ENABLED(mask) (mask == 0 ? 0 : 1)
|
#define IS_ENABLED(mask) (mask == 0 ? 0 : 1)
|
||||||
|
@ -279,6 +283,7 @@ void packBoxModeFlags(boxBitmask_t * mspBoxModeFlags)
|
||||||
CHECK_ACTIVE_BOX(IS_ENABLED(IS_RC_MODE_ACTIVE(BOXAUTOTRIM)), BOXAUTOTRIM);
|
CHECK_ACTIVE_BOX(IS_ENABLED(IS_RC_MODE_ACTIVE(BOXAUTOTRIM)), BOXAUTOTRIM);
|
||||||
CHECK_ACTIVE_BOX(IS_ENABLED(IS_RC_MODE_ACTIVE(BOXKILLSWITCH)), BOXKILLSWITCH);
|
CHECK_ACTIVE_BOX(IS_ENABLED(IS_RC_MODE_ACTIVE(BOXKILLSWITCH)), BOXKILLSWITCH);
|
||||||
CHECK_ACTIVE_BOX(IS_ENABLED(IS_RC_MODE_ACTIVE(BOXHOMERESET)), BOXHOMERESET);
|
CHECK_ACTIVE_BOX(IS_ENABLED(IS_RC_MODE_ACTIVE(BOXHOMERESET)), BOXHOMERESET);
|
||||||
|
CHECK_ACTIVE_BOX(IS_ENABLED(IS_RC_MODE_ACTIVE(BOXLIGHTS)), BOXLIGHTS);
|
||||||
|
|
||||||
memset(mspBoxModeFlags, 0, sizeof(boxBitmask_t));
|
memset(mspBoxModeFlags, 0, sizeof(boxBitmask_t));
|
||||||
for (uint32_t i = 0; i < activeBoxIdCount; i++) {
|
for (uint32_t i = 0; i < activeBoxIdCount; i++) {
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
#include "navigation/navigation.h"
|
#include "navigation/navigation.h"
|
||||||
|
|
||||||
#include "io/beeper.h"
|
#include "io/beeper.h"
|
||||||
|
#include "io/lights.h"
|
||||||
#include "io/dashboard.h"
|
#include "io/dashboard.h"
|
||||||
#include "io/gps.h"
|
#include "io/gps.h"
|
||||||
#include "io/ledstrip.h"
|
#include "io/ledstrip.h"
|
||||||
|
@ -314,6 +315,9 @@ void fcTasksInit(void)
|
||||||
setTaskEnabled(TASK_SERIAL, true);
|
setTaskEnabled(TASK_SERIAL, true);
|
||||||
#ifdef BEEPER
|
#ifdef BEEPER
|
||||||
setTaskEnabled(TASK_BEEPER, true);
|
setTaskEnabled(TASK_BEEPER, true);
|
||||||
|
#endif
|
||||||
|
#ifdef LIGHTS
|
||||||
|
setTaskEnabled(TASK_LIGHTS, true);
|
||||||
#endif
|
#endif
|
||||||
setTaskEnabled(TASK_BATTERY, feature(FEATURE_VBAT) || feature(FEATURE_CURRENT_METER));
|
setTaskEnabled(TASK_BATTERY, feature(FEATURE_VBAT) || feature(FEATURE_CURRENT_METER));
|
||||||
setTaskEnabled(TASK_RX, true);
|
setTaskEnabled(TASK_RX, true);
|
||||||
|
@ -445,6 +449,15 @@ cfTask_t cfTasks[TASK_COUNT] = {
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef LIGHTS
|
||||||
|
[TASK_LIGHTS] = {
|
||||||
|
.taskName = "LIGHTS",
|
||||||
|
.taskFunc = lightsUpdate,
|
||||||
|
.desiredPeriod = TASK_PERIOD_HZ(100), // 100 Hz
|
||||||
|
.staticPriority = TASK_PRIORITY_MEDIUM,
|
||||||
|
},
|
||||||
|
#endif
|
||||||
|
|
||||||
[TASK_BATTERY] = {
|
[TASK_BATTERY] = {
|
||||||
.taskName = "BATTERY",
|
.taskName = "BATTERY",
|
||||||
.taskFunc = taskUpdateBattery,
|
.taskFunc = taskUpdateBattery,
|
||||||
|
|
|
@ -41,7 +41,7 @@ static bool isUsingNAVModes = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
boxBitmask_t rcModeActivationMask; // one bit per mode defined in boxId_e
|
boxBitmask_t rcModeActivationMask; // one bit per mode defined in boxId_e
|
||||||
STATIC_ASSERT(CHECKBOX_ITEM_COUNT <= 32, too_many_box_modes);
|
STATIC_ASSERT(CHECKBOX_ITEM_COUNT <= 33, too_many_box_modes);
|
||||||
|
|
||||||
PG_REGISTER_ARRAY(modeActivationCondition_t, MAX_MODE_ACTIVATION_CONDITION_COUNT, modeActivationConditions, PG_MODE_ACTIVATION_PROFILE, 0);
|
PG_REGISTER_ARRAY(modeActivationCondition_t, MAX_MODE_ACTIVATION_CONDITION_COUNT, modeActivationConditions, PG_MODE_ACTIVATION_PROFILE, 0);
|
||||||
PG_REGISTER(modeActivationOperatorConfig_t, modeActivationOperatorConfig, PG_MODE_ACTIVATION_OPERATOR_CONFIG, 0);
|
PG_REGISTER(modeActivationOperatorConfig_t, modeActivationOperatorConfig, PG_MODE_ACTIVATION_OPERATOR_CONFIG, 0);
|
||||||
|
|
|
@ -56,6 +56,7 @@ typedef enum {
|
||||||
BOXCAMERA1 = 29,
|
BOXCAMERA1 = 29,
|
||||||
BOXCAMERA2 = 30,
|
BOXCAMERA2 = 30,
|
||||||
BOXCAMERA3 = 31,
|
BOXCAMERA3 = 31,
|
||||||
|
BOXLIGHTS = 32,
|
||||||
CHECKBOX_ITEM_COUNT
|
CHECKBOX_ITEM_COUNT
|
||||||
} boxId_e;
|
} boxId_e;
|
||||||
|
|
||||||
|
|
84
src/main/io/lights.c
Normal file
84
src/main/io/lights.c
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
#include "stdbool.h"
|
||||||
|
#include "stdint.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
|
#include "common/utils.h"
|
||||||
|
|
||||||
|
#include "drivers/time.h"
|
||||||
|
#include "drivers/io.h"
|
||||||
|
|
||||||
|
#include "rx/rx.h"
|
||||||
|
|
||||||
|
#include "fc/config.h"
|
||||||
|
#include "fc/rc_controls.h"
|
||||||
|
#include "fc/rc_modes.h"
|
||||||
|
#include "fc/runtime_config.h"
|
||||||
|
|
||||||
|
#include "config/feature.h"
|
||||||
|
|
||||||
|
#include "io/lights.h"
|
||||||
|
|
||||||
|
#ifdef LIGHTS
|
||||||
|
|
||||||
|
static IO_t lightsIO = DEFIO_IO(NONE);
|
||||||
|
static bool lights_on = false;
|
||||||
|
|
||||||
|
#ifdef FAILSAFE_LIGHTS
|
||||||
|
static timeUs_t last_status_change = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool lightsSetStatus(bool status)
|
||||||
|
{
|
||||||
|
if (status != lights_on) {
|
||||||
|
lights_on = status;
|
||||||
|
IOWrite(lightsIO, lights_on);
|
||||||
|
return(true);
|
||||||
|
} else
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lights handler function to be called periodically in loop. Updates lights
|
||||||
|
* state via time schedule.
|
||||||
|
*/
|
||||||
|
void lightsUpdate(timeUs_t currentTimeUs)
|
||||||
|
{
|
||||||
|
UNUSED(currentTimeUs);
|
||||||
|
if (lightsIO) {
|
||||||
|
#ifdef FAILSAFE_LIGHTS
|
||||||
|
if (FLIGHT_MODE(FAILSAFE_MODE) && ARMING_FLAG(WAS_EVER_ARMED)) {
|
||||||
|
bool new_lights_status = lights_on;
|
||||||
|
if (lights_on) {
|
||||||
|
if (currentTimeUs - last_status_change > FAILSAFE_LIGHTS_ON_TIME * 1000)
|
||||||
|
new_lights_status = false;
|
||||||
|
} else {
|
||||||
|
if (currentTimeUs - last_status_change > FAILSAFE_LIGHTS_OFF_TIME * 1000)
|
||||||
|
new_lights_status = true;
|
||||||
|
}
|
||||||
|
if (new_lights_status != lights_on) {
|
||||||
|
lightsSetStatus(new_lights_status);
|
||||||
|
last_status_change = currentTimeUs;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (lightsSetStatus(IS_RC_MODE_ACTIVE(BOXLIGHTS)))
|
||||||
|
last_status_change = currentTimeUs;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
lightsSetStatus(IS_RC_MODE_ACTIVE(BOXLIGHTS));
|
||||||
|
#endif /* FAILSAFE_LIGHTS */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void lightsInit()
|
||||||
|
{
|
||||||
|
lightsIO = IOGetByTag(IO_TAG(LIGHTS));
|
||||||
|
|
||||||
|
if (lightsIO) {
|
||||||
|
IOInit(lightsIO, OWNER_LED, RESOURCE_OUTPUT, 0);
|
||||||
|
IOConfigGPIO(lightsIO, LIGHTS_OUTPUT_MODE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* LIGHTS */
|
41
src/main/io/lights.h
Normal file
41
src/main/io/lights.h
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Cleanflight.
|
||||||
|
*
|
||||||
|
* Cleanflight is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Cleanflight is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/time.h"
|
||||||
|
|
||||||
|
#ifdef LIGHTS
|
||||||
|
|
||||||
|
//#define FAILSAFE_LIGHTS
|
||||||
|
|
||||||
|
#ifndef LIGHTS_OUTPUT_MODE
|
||||||
|
#define LIGHTS_OUTPUT_MODE IOCFG_OUT_PP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FAILSAFE_LIGHTS_ON_TIME
|
||||||
|
#define FAILSAFE_LIGHTS_ON_TIME 100 // ms
|
||||||
|
#endif
|
||||||
|
#ifndef FAILSAFE_LIGHTS_OFF_TIME
|
||||||
|
#define FAILSAFE_LIGHTS_OFF_TIME 900 // ms
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void lightsUpdate(timeUs_t currentTimeUs);
|
||||||
|
void lightsInit();
|
||||||
|
|
||||||
|
#endif /* LIGHTS */
|
|
@ -65,6 +65,9 @@ typedef enum {
|
||||||
#ifdef BEEPER
|
#ifdef BEEPER
|
||||||
TASK_BEEPER,
|
TASK_BEEPER,
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef LIGHTS
|
||||||
|
TASK_LIGHTS,
|
||||||
|
#endif
|
||||||
#ifdef USE_GPS
|
#ifdef USE_GPS
|
||||||
TASK_GPS,
|
TASK_GPS,
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue