Author Topic: [DONE] hold SET at camera startup to load ML (load Canon firmware by default)  (Read 3891 times)

caramel-nut

  • New to the forum
  • *
  • Posts: 3
Just because of the way I use Magic Lantern. I mostly prefer it not to be on, but in a blink of an eye, in a particular moment out in the field, I'd like to have the option to use it. I only have one SD card. Thank you.

Walter Schulz

  • Contributor
  • Hero Member
  • *****
  • Posts: 7788
You can't have your cake and eat it.

caramel-nut

  • New to the forum
  • *
  • Posts: 3
You can't have your cake and eat it.

What a stupid response.

Anyone with any knowledge care to chime in?

josepvm

  • Member
  • ***
  • Posts: 212
Your request is not possible. If ML is not loaded, it cannot monitor a button press to activate itself.  And no option in stock Canon menus allows you to load ML on demand.

caramel-nut

  • New to the forum
  • *
  • Posts: 3
As a programmer, it could be possible. With Magic Lantern on the sd card, it could go like this:

1. Turn on camera

2. At this point, where ML would normally load, in this theoretical instance it would check to see if SET is being held, if it is, then let it load as usual. If not, then bypass the loading of ML (in other words, run the same script that occurs when you do hold SET upon load)

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12545
Indeed. It will still delay the boot process (loading from SD card takes time), will still reserve some RAM (likely nothing to worry about), will still run our GUI task (which hopefully behaves just like Canon's), but otherwise, all our hooks will be disabled, none of our "user" tasks will be started, so it's a lot less likely to be affected by a bug that way.

Implementation would be pretty much a dummy config preset (which can be configured to look at what key was pressed during startup). Difficult points:
- checking for that setting before initializing all the stuff (easiest to do by checking the presence of a "boolean" file)
- using file I/O before FIO backend initialization, or making sure that routine (and everything before it) is without side effects (for this purpose)
- deciding where to put it in ML menu (look up YAMLMO)
- compatibility checking on all models (hard, I usually get feedback from just a few camera models after few months)
- using the SD read-only switch (similar to CHDK) is also an option (without YAMLMO, but model-specific; testable in QEMU)

There is a possible side effect on models with CONFIG_AUDIO_CONTROLS, where Canon audio task is started after some delay (after the decision of loading ML or not was taking). It's not a widely tested code path, but it's likely harmless.

Quote
As a programmer...

In this case, the easiest way would be to just hardcode the desired behavior in boot-hack.c - negate the if (magic_off_request) - and recompile. Takes maybe 15 minutes (quoting dfort) to get started.

Danne

  • Developer
  • Hero Member
  • *****
  • Posts: 7099
Tried to negate
Code: [Select]
if (!magic_off_request) on my 100D and surely ML would not boot. But pressing SET did not get me back either so I tried with going back
Code: [Select]
if (magic_off_request) again to see if SET button would work at all to bypass ML menu and it didn´t.
I compiled from this branch:
https://bitbucket.org/hudson/magic-lantern/branch/crop_rec_4k_mlv_lite_snd
Any hints what to check around SET button on a 100D?

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12545
Sure, a startup log with the SET button pressed.

Same for EOS M, please (or any other model where this feature is not working). If the feature is working, the startup log build won't save any log when you hold SET pressed (it will only save one when booting normally).

Danne

  • Developer
  • Hero Member
  • *****
  • Posts: 7099
Start up log with SET button pressed 100D(not having my eosm available atm):
https://bitbucket.org/Dannephoto/magic-lantern/downloads/DM-0000.LOG


a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12545
Code: [Select]
5DFEE>    PropMgr:0049363c:00:00: *** mpu_send(06 05 02 0a 01 00), from 42dc                         ; PROP_PERMIT_ICU_EVENT
5E454> **INT-36h*:004936a4:00:00: *** mpu_recv(06 05 06 20 01 00), from 36438                        ; BGMT_Q
5E656>   MainCtrl:ff0cc664:89:03: bindReceiveSwitch (32, 1)
5E687>   MainCtrl:ff0d6368:85:03: GUI_Control:29 0x0

In gui-common.c, handle_common_events_startup, try using BGMT_Q_SET instead of BGMT_INFO.

Code: [Select]
diff -r eb5a09af2cf1 platform/EOSM.202/gui.h
--- a/platform/EOSM.202/gui.h
+++ b/platform/EOSM.202/gui.h
@@ -26,2 +26,3 @@
 #define BGMT_LV 0x1E
+#define BGMT_Q_SET 0x1D
 
diff -r eb5a09af2cf1 src/gui-common.c
--- a/src/gui-common.c
+++ b/src/gui-common.c
@@ -170,3 +170,3 @@
 #if defined(CONFIG_EOSM) || defined(CONFIG_100D) // these have a combined Q/SET button, SET button event is not sent properly
-        if (event->param == BGMT_INFO) { _disable_ml_startup(); return 0;} // don't load ML
+        if (event->param == BGMT_Q_SET) { _disable_ml_startup(); return 0;} // don't load ML
 #else

Very likely, the EOS M might be the same. The long-press trick for ETTR and other features might work too, as the button codes seem identical. To try this one (on top of the first patch):

Code: [Select]
diff -r 245c7831cc00 src/menu.c
--- a/src/menu.c
+++ b/src/menu.c
@@ -5977,3 +5977,3 @@
 
-#ifdef CONFIG_100D
+#ifdef BGMT_Q_SET
 static struct longpress qset_longpress = {
@@ -6155,3 +6155,3 @@
 
-#ifdef CONFIG_100D
+#ifdef BGMT_Q_SET
     /* triggers Q-menu by a long press on the combined q/set button */

Danne

  • Developer
  • Hero Member
  • *****
  • Posts: 7099
Will dig into this later some more, gotta run. A quick check reveals this in gui-common.h:
Code: [Select]
/* half-shutter button codes (they are consecutive after BGMT_PRESS_HALFSHUTTER) */
#define BGMT_UNPRESS_HALFSHUTTER (BGMT_PRESS_HALFSHUTTER+1)
#define BGMT_PRESS_FULLSHUTTER   (BGMT_PRESS_HALFSHUTTER+2)
#define BGMT_UNPRESS_FULLSHUTTER (BGMT_PRESS_HALFSHUTTER+3)

/* make sure all cameras have a Q event, to simplify portable code */
/* negative events are not passed to Canon firmware */
#ifndef BGMT_Q
#define BGMT_Q -0x879001
#endif

Want me to change this part?
Code: [Select]
#define BGMT_Q -0x879001
Code: [Select]
#define BGMT_Q_SET -0x879001[/code?
Ok, noticed you posted some more to try in your post. Will do later...

Danne

  • Developer
  • Hero Member
  • *****
  • Posts: 7099
Cool, patches working. For both patches to apply they need to be run in the same patch:
https://stackoverflow.com/questions/26544681/how-to-apply-several-patches-using-hg-command-line-when-there-is-already-uncommi
Code: [Select]
hg import patch.diff --no-commit

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12545
Alright, committed to lua_fix branch.

Danne

  • Developer
  • Hero Member
  • *****
  • Posts: 7099
Nice.
Added the negate trick and working as expected. Even though I personally wouldn´t need this it´s actually not bad when it comes to using it on a bunch of older cams at work where half of the students now won´t mess up settings accidentally shooting raw and so on when most often they only need basic canon functions.

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12545
Alright, suggestion for menu entry welcome (out of inspiration). Found a place to implement it without disturbing the overall startup process.

I'd also disable the "Magic OFF" message (which is no longer working for quite some time) and replace it with something simpler (LED fade out?)

Danne

  • Developer
  • Hero Member
  • *****
  • Posts: 7099
Maybe put a switch under submenu Misc key settings? Or in submenu Config files?
Another thing. Is it even possible to still do the "format" card and still keep magic lantern even though it was disabled to begin with?

"Magic lantern not activated"?(instead of Magic off?)
Maybe not the best sentence  :P
Magic lantern disabled?

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12545
Draft patch:
Code: [Select]
diff -r 1324f51b5e85 src/boot-hack.c
--- a/src/boot-hack.c
+++ b/src/boot-hack.c
@@ -462,2 +462,31 @@
     _find_ml_card();
+
+    /* should we require SET for loading ML, or not? */
+    extern int _set_at_startup;
+    _set_at_startup = config_flag_file_setting_load("ML/SETTINGS/REQUIRE.SET");
+
+    // at this point, gui_main_task should be started and should be able to tell whether SET was pressed at startup
+    if (magic_off_request != _set_at_startup)
+    {
+        /* should we bypass loading ML? */
+        /* (pressing SET after this point will be ignored) */
+        magic_off = 1;
+
+    #if !defined(CONFIG_NO_ADDITIONAL_VERSION)
+        /* fixme: enable on all models */
+        extern char additional_version[];
+        additional_version[0] = '-';
+        additional_version[1] = 'm';
+        additional_version[2] = 'l';
+        additional_version[3] = '-';
+        additional_version[4] = 'o';
+        additional_version[5] = 'f';
+        additional_version[6] = 'f';
+        additional_version[7] = '\0';
+    #endif
+
+        /* do not continue loading ML */
+        return;
+    }
+
     _load_fonts();
@@ -878,33 +907,8 @@
     // wait for overriden gui_main_task (but use a timeout so it doesn't break if you disable that for debugging)
-    for (int i = 0; i < 30; i++)
+    for (int i = 0; i < 50; i++)
     {
         if (ml_gui_initialized) break;
-        msleep(100);
+        msleep(50);
     }
-    msleep(200);
-
-    // at this point, gui_main_start should be started and should be able to tell whether SET was pressed at startup
-    if (magic_off_request)
-    {
-        magic_off = 1;  // magic off request might be sent later (until ml is fully started), but will be ignored
-        for (int i = 0; i < 10; i++)
-        {
-            if (DISPLAY_IS_ON) break;
-            msleep(100);
-        }
-        bmp_printf(FONT_CANON, 0, 0, "Magic OFF");
-        info_led_off();
-    #if !defined(CONFIG_NO_ADDITIONAL_VERSION)
-        extern char additional_version[];
-        additional_version[0] = '-';
-        additional_version[1] = 'm';
-        additional_version[2] = 'l';
-        additional_version[3] = '-';
-        additional_version[4] = 'o';
-        additional_version[5] = 'f';
-        additional_version[6] = 'f';
-        additional_version[7] = '\0';
-    #endif
-        return ans;
-    }
+    msleep(50);
 
diff -r 1324f51b5e85 src/config.c
--- a/src/config.c
+++ b/src/config.c
@@ -282,3 +282,3 @@
 
-int config_flag_file_setting_load(char* file)
+int config_flag_file_setting_load(const char * file)
 {
@@ -288,3 +288,3 @@
 
-void config_flag_file_setting_save(char* file, int setting)
+void config_flag_file_setting_save(const char * file, int setting)
 {
@@ -304,3 +304,2 @@
     config_flag_file_setting_save(autosave_flag_file, !!config_autosave);
-    msleep(50);
     config_autosave = !config_flag_file_setting_load(autosave_flag_file);
@@ -858,5 +857,16 @@
 
+/* initialized and used in boot-hack.c */
+int _set_at_startup = 0;
+
+static MENU_SELECT_FUNC(set_at_startup_toggle)
+{
+    /* this one is a bit hard to integrate with config presets, so it's made global */
+    const char * flag_file = "ML/SETTINGS/REQUIRE.SET";
+    config_flag_file_setting_save(flag_file, !_set_at_startup);
+    _set_at_startup = config_flag_file_setting_load(flag_file);
+}
+
 static struct menu_entry cfg_menus[] = {
 {
-    .name = "Config files",
+    .name = "Config options",
     .select = menu_open_submenu,
@@ -867,2 +877,13 @@
         {
+            .name       = "SET at startup",
+            .priv       = &_set_at_startup,
+            .max        = 1,
+            .choices    = CHOICES("Bypass loading ML", "Required to load ML"),
+            .select     = set_at_startup_toggle,
+            .icon_type  = IT_BOOL,
+            .help       = "[GLOBAL] If you hold the SET button pressed at camera startup:",
+            .help2      = "Do not load ML if you start the camera with SET pressed (default)\n"
+                          "Load ML only if SET is pressed at startup (optional)"
+        },
+        {
             .name = "Config preset",
diff -r 1324f51b5e85 src/config.h
--- a/src/config.h
+++ b/src/config.h
@@ -149,4 +149,4 @@
 /* simple boolean settings that live outside of config files (just by presence of a file) */
-int config_flag_file_setting_load(char* file);
-void config_flag_file_setting_save(char* file, int setting);
+int config_flag_file_setting_load(const char * file);
+void config_flag_file_setting_save(const char * file, int setting);
 
diff -r 1324f51b5e85 src/menuindex.c
--- a/src/menuindex.c
+++ b/src/menuindex.c
@@ -27,2 +27,5 @@
 
+/* config.c */
+extern int _set_at_startup;
+
 static struct menu_entry help_menus[] = {
@@ -117,2 +120,11 @@
     {
+        .select = menu_nav_help_open,
+        .name = "SET at startup",
+        .priv = &_set_at_startup,
+        .max  = 1,
+        .icon_type = IT_ACTION,
+        .choices = CHOICES("Bypass loading ML", "Required to load ML"),
+        .help = "To change this setting: Prefs -> Config options",
+    },
+    {
         .name = "Key Shortcuts",

Format card and keep Magic Lantern even though it was disabled? Good point, will think about it (would require a background task to monitor Canon menu).

[edit: it's not trivial, a lot of checks there require properties - hooks in Canon code; if we go that far, you may as well create a config preset with most of the stuff turned off]

Yeah, a better message could work, but didn't want to go to the trouble of loading the fonts just for that.

Danne

  • Developer
  • Hero Member
  • *****
  • Posts: 7099
Checking asap. Got more work today. Probably tomorrow...

Danne

  • Developer
  • Hero Member
  • *****
  • Posts: 7099
Cool! Working. Enabled/disabled and did exactly what it´s supposed to(tested on 100D):


dfort

  • Developer
  • Hero Member
  • *****
  • Posts: 3751
Checked it out on the EOSM. Like the play button for getting to the submenus. The only issue is that when starting with the SET button to disable ML or configured to work the other way around, the LED stays lit until you shoot a picture or record a video. You aren't seeing that on the 100D?
5D3.* 7D.206 700D.115 EOSM.203 EOSM2.103 M50.102

Danne

  • Developer
  • Hero Member
  • *****
  • Posts: 7099
No issues on the 100D. Retested just now. All good.
How is the holding SET button working when config option not set on the eosm?

I can confirm the "led stays on" issue on the eosm and taking a picture releases it. BEhaviour occurs both when SET is selected in config menu and whn running without config seetting set by holding SET upon starting camera...

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12545
Mystery solved? At least it now works in QEMU.

Yet another EOS M quirk - Canon firmware accessing the SD card without turning on the LED

Danne

  • Developer
  • Hero Member
  • *****
  • Posts: 7099
Mystery solved? At least it now works in QEMU.

Confirmed working. Led not stuck anymore(eosm). Great!

Kharak

  • Hero Member
  • *****
  • Posts: 997
Cool! Working. Enabled/disabled and did exactly what it´s supposed to(tested on 100D):



I do not have this option running crop_rec_4k.2018Jul22.5D3123 build.

I can do Config Preset - Startup Mode, after restarting no modules are loaded, but ML still boots.

Is the option hidden somewhere else? Am I missing something, do I need to load some Config from here on to my SD card?

once you go raw you never go back

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12545
It's probably not yet integrated in crop_rec builds - but it's for sure present in lua_fix builds.

(I'll take a look when I'll revisit crop_rec again - hopefully in the next few months, but that's not a promise)