a lot of thread housekeeping. Switch them off when not needed / disabled.

pull/2074/head
Thomas Göttgens 2022-12-29 15:45:49 +01:00
rodzic 1a949b7ca6
commit 41a1dfec79
15 zmienionych plików z 102 dodań i 59 usunięć

Wyświetl plik

@ -54,7 +54,7 @@ int32_t RotaryEncoderInterruptBase::runOnce()
this->action = ROTARY_ACTION_NONE;
return 30000; // TODO: technically this can be MAX_INT
return INT32_MAX;
}
void RotaryEncoderInterruptBase::intPressHandler()

Wyświetl plik

@ -7,7 +7,7 @@ enum RotaryEncoderInterruptBaseStateType { ROTARY_EVENT_OCCURRED, ROTARY_EVENT_C
enum RotaryEncoderInterruptBaseActionType { ROTARY_ACTION_NONE, ROTARY_ACTION_PRESSED, ROTARY_ACTION_CW, ROTARY_ACTION_CCW };
class RotaryEncoderInterruptBase : public Observable<const InputEvent *>, private concurrency::OSThread
class RotaryEncoderInterruptBase : public Observable<const InputEvent *>, public concurrency::OSThread
{
public:
explicit RotaryEncoderInterruptBase(const char *name);

Wyświetl plik

@ -9,6 +9,8 @@ void RotaryEncoderInterruptImpl1::init()
{
if (!moduleConfig.canned_message.rotary1_enabled) {
// Input device is disabled.
setInterval(INT32_MAX);
enabled = false;
return;
}

Wyświetl plik

@ -13,6 +13,8 @@ void CardKbI2cImpl::init()
if (cardkb_found != CARDKB_ADDR)
{
// Input device is not detected.
setInterval(INT32_MAX);
enabled = false;
return;
}

Wyświetl plik

@ -5,7 +5,7 @@
class KbI2cBase :
public Observable<const InputEvent *>,
private concurrency::OSThread
public concurrency::OSThread
{
public:
explicit KbI2cBase(const char *name);

Wyświetl plik

@ -165,11 +165,20 @@ void createSSLCert()
WebServerThread *webServerThread;
WebServerThread::WebServerThread() : concurrency::OSThread("WebServerThread") {}
WebServerThread::WebServerThread() : concurrency::OSThread("WebServerThread") {
if(!config.network.wifi_enabled) {
setInterval(INT32_MAX);
enabled = false;
}
}
int32_t WebServerThread::runOnce()
{
// DEBUG_MSG("WebServerThread::runOnce()\n");
if(!config.network.wifi_enabled) {
setInterval(INT32_MAX);
enabled = false;
}
handleWebResponse();
if (requestRestart && (millis() / 1000) > requestRestart) {

Wyświetl plik

@ -55,10 +55,18 @@ CannedMessageModule::CannedMessageModule()
if ((this->splitConfiguredMessages() <= 0) && (cardkb_found != CARDKB_ADDR)) {
DEBUG_MSG("CannedMessageModule: No messages are configured. Module is disabled\n");
this->runState = CANNED_MESSAGE_RUN_STATE_DISABLED;
setInterval(INT32_MAX);
enabled = false;
} else {
DEBUG_MSG("CannedMessageModule is enabled\n");
this->inputObserver.observe(inputBroker);
}
setInterval(INT32_MAX);
enabled = false;
} else {
this->runState = CANNED_MESSAGE_RUN_STATE_DISABLED;
setInterval(INT32_MAX);
enabled = false;
}
}

Wyświetl plik

@ -199,6 +199,7 @@ ExternalNotificationModule::ExternalNotificationModule()
}
} else {
DEBUG_MSG("External Notification Module Disabled\n");
setInterval(INT32_MAX);
enabled = false;
}
}

Wyświetl plik

@ -48,64 +48,66 @@ static uint64_t digitalReads(uint64_t mask)
RemoteHardwareModule::RemoteHardwareModule()
: ProtobufModule("remotehardware", PortNum_REMOTE_HARDWARE_APP, &HardwareMessage_msg), concurrency::OSThread(
"remotehardware")
"RemoteHardwareModule")
{
}
bool RemoteHardwareModule::handleReceivedProtobuf(const MeshPacket &req, HardwareMessage *pptr)
{
auto p = *pptr;
DEBUG_MSG("Received RemoteHardware typ=%d\n", p.type);
if (moduleConfig.remote_hardware.enabled) {
auto p = *pptr;
DEBUG_MSG("Received RemoteHardware typ=%d\n", p.type);
switch (p.type) {
case HardwareMessage_Type_WRITE_GPIOS:
// Print notification to LCD screen
screen->print("Write GPIOs\n");
switch (p.type) {
case HardwareMessage_Type_WRITE_GPIOS:
// Print notification to LCD screen
screen->print("Write GPIOs\n");
for (uint8_t i = 0; i < NUM_GPIOS; i++) {
uint64_t mask = 1 << i;
if (p.gpio_mask & mask) {
digitalWrite(i, (p.gpio_value & mask) ? 1 : 0);
for (uint8_t i = 0; i < NUM_GPIOS; i++) {
uint64_t mask = 1 << i;
if (p.gpio_mask & mask) {
digitalWrite(i, (p.gpio_value & mask) ? 1 : 0);
}
}
pinModes(p.gpio_mask, OUTPUT);
break;
case HardwareMessage_Type_READ_GPIOS: {
// Print notification to LCD screen
if (screen)
screen->print("Read GPIOs\n");
uint64_t res = digitalReads(p.gpio_mask);
// Send the reply
HardwareMessage r = HardwareMessage_init_default;
r.type = HardwareMessage_Type_READ_GPIOS_REPLY;
r.gpio_value = res;
r.gpio_mask = p.gpio_mask;
MeshPacket *p2 = allocDataProtobuf(r);
setReplyTo(p2, req);
myReply = p2;
break;
}
pinModes(p.gpio_mask, OUTPUT);
break;
case HardwareMessage_Type_WATCH_GPIOS: {
watchGpios = p.gpio_mask;
lastWatchMsec = 0; // Force a new publish soon
previousWatch = ~watchGpios; // generate a 'previous' value which is guaranteed to not match (to force an initial publish)
enabled = true; // Let our thread run at least once
DEBUG_MSG("Now watching GPIOs 0x%llx\n", watchGpios);
break;
}
case HardwareMessage_Type_READ_GPIOS: {
// Print notification to LCD screen
if (screen)
screen->print("Read GPIOs\n");
case HardwareMessage_Type_READ_GPIOS_REPLY:
case HardwareMessage_Type_GPIOS_CHANGED:
break; // Ignore - we might see our own replies
uint64_t res = digitalReads(p.gpio_mask);
// Send the reply
HardwareMessage r = HardwareMessage_init_default;
r.type = HardwareMessage_Type_READ_GPIOS_REPLY;
r.gpio_value = res;
r.gpio_mask = p.gpio_mask;
MeshPacket *p2 = allocDataProtobuf(r);
setReplyTo(p2, req);
myReply = p2;
break;
}
case HardwareMessage_Type_WATCH_GPIOS: {
watchGpios = p.gpio_mask;
lastWatchMsec = 0; // Force a new publish soon
previousWatch = ~watchGpios; // generate a 'previous' value which is guaranteed to not match (to force an initial publish)
enabled = true; // Let our thread run at least once
DEBUG_MSG("Now watching GPIOs 0x%llx\n", watchGpios);
break;
}
case HardwareMessage_Type_READ_GPIOS_REPLY:
case HardwareMessage_Type_GPIOS_CHANGED:
break; // Ignore - we might see our own replies
default:
DEBUG_MSG("Hardware operation %d not yet implemented! FIXME\n", p.type);
break;
default:
DEBUG_MSG("Hardware operation %d not yet implemented! FIXME\n", p.type);
break;
}
}
return false;
@ -113,7 +115,7 @@ bool RemoteHardwareModule::handleReceivedProtobuf(const MeshPacket &req, Hardwar
int32_t RemoteHardwareModule::runOnce()
{
if (watchGpios) {
if (moduleConfig.remote_hardware.enabled && watchGpios) {
uint32_t now = millis();
if (now - lastWatchMsec >= WATCH_INTERVAL_MSEC) {
@ -134,6 +136,7 @@ int32_t RemoteHardwareModule::runOnce()
} else {
// No longer watching anything - stop using CPU
enabled = false;
return INT32_MAX;
}
return 200; // Poll our GPIOs every 200ms (FIXME, make adjustable via protobuf arg)

Wyświetl plik

@ -222,6 +222,7 @@ int32_t SerialModule::runOnce()
} else {
DEBUG_MSG("Serial Module Disabled\n");
enabled = false;
return INT32_MAX;
}
}
@ -303,9 +304,6 @@ ProcessMessage SerialModuleRadio::handleReceived(const MeshPacket &mp)
}
}
}
} else {
DEBUG_MSG("Serial Module Disabled\n");
}
return ProcessMessage::CONTINUE; // Let others look at this message also if they want
}

Wyświetl plik

@ -67,6 +67,7 @@ int32_t EnvironmentTelemetryModule::runOnce()
if (!(moduleConfig.telemetry.environment_measurement_enabled ||
moduleConfig.telemetry.environment_screen_enabled)) {
// If this module is not enabled, and the user doesn't want the display screen don't waste any OSThread time on it
enabled = false;
return result;
}

Wyświetl plik

@ -139,6 +139,8 @@ AudioModule::AudioModule() : SinglePortModule("AudioModule", PortNum_AUDIO_APP),
DEBUG_MSG(" using %d frames of %d bytes for a total payload length of %d bytes\n", encode_frame_num, encode_codec_size, encode_frame_size);
xTaskCreate(&run_codec2, "codec2_task", 30000, NULL, 5, &codec2HandlerTask);
} else {
setInterval(INT32_MAX);
enabled = false;
DEBUG_MSG("Codec2 disabled (AudioModule %d, Region %s, permitted %d)\n", moduleConfig.audio.codec2_enabled, myRegion->name, myRegion->audioPermitted);
}
}
@ -259,6 +261,7 @@ int32_t AudioModule::runOnce()
return 100;
} else {
DEBUG_MSG("Audio Module Disabled\n");
enabled = false;
return INT32_MAX;
}

