smartavionics / RawMouse

Cura Plugin that lets you use a HID mouse to pan/rotate/zoom the view
94 stars 7 forks source link

Automatic Restart #7

Closed eried closed 4 years ago

eried commented 4 years ago

Hi again! How could I trigger an automatic reload on every windows switch/activation?

For some reason under Windows (with the actions set to none in the official driver) this works perfectly but from time to time I need to call "Extensions / Rawmouse / Restart" to make it respond again. Usually after switching to Inventor for example.

I would appreciate any tip how to code that, because I can see how undocumented is the development of cura plugins

smartavionics commented 4 years ago

Hi. Do you get any messages in cura.log that say "Exception while reading HID events" when it fails after switching away and returning?

eried commented 4 years ago

I only see

2020-06-15 16:01:25,005 - ERROR - [RawMouse] RawMouse.RawMouse._run_hid [243]: Exception while reading HID events: read error
2020-06-15 16:07:50,341 - DEBUG - [MainThread] cura.OAuth2.AuthorizationHelpers.getAccessTokenUsingRefreshToken [53]: Refreshing the access token.
2020-06-15 16:07:50,694 - DEBUG - [MainThread] cura.OAuth2.AuthorizationService._storeAuthData [213]: Attempting to store the auth data

but nothing recently. I will try to find a way to replate the error, but I think just reloading on window active would do the job.

smartavionics commented 4 years ago

but I think just reloading on window active would do the job.

It would be nice to be able to detect when it's necessary to do a restart rather than restarting every time the focus is lost/restored by Cura.

eried commented 4 years ago

I know, but Restarting does not seem to be very resource intensive

smartavionics commented 4 years ago

Next time it occurs, look at the log and see if it produced a message, thanks.

eried commented 4 years ago

Next time it occurs, look at the log and see if it produced a message, thanks.

OK, so the last message before it failed (and continued working in other software for example)

2020-06-24 15:50:45,389 - DEBUG - [RawMouse] RawMouse.RawMouse._decodeSpacemouseEvent [336]: Spacemouse battery level 54%
2020-06-24 15:53:54,181 - DEBUG - [MainThread] cura.OAuth2.AuthorizationHelpers.getAccessTokenUsingRefreshToken [53]: Refreshing the access token.
2020-06-24 15:53:54,551 - DEBUG - [MainThread] cura.OAuth2.AuthorizationService._storeAuthData [213]: Attempting to store the auth data
2020-06-24 15:54:02,024 - DEBUG - [RawMouse] RawMouse.RawMouse._decodeSpacemouseEvent [336]: Spacemouse battery level 54%
2020-06-24 15:54:04,570 - DEBUG - [MainThread] cura.AutoSave._onTimeout [60]: Autosaving preferences, instances and profiles
2020-06-24 15:54:07,407 - ERROR - [RawMouse] RawMouse.RawMouse._run_hid [243]: Exception while reading HID events: read error
2020-06-24 15:54:07,407 - ERROR - [RawMouse] RawMouse.RawMouse._run_hid [243]: Exception while reading HID events: read error

So I would guess that the best solution would be to register any error, and if rawmouse was enabled before the error, then trigger Restart on the first window focus no?

smartavionics commented 4 years ago

The master branch now detects the read error and does a restart, could you please try that.

eried commented 4 years ago

Loaded, I will see if it happens again. Thanks! :)

smartavionics commented 4 years ago

Hi, has this fix been working OK for you?

eried commented 4 years ago

Yes! I have been using it since then and no more issues