mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-31 15:10:40 +00:00
MUI: BT programming mode (#6046)
* allow BT connection with disabled MUI * Update device-ui --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
@@ -422,13 +422,7 @@ bool NodeDB::resetRadioConfig(bool factory_reset)
|
||||
rebootAtMsec = millis() + (5 * 1000);
|
||||
}
|
||||
|
||||
#if (defined(T_DECK) || defined(T_WATCH_S3) || defined(UNPHONE) || defined(PICOMPUTER_S3)) && HAS_TFT
|
||||
// as long as PhoneAPI shares BT and TFT app switch BT off
|
||||
config.bluetooth.enabled = false;
|
||||
if (moduleConfig.external_notification.nag_timeout == 60)
|
||||
moduleConfig.external_notification.nag_timeout = 0;
|
||||
#endif
|
||||
|
||||
LOG_ERROR("NodeDB::resetRadioConfig done %d", didFactoryReset);
|
||||
return didFactoryReset;
|
||||
}
|
||||
|
||||
@@ -612,6 +606,13 @@ void NodeDB::installDefaultConfig(bool preserveKey = false)
|
||||
#else
|
||||
bool hasScreen = screen_found.port != ScanI2C::I2CPort::NO_I2C;
|
||||
#endif
|
||||
#if (defined(T_DECK) || defined(T_WATCH_S3) || defined(UNPHONE) || defined(PICOMPUTER_S3) || defined(INDICATOR)) && HAS_TFT
|
||||
// as long as PhoneAPI shares BT and TFT app switch BT off
|
||||
LOG_ERROR("config.bluetooth.enabled = false");
|
||||
config.bluetooth.enabled = false;
|
||||
if (moduleConfig.external_notification.nag_timeout == 60)
|
||||
moduleConfig.external_notification.nag_timeout = 0;
|
||||
#endif
|
||||
#ifdef USERPREFS_FIXED_BLUETOOTH
|
||||
config.bluetooth.fixed_pin = USERPREFS_FIXED_BLUETOOTH;
|
||||
config.bluetooth.mode = meshtastic_Config_BluetoothConfig_PairingMode_FIXED_PIN;
|
||||
|
||||
@@ -16,11 +16,23 @@ PacketAPI *PacketAPI::create(PacketServer *_server)
|
||||
return packetAPI;
|
||||
}
|
||||
|
||||
PacketAPI::PacketAPI(PacketServer *_server) : concurrency::OSThread("PacketAPI"), isConnected(false), server(_server) {}
|
||||
PacketAPI::PacketAPI(PacketServer *_server)
|
||||
: concurrency::OSThread("PacketAPI"), isConnected(false), programmingMode(false), server(_server)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t PacketAPI::runOnce()
|
||||
{
|
||||
bool success = sendPacket();
|
||||
bool success = false;
|
||||
if (config.bluetooth.enabled) {
|
||||
if (!programmingMode) {
|
||||
// in programmingMode we don't send any packets to the client except this one notify
|
||||
programmingMode = true;
|
||||
success = notifyProgrammingMode();
|
||||
}
|
||||
} else {
|
||||
success = sendPacket();
|
||||
}
|
||||
success |= receivePacket();
|
||||
return success ? 10 : 50;
|
||||
}
|
||||
@@ -79,10 +91,6 @@ bool PacketAPI::sendPacket(void)
|
||||
if (len != 0) {
|
||||
static uint32_t id = 0;
|
||||
fromRadioScratch.id = ++id;
|
||||
// TODO: think about redesign or drop class MeshPacketServer
|
||||
// if (typeid(*server) == typeid(MeshPacketServer))
|
||||
// return dynamic_cast<MeshPacketServer*>(server)->sendPacket(fromRadioScratch);
|
||||
// else
|
||||
bool result = server->sendPacket(DataPacket<meshtastic_FromRadio>(id, fromRadioScratch));
|
||||
if (!result) {
|
||||
LOG_ERROR("send queue full");
|
||||
@@ -92,6 +100,18 @@ bool PacketAPI::sendPacket(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PacketAPI::notifyProgrammingMode(void)
|
||||
{
|
||||
// tell the client we are in programming mode by sending only the bluetooth config state
|
||||
LOG_INFO("force client into programmingMode");
|
||||
memset(&fromRadioScratch, 0, sizeof(fromRadioScratch));
|
||||
fromRadioScratch.id = nodeDB->getNodeNum();
|
||||
fromRadioScratch.which_payload_variant = meshtastic_FromRadio_config_tag;
|
||||
fromRadioScratch.config.which_payload_variant = meshtastic_Config_bluetooth_tag;
|
||||
fromRadioScratch.config.payload_variant.bluetooth = config.bluetooth;
|
||||
return server->sendPacket(DataPacket<meshtastic_FromRadio>(0, fromRadioScratch));
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if we got (once!) contact from our client and the server send queue is not full
|
||||
*/
|
||||
|
||||
@@ -27,8 +27,10 @@ class PacketAPI : public PhoneAPI, public concurrency::OSThread
|
||||
private:
|
||||
bool receivePacket(void);
|
||||
bool sendPacket(void);
|
||||
bool notifyProgrammingMode(void);
|
||||
|
||||
bool isConnected;
|
||||
bool programmingMode;
|
||||
PacketServer *server;
|
||||
uint8_t txBuf[MAX_TO_FROM_RADIO_SIZE] = {0}; // dummy buf to obey PhoneAPI
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user