Skip to content

Conversation

SummerSigh
Copy link

This version unified wifi and USB firmware, making it so now setup can be done on the actual application in real deployment.

Copy link
Member

@lorow lorow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a lot of good work, much appreciated. Leaving mostly some questions, nothing major :D

Once more, thanks for taking care of this!

deviceModeManager->setMode(DeviceMode::WIFI_MODE);
log_i("[CommandManager] Switching to WiFi mode after receiving credentials");

OpenIrisTasks::ScheduleRestart(2000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a bad idea, we're sending two commands in one payload in the flasher, first one to setup wifi and second to setup mDNS, so the second one might fail or won't get executed at all since they're executed in the order they were received.

I think it'd be better to introduce one more command - RESTART_DEVICE and send it as the very last command so that we're sure we've got everything set properly before

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! That makes sense; I'll add it then! i wasnt really sure how the flasher worked, but that makes sense


const CommandType CommandManager::getCommandType(JsonVariant& command) {
if (!command.containsKey("command"))
if (!command["command"].is<const char*>())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, why the change? Is .is<T> is faster / more memory efficient than .containsKey()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

command["command"].is<const char*>() it's the recommended approach in ArduinoJson because containsKey() is deprecated lol and i didn't like the warnings

deviceModeManager->setMode(DeviceMode::USB_MODE);
log_i("[CommandManager] Switching to USB mode after wiping credentials");

OpenIrisTasks::ScheduleRestart(2000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something happened here with formatting or github crewed up?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! i wrote some code that didn't work, deleted it and then forgot to fix the restart fomat imao

}

void DeviceModeManager::init() {
preferences.begin(PREF_NAMESPACE, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I'm sold on this. We've got a config manager that takes care of manipulating everything related to preferences and configuration so we could move most of the responsibility into it, what do ya think?

Granted, the idea of DeviceModeManager being a singleton would have to go and with it a bit of the implementation, but might be a bit cleaner?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perchance yeah, I needed some lightweight code to do what i wanted at the time, so ill change it to use config manager lol

}

DeviceModeManager* deviceModeManager = DeviceModeManager::getInstance();
if (deviceModeManager) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from what I gather, getInstance() will return the already existing instance or create a fresh one, do we still have to check for a nullpointer then?

Comment on lines +96 to +98
} else {
CommandsPayload commands = {doc};
this->commandManager->handleCommands(commands);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the change?

Comment on lines 103 to 104
DeviceMode currentMode = DeviceModeManager::getInstance()->getMode();
if (currentMode == DeviceMode::USB_MODE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about:

if (DeviceModeManager::getInstance()->getMode() == DeviceMode::USB_MODE)

I'm pretty sure the compiler will optimize it away anyway, but we can make it slightly cleaner

Comment on lines 184 to 186
if (Serial.available()) {
yield();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the way I understand it. We're connecting to wifi, but then a command came telling us to use usb instead, so we've changed the mode. Why do we have to yield here then? Shouldn't wifi manager just stop in its track once we disconnect?

ESP/src/main.cpp Outdated
Comment on lines 44 to 48
if (deviceModeManager && deviceModeManager->getMode() == DeviceMode::USB_MODE) {
log_i("[SETUP]: Mode changed to USB before network initialization, aborting");
WiFi.disconnect(true);
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're doing the same thing three times, I'd move it out to a smaller helper function, a bit easier to maintain later

def send_command(self, command_obj):
if not self.serial_conn:
print("Serial connection not established")
return False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're returning here a False, a Json object and a None. I'd replace the False with a None just to be consistent

@lorow
Copy link
Member

lorow commented Mar 16, 2025

Also, builds are failing because (Like Assassin mentioned on discord) etvr_eye_tracker_web_init() is apparently missing in some builds, most likely some defines going wrong. I can take a look at it this week if you'd like

Removed DeviceModeManager and integrated device mode handling into ProjectConfig for better maintainability. Added RESTART_DEVICE command for explicit device reboots and updated related tests to verify reboot functionality. Simplified mode checks across the codebase by using ProjectConfig directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants