indication: advanced indication with per-channel status led (#235)

* indication: advanced indication with per-channel status led

(cherry picked from commit b486dfe682622c9835cf00457834cebf6e34da2f)

* f1_dual_rev1: enable advanced indication

---------

Co-authored-by: Andrey Gusakov <dron0gus@gmail.com>
This commit is contained in:
rusefillc 2023-05-03 16:18:05 -04:00 committed by GitHub
parent c79964979c
commit 9519ad51dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 138 additions and 2 deletions

View File

@ -155,6 +155,7 @@ CPPSRC = $(ALLCPPSRC) \
uart.cpp \
auxout.cpp \
livedata.cpp \
indication.cpp \
console/binary/tunerstudio.cpp \
console/binary/tunerstudio_io.cpp \
console/binary/tunerstudio_io_serial.cpp \

View File

@ -74,3 +74,8 @@
// enable BT module setup attempt
#define BT_SERIAL_OVER_JDY33 TRUE
#define BT_BROADCAST_NAME "RusEFI WBO x2"
// *******************************
// Indication: per channel status LED + communication LED
// *******************************
#define ADVANCED_INDICATION

View File

@ -73,6 +73,8 @@
#include "tunerstudio_impl.h"
#include "byteswap.h"
#include "indication.h"
#include <rusefi/crc.h>
#ifndef EFI_BLUETOOTH_SETUP
@ -437,7 +439,7 @@ void TunerstudioThread::ThreadTask() {
// Until the end of time, process incoming messages.
while (true) {
if (tsProcessOne(channel) == 0) {
//onDataArrived(true);
onDataArrived(true);
btTimeout = 0;
} else {
btTimeout += TS_COMMUNICATION_TIMEOUT;
@ -449,7 +451,7 @@ void TunerstudioThread::ThreadTask() {
// Try this only once
btInitAttempted = true;
}
//onDataArrived(false);
onDataArrived(false);
}
}
}

117
firmware/indication.cpp Normal file
View File

@ -0,0 +1,117 @@
#include "ch.h"
#include "hal.h"
#include "fault.h"
#include "heater_control.h"
#include "indication.h"
#include "wideband_config.h"
using namespace wbo;
#ifdef ADVANCED_INDICATION
#define LED_BLINK_FAST (50)
#define LED_BLINK_MEDIUM (300)
#define LED_BLINK_SLOW (700)
#define LED_OFF_TIME (2000)
struct indicationThreadData {
uint32_t idx;
ioline_t line;
};
indicationThreadData indData[] = {
{0, PAL_LINE(LED_GREEN_PORT, LED_GREEN_PIN)},
#ifdef LED_R_GREEN_PORT
{1, PAL_LINE(LED_R_GREEN_PORT, LED_R_GREEN_PIN)},
#endif
};
static THD_WORKING_AREA(waIndicationThread, 128);
#ifdef LED_R_GREEN_PORT
static THD_WORKING_AREA(waIndicationThread2, 128);
#endif
static void IndicationThread(void *ptr)
{
chRegSetThreadName("Indication");
indicationThreadData *data = (indicationThreadData *)ptr;
while(true)
{
auto fault = GetCurrentFault(data->idx);
if (fault == Fault::None)
{
// Green is blinking
palToggleLine(data->line);
// Slow blink if closed loop, fast if not
chThdSleepMilliseconds(IsRunningClosedLoop(data->idx) ? LED_BLINK_SLOW : LED_BLINK_FAST);
}
else
{
// Start from off state
palClearLine(data->line);
// Blink out the error code
for (int i = 0; i < 2 * static_cast<int>(fault); i++)
{
// Blue is blinking
palToggleLine(data->line);
// fast blink
chThdSleepMilliseconds(LED_BLINK_MEDIUM);
}
chThdSleepMilliseconds(LED_OFF_TIME);
}
}
}
void InitIndication()
{
chThdCreateStatic(waIndicationThread, sizeof(waIndicationThread), NORMALPRIO, IndicationThread, &indData[0]);
#ifdef LED_R_GREEN_PORT
chThdCreateStatic(waIndicationThread2, sizeof(waIndicationThread2), NORMALPRIO, IndicationThread, &indData[1]);
#endif
}
/* Can be calles from two TS channels. */
void onDataArrived(bool status)
{
/* to avoid blinking when two TS channels available and only one is communicating
* another one will call this function with status = false every timeout */
/* TODO: total crap, rework */
static int filter = 0;
if (status) {
if (filter < 3) {
filter = 3;
}
} else {
if (filter > 0) {
filter--;
}
}
if (filter) {
palSetPad(LED_BLUE_PORT, LED_BLUE_PIN);
} else {
palClearPad(LED_BLUE_PORT, LED_BLUE_PIN);
}
}
#else
void InitIndication()
{
}
void onDataArrived(bool)
{
}
#endif

4
firmware/indication.h Normal file
View File

@ -0,0 +1,4 @@
#pragma once
void InitIndication();
void onDataArrived(bool status);

View File

@ -13,6 +13,7 @@
#include "max31855.h"
#include "port.h"
#include "tunerstudio.h"
#include "indication.h"
#include "wideband_config.h"
@ -41,6 +42,7 @@ int main() {
InitCan();
InitUart();
InitIndication();
#if (EGT_CHANNELS > 0)
StartEgt();
@ -48,6 +50,10 @@ int main() {
while(true)
{
#ifdef ADVANCED_INDICATION
/* NOP nap */
chThdSleepMilliseconds(1000);
#else
/* TODO: show error for all AFR channels */
/* TODO: show EGT errors */
auto fault = GetCurrentFault(0);
@ -80,6 +86,7 @@ int main() {
chThdSleepMilliseconds(2000);
}
#endif
}
}