Page 6 of 12

Re: Script Language

Posted: Thu Dec 21, 2017 9:53 pm
by MikeB
The AR9X board, as standard, doesn't support the Smart Port in bi-directional mode needed to send data to the Rx.
You need to add a diode to the inverted COM1 connections for this to work. Have you done this?

Mike.

Re: Script Language

Posted: Thu Dec 21, 2017 11:03 pm
by nico84
No, now I have added the diode and ist is working now. Thank you.

Re: Script Language

Posted: Fri Dec 22, 2017 9:31 pm
by nico84
I tried to add vtx setup to midelics script. I can read the values, but when I change and save them betaflight does not accept them. I have no Idea why.

@midelic
what does packet_size do. From where do you get the values?
0BF_basic.zip
(4.39 KiB) Downloaded 327 times

Re: Script Language

Posted: Sat Dec 23, 2017 2:53 pm
by jhsa
Hi nico84. I am posting on Midelic's behalf as he cannot access this forum at the moment.

João

Here is his message:
Please check an older version LUA script to adapt version of getWriteValuesVTX and postReadVTX to bas script ,I'm not at home to test and come back in January.

As an example:

Code: Select all

saveSettings:
rem --write commands
page= currentPage
gosub check_values
  if v_flag
     cmnd = write
     p_size = packet_size
 j=1
 while j<=packet_size
     if page=1
  payloadReq[j]=values_pid[j]
     elseif page= 2
  payloadReq[j]=values_rates[j]
  else
  gosub getWriteValuesVTX
  payloadReq[j]= values_vtx[j]
      end	 
 j=j+1
 end
     gosub mspSendRequest
     _______________________________

https://github.com/betaflight/betafligh ... eb67234b3b

Re: Script Language

Posted: Sat Dec 23, 2017 3:43 pm
by nico84
Hi Midelic and João,
thank you. I will try. But I think my code is bad. PID read and write is fine.

Edit:
Ok I see it. I will try.

Re: Script Language

Posted: Sun Jan 07, 2018 3:42 pm
by nico84
I works. Added:

Code: Select all

saveSettings:
rem --write commands
page= currentPage
gosub check_values
   if v_flag
      cmnd = write
      p_size = packet_size
	  j = 1
	  while j <= packet_size
      if page = 1
	   payloadReq[j] = values_pid[j]
      elseif page = 2
	   payloadReq[j] = values_rates[j]
	  elseif page = 3
	   gosub getWriteValuesVTX
	   payloadReq[j] = values_vtx_rx[j]
       end	  
	  j = j+1
	  end
      gosub mspSendRequest


      saveTS = gettime()
      if gState = PAGE_SAVING 
         saveRetries = saveRetries + 1
      else
       gState = PAGE_SAVING
      end	  
end
return

getWriteValuesVTX:
values_vtx_rx[1] = (values_vtx[2]-1)*8 + values_vtx[3]-1
values_vtx_rx[2] = 0
values_vtx_rx[3] = values_vtx[4]
values_vtx_rx[4] = values_vtx[5]
return
Now I have to define the allowed values and to differentiate between tramp and TBS

Re: Script Language

Posted: Fri Jan 19, 2018 10:39 pm
by gizmatron
great work guys .. seems like we almost have a working script for pids and vtx... now i just need to read back and work out how to add it all to my 9xr-pro

Re: Script Language

Posted: Wed Jan 24, 2018 1:25 pm
by planger
Is there a way to write a value to a channel?
Like for the Logical switches if they are unused?

Re: Script Language

Posted: Wed Jan 24, 2018 3:53 pm
by MikeB
At the moment, I've deliberately made this non-obvious, as I feel scripts shouldn't be used for significant control functions.
You need to use a GVAR to do this, in the script use:
settelitem( "GVAR1", value )
where value goes from -125 to +125 (%), then use GVAR1 as the source for the channel.

Mike

Re: Script Language

Posted: Wed Jan 24, 2018 7:21 pm
by planger
Thanks Mike, I've got other questions:
- Can we set haptic? example vibrate(x) with x in ms.
- Can there be an overlay on the existing display? I'm thinking of replacing for example the low part of the main screen where the channels are displayed with the script output. It could be an additional page. The script is informed that the page has been selected (sysflags.0?) and starts to draw over the bottom part. That would enable the script to run in background and only display when asked. If that's too complicated at least a blank page you could access, inform the script that it can draw and a way to exit it without ending the script.

Re: Script Language

Posted: Wed Jan 24, 2018 8:11 pm
by jhsa
Perhaps a script could create a "Custom" main screen if needed when it starts? And then close it again when the script stops?
or is this a nonsense?? :)
João

Re: Script Language

Posted: Wed Jan 24, 2018 8:13 pm
by jhsa
MikeB wrote: Wed Jan 24, 2018 3:53 pm At the moment, I've deliberately made this non-obvious, as I feel scripts shouldn't be used for significant control functions.
I completely agree.. :)

João

Re: Script Language

Posted: Wed Jan 24, 2018 8:21 pm
by planger
That's not the idea... I woud like my script to run when my model is loaded. It should work in background all the time and display information when you request it.
I could use a switch and only display when it is pushed but I was thinking of a better integration within the radio. I don't know if that's hard to do or not... But if you don't ask...

