Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable/Disable Logging to SD Card from LUA #5191

Closed
1 task done
derelict opened this issue Jun 17, 2024 · 8 comments
Closed
1 task done

Enable/Disable Logging to SD Card from LUA #5191

derelict opened this issue Jun 17, 2024 · 8 comments
Labels
enhancement ✨ New feature or request lua

Comments

@derelict
Copy link

derelict commented Jun 17, 2024

Is there an existing issue for this feature request?

  • I have searched the existing issues

Is your feature request related to a problem?

no

Describe the solution you'd like

add a LUA Function to enable/disable Logging to SD Card like:

sdlogging(true)

and

sdlogging(false)

optionally with an option to specify the interval.

I'd like to use this in a LUA Script ... to dynamically turn logging on for certain circumstances.

I'm sure this could be usefull for other LUA Scripts too

Describe alternatives you've considered

none

Additional context

i have tried to do it myself in the code ... but i have no knowhow with C++ ... i'm sure for a DEV it would be easy to do. I have managed to create a LUA Function that turns logging on or off by modifying initLoggingTimer() logsWrite() with a Boolean value ... but the status was not reflected on the UI.

@derelict derelict added the enhancement ✨ New feature or request label Jun 17, 2024
@mha1
Copy link
Contributor

mha1 commented Aug 17, 2024

You can do this with LUA itself. Attached find a LUA function to enable/disable a defined SF SD Logs plus a little init routine that needs to be run once in order for the SD Logs enable/disable function to work.

For demo purposes the LUA function is embedded in a little function script to show how it is used. Just rip out function initSDLogEnable() and function SDLogsEnable(enable) and use it in your code.

Ho does it work? initSDLogEnable() searches for a defined SF SD Logs in the current selected model setup. If it finds one it memorizes its definition. SDLogsEnable(0) or SDLogsEnable(1) uses the stored SF data and overrides the enable status. To see what the demo does install Logs01.lua as function script and define a special function SD Logs. The function script will enable/disable the logs every 5s. The UI reflects the status accordingly.

Logs01.lua.txt

@derelict
Copy link
Author

You can do this with LUA itself. Attached find a LUA function to enable/disable a defined SF SD Logs plus a little init routine that needs to be run once in order for the SD Logs enable/disable function to work.

will this work ... even if the transmitter does not have an SF for logs defined/set ?

@mha1
Copy link
Contributor

mha1 commented Aug 19, 2024

currently no but init can be extended with a few lines of code to automatically create an SF in case it doesn't find one.

@mha1
Copy link
Contributor

mha1 commented Aug 19, 2024

Here's the version that'll create a SF SD Logs in the first free SF slot with default 1.0s log period if the model setup doesn't have a SF SD Logs defined

Logs01.lua.txt

@derelict
Copy link
Author

derelict commented Aug 23, 2024

Cool. I will give it a try in my widget (currently using "radio made SF"). Thanks for the Hint/Input !

@pfeerick
Copy link
Member

Gonna close this as resolved as like how #5191 (comment) is doing it is probably the only way this can really be reasonably be done, given this is a SF you need to define in the first place, and can be any line, any trigger, any state. So the API to do what you want can't be as 'simple' as a sdlogging(true/false) function... i.e. as you have multiple SD lines actually work, to configure logging at different times/rates, etc. It really does need to be "find the SD Logging SF of interest, enable or disable it" approach.

@pfeerick pfeerick added the lua label Aug 24, 2024
@derelict
Copy link
Author

derelict commented Sep 28, 2024

Here's the version that'll create a SF SD Logs in the first free SF slot

Could it be, that this is not working when called/used in a widget script ?

If i execute your script manually it works ... but once "embedded" in a widget script it doesn't work anymore.

Even using get/setCustomFunction does not seem to change anything:

local test = model.getCustomFunction(SDlogsSFIndex) -- get SF at index i

test.active = 1
test.value = 30

model.setCustomFunction(SDlogsSFIndex, test)

local test = model.getCustomFunction(SDlogsSFIndex) -- get SF at index i

print("SFDEBG: CF Debug " .. test.switch )
print("SFDEBG: CF Debug " .. test.func )
print("SFDEBG: CF Debug " .. test.value )
print("SFDEBG: CF Debug " .. test.active )

returns the correct values ... but nothing is changed/visible at the SF Screen ... and logging is not on ... even though "test.active" says "1"

SFDEBG: CF Debug 233
SFDEBG: CF Debug 18
SFDEBG: CF Debug 30
SFDEBG: CF Debug 1

all values correct ... but logging still off ... and customfunction unchanged (interval set to 10 .... but should have changed to 30)

@mha1
Copy link
Contributor

mha1 commented Sep 29, 2024

I don't know but can't think of a reason why it wouldn't work in a widget. Please attach a minimal version of your widget demonstrating the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request lua
Projects
None yet
Development

No branches or pull requests

3 participants