---------------------------------------------------------------------------- -- App für die Telemetriedaten GPSLog2 von A.Straßburg ---------------------------------------------------------------------------- -- Wenn bei Einstellung der Werte der Test auf 1 steht, dann kann mit den Servoausgängen 6-8 -- die aktuelle Höhe , Geschwindigkeit und Entfernung simuliert werden. -- Bei mir waren P6 auf K7 (Gas) und P5 auf K8 (Höhe) sowie P7 auf K6 (Entfernung) -------------------------------------------------------------------------------- -- Lokale Variablen -------------------------------------------------------------------------------- local model, owner = " ", " " local sensorId local speed , hoehe , flricht , pos , richtung , entf , strecke , sat , accx , accy , accz = 1,1,0,0,0,0,0,0,0,0,0 local satm , accxm , accym , acczm = 0,0,0,0 local maxspeed , maxhoehe , switch = 1 , 1 , 0 local Bgrad , Lgrad = " " , " " local spstick , hstick , estick , frstick , sp = 0 , 0 , 0 , 0 , 0 local spmax , hmax , emax = 0 , 0 ,0 ---------------------------------------------------------------------- -- Gebe Balken für den Hoehenwert aus -------------------------------------------------------------------------------- local function hoehebalken(Value, hm) local balken , balmax local bgr,bgg,bgb = lcd.getBgColor() if(bgr+bgg+bgb)/3 >128 then bgr,bgg,bgb = 0,0,0 else bgr,bgg,bgb = 255,255,255 end lcd.setColor(50, 50, 50) -- Dunkel Grau lcd.drawFilledRectangle(0,0,320,160) if Value <= maxhoehe then balken = (Value/maxhoehe * 155) -- Aktuelle Hoehe auf Balkenhöhe 0-155 bringen else balken = 155 -- über Maximum end if hm <= maxhoehe then balmax = (hm/maxhoehe * 155) -- Maxwert auf Balkenhöhe 0-155 bringen else balmax = 155 -- über Maximum end for j = 0 , balken , 1 do --Linke Seite mit aktuellem Wert lcd.setColor(0, 125, math.floor(j*1.64)) lcd.drawLine (1,155-j,157,155-j) end for j = 0 , balmax , 1 do -- Rechte Seite mit Maximalwert lcd.setColor(0, 125, math.floor(j*1.64)) lcd.drawLine (158,155-j,315,155-j) end lcd.setColor(255, 255, 0) -- gelb i = math.floor(lcd.getTextWidth(FONT_NORMAL,string.format("H:%.0f",Value))) -- Ausgabe linkes Fenster j = math.floor(lcd.getTextWidth(FONT_MINI,"m")) k = (i+j) / 2 lcd.drawText(35-k, 2 ,string.format("H:%.0f",Value),FONT_NORMAL) lcd.drawText(37-k+i, 7 ,"m",FONT_MINI) lcd.drawRectangle(5,3,60,19,5) i = math.floor(lcd.getTextWidth(FONT_MINI,"max")) -- Ausgabe rechtes Fenster j = math.floor(lcd.getTextWidth(FONT_NORMAL,string.format("%.0f",hm))) k = math.floor((i+j) / 2 ) lcd.drawText(282-k, 7 ,string.format("max"),FONT_MINI) lcd.drawText(284-k+i, 2 ,string.format("%.0f",hm),FONT_NORMAL) lcd.drawRectangle(253,3,60,19,5) end -------------------------------------------------------------------------------- -- Gebe die Tachoanzeige aus -------------------------------------------------------------------------------- local function tacho(te,tmax) local i , zeiger local zx , zy = 0.0 , 0.0 local radius , ra , tempo = 155 , 155 , 0 local x , y , x1 , y1 = 156 , 156 , 0 , 0 local bgr,bgg,bgb = lcd.getBgColor() local x0 , y0 = 156 , 156 -- Nullpunkt Radius Tacho if(bgr+bgg+bgb)/3 >128 then bgr,bgg,bgb = 0,0,0 else bgr,bgg,bgb = 255,255,255 end tempo = math.floor(te) ------------- Zeichne den Tacho ---------- lcd.setColor(255, 255, 255) -- weiss lcd.setColor(255, 255, 0) -- gelb lcd.setClipping(2,2,314,155) for i=0 , 10 , 1 do -- oberen gelben Halbkreis zeichnen lcd.drawCircle (x0,y0,155-i) lcd.drawCircle (x0+1,y0,155-i) end lcd.setColor(0,0,0) -- Skalierung in 9 Grad schritten for zeiger = 0 , 180 , 9 do if zeiger <= 90 then zy = math.sin(math.rad(zeiger)) * ra zx = math.sqrt((ra*ra) - (zy*zy)) x1 = math.floor(x0 - zx) -- Da links von 0 y1 = math.floor(y0 - zy) else zeiger = 180 - zeiger zy = math.sin(math.rad(zeiger)) * ra zx = math.sqrt((ra*ra) - (zy*zy)) x1 = math.floor(x0 + zx) y1 = math.floor(y0 - zy) end lcd.drawLine(x+1,y,x1+1,y1) -- Zeiger zeichnen , bleibt nachher dann nur die Sklalierung übrig end lcd.setColor(255, 255, 0) -- unteren gelben Halbkreis zeichnen for i=0 , 15 , 1 do lcd.drawCircle (x0,y0,i+1) lcd.drawCircle (x0+1,y0,i+1) end j = 255 for i=11 , 140 , 1 do -- den roten Inhalt zeichnen lcd.setColor(j, 0, 0) j = j-2 lcd.drawCircle (x0,y0,155-i) lcd.drawCircle (x0+1,y0,155-i) lcd.drawCircle (x0,y0,155-i) lcd.drawCircle (x0+1,y0,155-i) end lcd.resetClipping() lcd.setColor(0,0,0) -- Tachobeschriftung schwarz j = math.floor(lcd.getTextWidth(FONT_MINI,string.format("%.f",maxspeed))/2) lcd.drawText(4, 138,"0",FONT_NORMAL) lcd.drawText(x0+4-j,11 ,string.format("%.0f",(maxspeed/2)),FONT_NORMAL) lcd.drawText(300-lcd.getTextWidth(FONT_NORMAL,string.format("%.f",maxspeed))/2,138 ,string.format("%.0f",maxspeed),FONT_NORMAL) lcd.setColor(255, 255, 0) -- Textfarbe gelb lcd.drawText(144, 110,"Kmh",FONT_NORMAL) lcd.setColor(bgr,bgg,bgb) -- Zeiger berechnen if tempo <= maxspeed then zeiger = tempo/maxspeed * 180 -- max 180° else zeiger = 180 end if zeiger <= 90 then zy = math.sin(math.rad(zeiger)) * radius zx = math.sqrt((radius*radius) - (zy*zy)) x1 = math.floor(x0 - zx) -- Da links von 0 y1 = math.floor(y0 - zy) else zeiger = 180 - zeiger zy = math.sin(math.rad(zeiger)) * radius zx = math.sqrt((radius*radius) - (zy*zy)) x1 = math.floor(x0 + zx) y1 = math.floor(y0 - zy) end lcd.drawLine(x+1,y,x1+1,y1) -- Zeiger zeichnen leicht spitz daher 5 Linien lcd.drawLine(x,y,x1+1,y1) lcd.drawLine(x+2,y,x1+1,y1) lcd.drawLine(x-1,y,x1+1,y1) lcd.drawLine(x+3,y,x1+1,y1) lcd.setColor(255, 255, 0) -- gelb lcd.drawRectangle(105,30,100,55,5) -- Ausgabe der Geschwindigkeit und der höchsten Wertes lcd.drawText(113, 29 ,"Geschwindigkeit",FONT_MINI) i = math.floor(lcd.getTextWidth(FONT_MAXI,string.format("%.f",tempo))) -- Länge Zahl j = math.floor(lcd.getTextWidth(FONT_MINI,"km/h")) -- Länge Text k = (i+j) / 2 lcd.drawText(x-k, 36 ,string.format("%.0f",tempo),FONT_MAXI) lcd.drawText(x-k+i+2, 57 ,"km/h",FONT_MINI) i = math.floor(lcd.getTextWidth(FONT_MINI,string.format("max: %.f km/h",tmax)) / 2) lcd.drawText(x+2-i, 69 ,string.format("max: %.0f km/h",tmax),FONT_MINI) end -------------------------------------------------------------------------------- -- Gebe die Entfernung aus -------------------------------------------------------------------------------- local function entfernung(ef,em) lcd.setColor(255, 255, 0) -- gelb lcd.drawRectangle(45,95,84,55,5) -- Ausgabe der Geschwindigkeit und des höchsten Wertes lcd.drawText(57, 95 ,"Entfernung",FONT_MINI) i = math.floor(lcd.getTextWidth(FONT_MAXI,string.format("%.f",ef))) j = math.floor(lcd.getTextWidth(FONT_MINI,string.format(" m"))) k = (i+j) / 2 lcd.drawText(88-k, 102 ,string.format("%.0f",ef),FONT_MAXI) lcd.drawText(88-k + i, 122 ," m",FONT_MINI) i = math.floor(lcd.getTextWidth(FONT_MINI,string.format("max: %.f",em)) / 2) lcd.drawText(82-i, 135 ,string.format("max: %.0fm",em),FONT_MINI) end -------------------------------------------------------------------------------- -- Gebe die Flugrichtung aus -------------------------------------------------------------------------------- local function flugrichtung(fr) local flr lcd.setColor(255, 255, 0) -- gelb lcd.drawRectangle(188,95,84,55,5) -- Ausgabe der Flugrichtung 0-360° lcd.drawText(197, 95 ,"Flugrichtung",FONT_MINI) if fr > 337 then flr = "NNW" elseif fr >= 315 then flr = "NW" elseif fr >= 293 then flr = "WNW" elseif fr >= 270 then flr = "W" elseif fr >= 247 then flr = "WSW" elseif fr >= 225 then flr = "SW" elseif fr >= 203 then flr = "SSW" elseif fr >= 180 then flr = "S" elseif fr >= 158 then flr = "SSO" elseif fr >= 135 then flr = "SO" elseif fr >= 113 then flr = "OSO" elseif fr >= 90 then flr = "O" elseif fr >= 68 then flr = "ONO" elseif fr >= 45 then flr = "NO" elseif fr >= 23 then flr = "NNO" else flr = "N" end i = math.floor(lcd.getTextWidth(FONT_MAXI,flr) / 2) -- Textausgabe des Wertes in ° lcd.drawText(230-i, 102 ,flr,FONT_MAXI) i = math.floor(lcd.getTextWidth(FONT_MINI,string.format("Richtung: %.0f",fr)) / 2) lcd.drawText(230-i, 135 ,string.format("Richtung: %.0f°",fr),FONT_MINI) end -------------------------------------------------------------------------------- -- Telemetriefenster Seite 1 mit Graphikausgaben -------------------------------------------------------------------------------- local function Page1(width, height) if switch == 1 then -- Demomodus hoehebalken(hstick,hmax) tacho(spstick,spmax) entfernung(estick,emax) flugrichtung(frstick) else -- Telemetriewerte hoehebalken(hoehe,hmax) tacho(speed,spmax) entfernung(entf,emax) flugrichtung(flricht) end end -------------------------------------------------------------------------------- -- Telemetriefenster Seite 2 mit Werteausgaben in Fenstern -------------------------------------------------------------------------------- local function Page2(width, height) for i=1 , 160 , 1 do -- den roten Inhalt zeichnen lcd.setColor(255-i, 0, 0) lcd.drawLine(0,i,317,i) end -- Ausgabe der GPS-Koordinaten ------------------------------------------------ lcd.setColor(255, 255, 0) -- gelb lcd.drawRectangle(2,2,130,50,5) lcd.drawText(32, 3," GPS Position" , FONT_MINI) lcd.drawText(4, 13,"B:", FONT_BIG) lcd.drawText(19, 13,string.format("%s",Bgrad) , FONT_BIG) lcd.drawText(4, 30,"L:" , FONT_BIG) lcd.drawText(19, 30, string.format("%s",Lgrad), FONT_BIG) -- Ausgabe Anzah Satelliten ------------------------------------------------ lcd.drawRectangle(2,54,130,50,5) lcd.drawText(8, 55," Anz. Satelliten / Max" , FONT_MINI) lcd.drawText(30, 65,string.format("%.0f / %.0f",sat,satm) , FONT_MAXI) -- Ausgabe der zurückgekegten Strecke ------------------------------------------------ lcd.drawRectangle(2,106,130,50,5) lcd.drawText(22, 106,"geflogene Strecke" , FONT_MINI) i = lcd.getTextWidth(FONT_MAXI,string.format("%.0f",strecke)) j = lcd.getTextWidth(FONT_MINI,string.format("m")) k = (i+j) /2 lcd.drawText(65-k, 117,string.format("%.0f",strecke) , FONT_MAXI) lcd.drawText(57+k, 137,"m" , FONT_MINI) -- Ausgabe der ACC-Werte ------------------------------------------------ lcd.drawRectangle(135,2,180,88,5) lcd.drawText(165, 3,"Beschleunigung X Y Z" , FONT_MINI) lcd.drawText(145, 15,string.format("X: %.2f",accx) , FONT_BIG) i = lcd.getTextWidth(FONT_BIG,string.format("X: %.2f",accx)) lcd.drawText(148 + i, 22,"g" , FONT_MINI) lcd.drawText(235 , 22,"max" , FONT_MINI) lcd.drawText(263,18,string.format("%.2f",accxm) , FONT_BOLD) i = lcd.getTextWidth(FONT_BOLD,string.format("%.2f",accxm)) lcd.drawText(265 + i, 22,"g" , FONT_MINI) lcd.drawText(145, 40,string.format("Y: %.2f",accy) , FONT_BIG) i = lcd.getTextWidth(FONT_BIG,string.format("Y: %.2f",accy)) lcd.drawText(148 + i, 47,"g" , FONT_MINI) lcd.drawText(235 , 47,"max" , FONT_MINI) lcd.drawText(263,43,string.format("%.2f",accym) , FONT_BOLD) i = lcd.getTextWidth(FONT_BOLD,string.format("%.2f",accym)) lcd.drawText(265 + i, 47,"g" , FONT_MINI) lcd.drawText(145, 65,string.format("Z: %.2f",accz) , FONT_BIG) i = lcd.getTextWidth(FONT_BIG,string.format("Z: %.2f",accz)) lcd.drawText(148 + i, 72,"g" , FONT_MINI) lcd.drawText(235 , 72,"max" , FONT_MINI) lcd.drawText(263,68,string.format("%.2f",acczm) , FONT_BOLD) i = lcd.getTextWidth(FONT_BOLD,string.format("%.2f",acczm)) lcd.drawText(265 + i, 72,"g" , FONT_MINI) -- Ausgabe der Richtung ( relativ, bezogen auf den Startpunkt ---------------- lcd.drawRectangle(135,92,87,64,5) lcd.drawText(143, 93,"Richtung bez." , FONT_MINI) lcd.drawText(141, 107,"auf Startpunkt" , FONT_MINI) i = lcd.getTextWidth(FONT_MAXI,string.format("%.0f°",richtung)) / 2 lcd.drawText(180-i, 117,string.format("%.0f°",richtung) , FONT_MAXI) -- Ausgabe der Richtung (Position , Richtung vom Startpunkt zum Modell ------- lcd.drawRectangle(226,92,88,64,5) lcd.drawText(233, 94,"Richtung vom" , FONT_MINI) lcd.drawText(232, 108,"SP zum Modell" , FONT_MINI) i = lcd.getTextWidth(FONT_MAXI,string.format("%.0f°",pos)) / 2 lcd.drawText(271-i, 117,string.format("%.0f°",pos) , FONT_MAXI) end -------------------------------------------------------------------------------- -- Änderungen der Einstellungen speichern -------------------------------------------------------------------------------- local function sensorChanged(value) sensorId = sensorsAvailable[value].id system.pSave("sensorId", sensorId) end local function maxspeedChanged(value) maxspeed = value system.pSave("maxspeed", maxspeed) end local function maxhoeheChanged(value) maxhoehe = value system.pSave("maxhoehe", maxhoehe) end local function switchChanged(value) switch=value system.pSave("switch",switch) end -------------------------------------------------------------------------------- -- Variablen-Eingabe -------------------------------------------------------------------------------- local function setupForm(formID) sensorsAvailable = {} local available = system.getSensors(); local list={} local curIndex=-1 local descr = "" for index,sensor in ipairs(available) do if(sensor.param == 0) then list[#list+1] = sensor.label sensorsAvailable[#sensorsAvailable+1] = sensor if(sensor.id==sensorId ) then curIndex=#sensorsAvailable end end end local form, addRow, addLabel = form, form.addRow ,form.addLabel local addIntbox, addSelectbox = form.addIntbox, form.addSelectbox local addInputbox, addCheckbox = form.addInputbox, form.addCheckbox local setTitle, addSpacer = form.setTitle, form.addSpacer setTitle("Einstellungen Werte") addSpacer(318,7) addRow(2) addLabel({label = "Sensorauswahl", width=200}) addSelectbox(list, curIndex, true, sensorChanged) addRow(2) addLabel({label="Max Speed (Kmh)", width=230}) addIntbox(maxspeed, 0,500, 200, 0, 10, maxspeedChanged) addRow(2) addLabel({label="Max Höhe (m)", width=230}) addIntbox(maxhoehe, 0,500, 250, 0, 10, maxhoeheChanged) addRow(2) addLabel({label="Test (0=nein)(1=ja)", width=230}) addIntbox(switch, 0,1, 1, 0, 1, switchChanged) addSpacer(0,20) addLabel({label="Powered by A.Strassburg "..Version.." ", font=FONT_MINI, alignRight=true}) end -------------------------------------------------------------------------------- -- Endlosschleife -------------------------------------------------------------------------------- local function loop() -- Test mit P6 (Gas) und P5 (Höhe) sowie P7 (Entfernung)als Wertegeber if switch == 1 then spstick = system.getInputs("O7") spstick = (spstick + 1) / 2 -- somit einen Bereich von 0 - 1 spstick = spstick * maxspeed * 1.2 -- damit bei Vollausschlag auch maxspeed + 20 % if spmax < spstick then spmax = spstick end hstick = system.getInputs("O8") hstick = (hstick + 1) / 2 hstick = math.floor(hstick * maxhoehe * 1.2) -- max + 20% if hmax < hstick then hmax = hstick end estick = system.getInputs("O6") estick = (estick + 1) / 2 estick = math.floor(estick * 900) -- max 900m if emax < estick then emax = estick end frstick = estick / 900 * 360 -- max 360° end -- Read Sensor ID 3 Breitengrad sensor = system.getSensorByID(sensorId, 3) if(sensor and sensor.valid) then if(sensor.type == 9) then -- GPS coordinates local nesw = {"N", "O", "S", "W"} local minutes = (sensor.valGPS & 0xFFFF) * 0.001 local degs = (sensor.valGPS >> 16) & 0xFF Bgrad = string.format("%3d°%2.3f'%s", degs, minutes, nesw[sensor.decimals+1]) else Bgrad = "23° 45.678' N" end end -- Read Sensor ID 4 Längengrad sensor = system.getSensorByID(sensorId, 4) if(sensor and sensor.valid) then if(sensor.type == 9) then -- GPS coordinates local nesw = {"N", "O", "S", "W"} local minutes = (sensor.valGPS & 0xFFFF) * 0.001 local degs = (sensor.valGPS >> 16) & 0xFF Lgrad = string.format("%3d°%2.3f'%s", degs, minutes, nesw[sensor.decimals+1]) else Lgrad = "76° 54.321' O" end end -- Read Sensor ID 5 Speed sensor = system.getSensorByID(sensorId, 5) if(sensor and sensor.valid) then speed = sensor.value if spmax < speed then spmax = speed end end -- Read Sensor ID 6 Hoehe sensor = system.getSensorByID(sensorId, 6) if(sensor and sensor.valid) then hoehe = sensor.value if hmax < hoehe then hmax = hoehe end end -- Read Sensor ID 9 Flugrichtung sensor = system.getSensorByID(sensorId, 9) if(sensor and sensor.valid) then flricht = sensor.value else if switch == 1 then flricht = math.random() * 360 end end -- Read Sensor ID 10 Position sensor = system.getSensorByID(sensorId, 10) if(sensor and sensor.valid) then pos = sensor.value else if switch == 1 then pos = math.random() * 360 end end -- Read Sensor ID 11 Richtung sensor = system.getSensorByID(sensorId, 11) if(sensor and sensor.valid) then richtung = sensor.value else if switch == 1 then richtung = math.random() * 360 end end -- Read Sensor ID 12 Entfernung sensor = system.getSensorByID(sensorId, 12) if(sensor and sensor.valid) then entf = sensor.value if emax < entf then emax = entf end end -- Read Sensor ID 13 Strecke sensor = system.getSensorByID(sensorId, 13) if(sensor and sensor.valid) then strecke = sensor.value else strecke = 1234 end -- Read Sensor ID 14 Satteliten sensor = system.getSensorByID(sensorId, 14) if(sensor and sensor.valid) then sat = sensor.value if satm < sat then satm = sat end else if switch == 1 then sat = math.floor(math.random() * 10) if satm < sat then satm = sat end end end -- Read Sensor ID 20 Acc_X sensor = system.getSensorByID(sensorId, 20) if(sensor and sensor.valid) then accx = sensor.value else if switch == 1 then accx = (math.random()-0.5) * 19.99 end end if accxm < math.abs(accx) then accxm = math.abs(accx) end -- Read Sensor ID 21 Acc_Y sensor = system.getSensorByID(sensorId, 21) if(sensor and sensor.valid) then accy = sensor.value else if switch == 1 then accy = (math.random()-0.5) * 19.99 end end if accym < math.abs(accy) then accym = math.abs(accy) end -- Read Sensor ID 22 Acc_Z sensor = system.getSensorByID(sensorId, 22) if(sensor and sensor.valid) then accz = sensor.value else if switch == 1 then accz = (math.random()-0.5) * 19.99 end end if acczm < math.abs(accz)then acczm = math.abs(accz) end end -------------------------------------------------------------------------------- -- Initialisierung -------------------------------------------------------------------------------- local function init(code1) model = system.getProperty("Model") sensorId = system.pLoad("sensorId", 0) maxspeed = system.pLoad("maxspeed",0) maxhoehe = system.pLoad("maxhoehe",0) switch = system.pLoad("switch",0) system.registerForm(1, MENU_APPS, "GPS-Log2", setupForm) system.registerTelemetry(1, "Seite 1".." "..model, 4, Page1) -- Volle Seite 1 system.registerTelemetry(2, "Seite 2".." "..model, 4, Page2) -- Volle Seite 2 end -------------------------------------------------------------------------------- Version = "1.0" collectgarbage() return {init=init, loop=loop, author="A.Strassburg", version=Version, name="GPS-Log2"}