Re: Script Language

Posted: Wed Jan 24, 2018 10:10 pm
by jhsa
I probably was talking something a bit different, which is, when a script needs to show data on a screen, it could create a new screen when it is running, and actually not use the telemetry custom screens... This would be nice.

João

Re: Script Language

Posted: Wed Jan 24, 2018 11:08 pm
by MikeB
Not at present. You have:
1. A standalone script that writes to the LCD, no menus run.
Or
2. 1 or 2 "Telemetry" scripts that write to the custom telemetry screens, menus run unless the custom telemetry screen is selected.
3. A model scrip that runs in the background, and cannot write to the display, menus run normally.

Scripts run before menus, so if a script as the display available, the menus do not run.

Mike

Re: Script Language

Posted: Thu Jan 25, 2018 12:04 am
by jhsa
It was just an idea

Thanks

João

Re: Script Language

Posted: Thu Jan 25, 2018 8:00 am
by planger
Mike, what about haptic?
Can we get a haptic/vibrate instruction?

Re: Script Language

Posted: Thu Jan 25, 2018 10:25 am
by MikeB
I'll look into what is possible, I don't, currently, have a low level function to drive the haptic in that way.
A work-around, for now, is to configure a voice alarm to play one of the three, pre-defined, haptic outputs, trigger the voice alarm using a logical switch, and then set the logical switch from the script to play the haptic!

Mike

Re: Script Language

Posted: Thu Jan 25, 2018 10:28 am
by planger
simple and working :D

Re: Script Language

Posted: Thu Jan 25, 2018 11:40 am
by jhsa
Simple for you ;) :mrgreen:

João

Sent from my BLN-L21 using Tapatalk


Re: Script Language

Posted: Thu Jan 25, 2018 2:34 pm
by MikeB
I've done a change to the "playfile" function. It will now look for the following names:
"Warn1"
"Warn2"
"Cheap"
"Ring"
"SciFi"
"Robot"
"Chirp"
"Tada"
"Crickt"
"Siren"
"AlmClk"
"Ratata"
"Tick"
"Haptc1"
"Haptc2"
"Haptc3"
and if one is found, then the corresponding audio sound will be played (or the haptic run for the last three).

There may still be a better implementation, but this was easy to do.

Mike

Re: Script Language

Posted: Thu Jan 25, 2018 2:51 pm
by planger
...

Re: Script Language

Posted: Thu Jan 25, 2018 2:57 pm
by planger
Note: you shouldn't put the extension .wav in playfile...

Re: Script Language

Posted: Thu Jan 25, 2018 3:02 pm
by planger
Is there a way to empty the play queue? or a parameter to playfile to either queue the file or play it immediately (=empty queue+play).

Re: Script Language

Posted: Thu Jan 25, 2018 4:35 pm
by MikeB
At the bottom of the model voice menu there is a "Voice Flush Switch" option, where you select a switch (physical or logical) to empty the play queue. You may set this to a logical switch, then set the switch from the script.

Mike

Re: Script Language

Posted: Thu Jan 25, 2018 6:07 pm
by jhsa
Mike, could this "flush switch" be implemented in every voice Alarm switch? I'll try to explain why :)
the reason is sometimes we would like some information like a telemetry value or alarm that it is very important and need playing immediately, jump to the front of the cue, or delete all events before it. So, if this option was ON when the condition of the switch is true, all the other voice events of the cue would be discarded, and this voice Alarm switch would be played right after.
For example, a battery alarm is being played, or some other events triggered by the user, like altitude, voltage, etc, but suddenly there is a RSSI critical alarm. This should have priority over any other voice event.

The option could be called for example "Voice Flush", and then be ON or OFF.. No need to assign a switch to it in this case as it is triggered by its own voice switch only.. I hope I explained the idea well, you know that my English is far from perfect.. :)

Thanks´

João

EDIT: also, if implemented this way, the current implemented voice flush switch wouldn't be needed, because you could just create a normal voice switch without source / function, and without a voice file selected.
Just assign a switch to it and turn the new option "Voice Flush" ON.
This way, the voice switch would just delete the voice cue without playing any file..

This would solve both problems with just one implementation.. and still keep the things organized.

Re: Script Language

Posted: Thu Jan 25, 2018 11:22 pm
by MikeB
Currently, there could be problems with activating the queue flushing and immediately sending another voice message. The queue flushing operation is done by setting a flag for the voice task to pick up next time it processes the voice queue. It's done this way to avoid having two different tasks both trying to remove items from the queue.

Mike

Re: Script Language

Posted: Fri Jan 26, 2018 1:18 pm
by planger
One more question: How can I access trim switches? I've tried "Atu" and "Atd" with no luck. I've checked and they are not set in the AIL mixer.

Pascal

Re: Script Language

Posted: Fri Jan 26, 2018 2:16 pm
by MikeB
That is supposed to be working, but I just did a test and all eight trims switches "names" seem to be responding to the Ele down trim switch!
Investigating.

Mike

Re: Script Language

Posted: Fri Jan 26, 2018 6:30 pm
by MikeB
OK, I've found the problem, I 'll get an updated test version out, probably tomorrow.

Mike