Wyświetl plik

@ -82,6 +82,7 @@ int32_t RangeTestModule::runOnce()
return (senderHeartbeat);
} else {
enabled = false;
return (INT32_MAX);
// This thread does not need to run as a receiver
}
@ -94,6 +95,7 @@ int32_t RangeTestModule::runOnce()
}
#endif
enabled = false;
return (INT32_MAX);
}

Wyświetl plik

@ -52,6 +52,7 @@ int32_t StoreForwardModule::runOnce()
return (this->packetTimeMax);
}
#endif
enabled = false; // Client doesn't need periodical
return (INT32_MAX);
}
@ -458,6 +459,9 @@ StoreForwardModule::StoreForwardModule()
is_client = true;
DEBUG_MSG("*** Initializing Store & Forward Module in Client mode\n");
}
} else {
setInterval(INT32_MAX);
enabled = false;
}
#endif
}

Wyświetl plik

@ -128,12 +128,18 @@ void mqttInit()
MQTT::MQTT() : concurrency::OSThread("mqtt"), pubSub(mqttClient), mqttQueue(MAX_MQTT_QUEUE)
{
assert(!mqtt);
mqtt = this;
if(moduleConfig.mqtt.enabled) {
pubSub.setCallback(mqttCallback);
assert(!mqtt);
mqtt = this;
// preflightSleepObserver.observe(&preflightSleep);
pubSub.setCallback(mqttCallback);
// preflightSleepObserver.observe(&preflightSleep);
} else {
setInterval(INT32_MAX);
enabled = false;
}
}
bool MQTT::connected()
@ -238,6 +244,10 @@ bool MQTT::wantsLink() const
int32_t MQTT::runOnce()
{
if(!moduleConfig.mqtt.enabled) {
enabled = false;
return INT32_MAX;
}
bool wantConnection = wantsLink();
// If connected poll rapidly, otherwise only occasionally check for a wifi connection change and ability to contact server