Thread Tools
This thread is privately moderated by l shems, who may elect to delete unwanted replies.
Nov 14, 2017, 01:45 PM
Have Fun and Just Fly!
l shems's Avatar
Discussion

making the Horus Graph script usable for the Taranis


OK, last topic to cover in this series.

We have succesfully made a graph showing some source value with a 'One-time' script, and used some library functions to get it loaded as a widget.

Now I want to use it on the Taranis as well. Let's first just run it and see what happens:

Quote:
Script error: /Scripts/TELEM/Graph.lua:68: bad argument #6 to 'drawLine' (number expected, got nil)
So what's on line 68:
Code:
    lcd.drawLine(0          ,P.y0    ,LCD_W-1    ,P.y0      ,DOTTED ,CURVE_AXIS_COLOR)
Well, something must be provided here, but this global is not known on the Taranis, so it get's a nil value.
Let's add it at the first line of the script, and give it some value we DO know in the Taranis. And at the same time define the other colors:
Code:
CURVE_AXIS_COLOR = GREY(12)
LINE_COLOR = GREY(8)
CURVE_COLOR = GREY(4)
TEXT_COLOR = GREY(15) 
MAINVIEW_PANES_COLOR = GREY_DEFAULT
Well, it's running (either use the standard "go.lua" script we wrote in the other post, or add the 'background()' call to the first line of the 'run' command.)

Name: screenshot_x9d+_17-11-14_20-41-16.png
Views: 41
Size: 1.4 KB
Description:

Sign up now
to remove ads between posts
Nov 14, 2017, 01:56 PM
Have Fun and Just Fly!
l shems's Avatar

Dotted lines ??!!


That wasn't that hard

We do have some issues though:

I dont like the colors
the lines seem dotted.

the second problem lies in the greyscale plotting. Plotting a dot with the same color on top of an existing dot, erases it. Unless you specify the FORCE argument:
Code:
LINE_COLOR = GREY(8) + FORCE
CURVE_COLOR = GREY(4) + FORCE
Name: screenshot_x9d+_17-11-14_20-50-02.png
Views: 9
Size: 1.2 KB
Description:
That looks already a lot better.

Now fix the background color, that we assigned to the PANES:
Code:
MAINVIEW_PANES_COLOR = GREY(15)
Name: screenshot_x9d+_17-11-14_20-54-49.png
Views: 7
Size: 1.2 KB
Description:

Well, That's it. Done!!!
Nov 14, 2017, 02:57 PM
Have Fun and Just Fly!
l shems's Avatar

Tidying up


Well, this approach was not tht nice. We messed with the original script again.

Why not use a separate script to do it tidy:
"/SCRIPTS/L/Tutorial/color.lua":
Code:
SHADOWED = SHADOWED or 0

WHITE = GREY(15) 
YELLOW = GREY(14)
LIGHTGREY = GREY(12)
--GREY = GREY(8)
BLUE = GREY(9)
DARKGREY = GREY(8)
RED = GREY(4)
DARKRED = GREY(2)
BLACK = GREY(0)

TEXT_COLOR = WHITE
LINE_COLOR = DARKGREY + FORCE
CURVE_AXIS_COLOR = LIGHTGREY
LINE_COLOR = DARKGREY + FORCE
CURVE_COLOR = RED + FORCE
MAINVIEW_PANES_COLOR = WHITE
We have first defined the main color codes known in Horus, and then assigned them to the zones.
Mind the FORCE we added to the colors used for graph curves and lines, to prevent the dotting .

Now we just need to adapt our script loader to include these globals in the environment used for the script. We don't want to declare them globally if we run telemetry scripts. Unless we want to use the same color scheme for all Horus scripts we are running as seperate telemetry screens.

So "/Go.lua":
Code:
local Legacy = false
local ENV={}
loadfile("SCRIPTS/L/Tutorial/color.lua","bt",ENV)()
local script =  loadfile("/SCRIPTS/TELEM/graph.lua","bt",ENV)()

local run = function (event)
  if not Legacy then --legacy scripts will call the background from the run themselves
    if script.background
      then script.background()
    end
  end
  return script.run(event) or 0
end

return {run=run, init=script.init}
That's way nicer

now we only need to autodetect the LCD type used, and decide to call the color definitions or not:
Code:
local ENV={}

if LCD_W ~= 480 then
  loadfile("SCRIPTS/L/Tutorial/color.lua","bt",ENV)()
end

local script =  loadfile("/SCRIPTS/TELEM/graph.lua","bt",ENV)()
Ok, that's about it. We still need to cover the 'lcd.refresh' function, and the 'lcd.setColor' and 'lcd.RGB', but hey, we"ll figure that out later.

The concept is there, we got our script running on the Taranis. Just add any colors that are missing.



But you can understand that if you want to be able to run any Horus script, we still need the widgets to work. That has been covered in the other topic, and adding the color support there, is not that difficult anymore.

So,

Have fun and just Fly!!


Quick Reply
Message:
Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Discussion F3K program for Taranis QX7 and X9D with scripts for score keeping and graphing jfrickmann Hand Launch 607 Sep 20, 2018 03:24 AM
Discussion how to get nigelsheffields lua scripts for Taranis to work. nigelsheffield Radios 197 Apr 11, 2017 08:56 AM