Advertisement
Guest User

telem1.lua

a guest
Aug 29th, 2015
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.58 KB | None | 0 0
  1. -- ###############################################################
  2. -- #                                                             #
  3. -- #        Telemetry Lua Script Naze32, Version B1.0            #
  4. -- #                                                             #
  5. -- #  + naze32 telemetry enabled                                 #
  6. -- #  + tested with D4r-II                                       #
  7. -- #                                                             #
  8. -- #  License (Script & images): Share alike                     #
  9. -- #  Can be used and changed non commercial                     #
  10. -- #                                                             #
  11. -- #  Inspired by SockEye, Richardoe, Schicksie, lichtl          #
  12. -- #                                                             #
  13. -- #  Änderungen: ben_ FPV-Community                            #
  14. -- #                                                             #
  15. -- ###############################################################
  16.  
  17.     local function run(event)
  18.  
  19. -- ###############################################################
  20. -- Batteriestand Leer | Einfach anpassen
  21. -- ###############################################################
  22.  
  23.     local four_low=13.5                                                                     -- Akku 4s | Warnung, Entladezustand, Restspannung
  24.     local three_low=10.6                                                                    -- Akku 3s | Warnung, Entladezustand, Restspannung
  25.    
  26. -- ###############################################################
  27. -- Batteriestand Voll | Einfach anpassen
  28. -- ###############################################################
  29.  
  30.     local four_high=16.5                                                                    -- Akku 4s | Ladezustand, Spannung bei vollem Akku
  31.     local three_high=12.5                                                                   -- Akku 3s | Ladezustand, Spannung bei vollem Akku                                 
  32.  
  33. -- ###############################################################
  34. -- Batteriestand
  35. -- ###############################################################
  36.    
  37.     local battype = 3
  38.     local battypestr="_S"
  39.     local percent=0                                                        
  40.     local batt_sum = getValue("Cels")                                                       -- old "cell-sum" -> Cels
  41.        
  42.     if batt_sum>3 then
  43.         battype=math.ceil(batt_sum/4.25)
  44.     if battype==4 then
  45.         battypestr="4S"
  46.         percent = (batt_sum-four_low)*(100/(four_high-four_low))
  47.     end
  48.     if battype==3 then
  49.         battypestr="3S"
  50.         percent = (batt_sum-three_low)*(100/(three_high-three_low))
  51.     end
  52.     end
  53.    
  54.     local myPxHeight = math.floor(percent * 0.37)              
  55.     local myPxY = 11 + 37 - myPxHeight
  56.  
  57.         lcd.drawPixmap(3, 1, "/SCRIPTS/BMP/battery.bmp")
  58.  
  59.     if percent > 0 then
  60.         lcd.drawFilledRectangle(8, myPxY, 21, myPxHeight, FILL_WHITE )
  61.     end
  62.  
  63.     local i = 36
  64.     while (i > 0) do
  65.         lcd.drawLine(7, 11 + i, 27, 11 +i, SOLID, GREY_DEFAULT)
  66.         i= i-2
  67.     end
  68.     --if (percent < 50) then
  69.     --playFile("SOUNDS/en/5Left.wav")
  70.     --end
  71.     if (percent < 15) then
  72.         lcd.drawNumber(4,55, batt_sum  ,PREC2 + LEFT + BLINK)
  73.     else
  74.         lcd.drawNumber(4,55, batt_sum  ,PREC2 + LEFT)
  75.     end
  76.         lcd.drawText(lcd.getLastPos(), 55, "v ", 0)
  77.         lcd.drawText(lcd.getLastPos(), 55,battypestr,0)
  78.  
  79. -- ###############################################################
  80. -- Timer
  81. -- ###############################################################
  82.  
  83.     local timer = model.getTimer(0)
  84.         lcd.drawText(98, 45, "Timer:",SMLSIZE, 0)
  85.         lcd.drawTimer(133, 41, timer.value, MIDSIZE)
  86.  
  87. -- ###############################################################
  88. -- Cell voltage / Clock
  89. -- ###############################################################
  90.    
  91.         lcd.drawText(38,3, "Cell:",SMLSIZE,0)                                                                   -- this is a custom sensor - use whatever senssor you have or switch to clock below
  92.         lcd.drawNumber(38, 12, getValue("Cell"), PREC2 +LEFT+MIDSIZE)                       -- lcd.drawTimer(38, 12, getValue(190), LEFT+MIDSIZE)
  93.  
  94. -- ###############################################################
  95. -- Gas Anzeige in %
  96. -- ###############################################################
  97.        
  98.     function round(num, idp)
  99.     local mult = 10^(idp or 0)
  100.     return math.floor(num * mult + 0.5) / mult
  101.     end
  102.  
  103.         lcd.drawText(98, 31,"THR %: ",SMLSIZE, 0)
  104.         lcd.drawText(133,27,"    ",MIDSIZE,0)
  105.         lcd.drawText(133,27,round((getValue(MIXSRC_Thr)/10.24)/2+50,0),MIDSIZE,0)
  106.  
  107. -- ###############################################################
  108. -- Modellbezeichnung zum ändern hier
  109. -- ###############################################################
  110.  
  111.         lcd.drawText(98,12,"ZMR250",MIDSIZE)                                            -- model text, moved up top since I don't use baro modes
  112.        
  113. -- ###############################################################
  114. -- Flugmode Bild
  115. -- ###############################################################
  116.        
  117.         lcd.drawPixmap(65, 1, "/SCRIPTS/BMP/fm.bmp")                                    -- this is using a custom quadcopter icon, adjust to fit (i didn't like the plane)
  118.  
  119. -- ###############################################################
  120. -- Flightcontrol    DISARMED/ARMED                      switch SF
  121. -- ###############################################################
  122.  
  123.     if getValue(MIXSRC_SF)<0 then                                                       -- switch SF
  124.         lcd.drawText(38, 31, "FC DISARMED",SMLSIZE)
  125.     else
  126.         lcd.drawText(38, 31, "FC ARMED     ",SMLSIZE)                                   -- added spaces
  127.     end
  128.    
  129. -- ###############################################################
  130. -- Beeper           ON/OFF                              switch SA
  131. -- ###############################################################
  132.  
  133.     if getValue(MIXSRC_SA)<0 then                                                       -- switch SA
  134.         lcd.drawText(38, 45, "BEEPER OFF",SMLSIZE)
  135.     else
  136.         lcd.drawText(38, 45, "BEEPER ON  ",SMLSIZE)
  137.     end
  138.  
  139. -- ###############################################################         
  140. -- Flightmode1      Level/Horizon/Acro                  switch SD
  141. -- ###############################################################
  142.  
  143.     if getValue(MIXSRC_SD)<0 then                                                       -- switch SD
  144.         lcd.drawText(98,1,"Acro     ",MIDSIZE)                                          -- Startmode
  145.     elseif getValue(MIXSRC_SD) == 0 then                                                -- switch SD
  146.         lcd.drawText(98,1,"Horizon",MIDSIZE)
  147.     else
  148.     lcd.drawText(98,1,"Angle   ",MIDSIZE)                                               -- Level renamed to Angle mode for CleanFlight
  149.     end
  150.  
  151. -- ###############################################################
  152. -- Displays xyz data
  153. -- ###############################################################
  154.  
  155. --  lcd.drawNumber(65,55,getValue("tx-voltage"),PREC1+SMLSIZE,0) -- this doesn't work :(
  156. --  lcd.drawText(lcd.getLastPos(), 56, "v Tx", SMLSIZE)
  157.  
  158. -- ###############################################################
  159. -- Displays RSSI data
  160. -- ###############################################################
  161.  
  162.     if getValue("RSSI") > 38 then
  163.         percent = ((math.log(getValue("RSSI")-28, 10)-1)/(math.log(72, 10)-1))*100
  164.     else
  165.         percent = 0
  166.     end
  167.  
  168.     if percent > 90 then
  169.         lcd.drawPixmap(164, 1, "/SCRIPTS/BMP/RSSI10.bmp")
  170.     elseif percent > 80 then
  171.         lcd.drawPixmap(164, 1, "/SCRIPTS/BMP/RSSI09.bmp")
  172.     elseif percent > 70 then
  173.         lcd.drawPixmap(164, 1, "/SCRIPTS/BMP/RSSI08.bmp")
  174.     elseif percent > 60 then
  175.         lcd.drawPixmap(164, 1, "/SCRIPTS/BMP/RSSI07.bmp")
  176.     elseif percent > 50 then
  177.         lcd.drawPixmap(164, 1, "/SCRIPTS/BMP/RSSI06.bmp")
  178.     elseif percent > 40 then
  179.         lcd.drawPixmap(164, 1, "/SCRIPTS/BMP/RSSI05.bmp")
  180.     elseif percent > 30 then
  181.         lcd.drawPixmap(164, 1, "/SCRIPTS/BMP/RSSI04.bmp")
  182.     elseif percent > 20 then
  183.         lcd.drawPixmap(164, 1, "/SCRIPTS/BMP/RSSI03.bmp")
  184.     elseif percent > 10 then
  185.         lcd.drawPixmap(164, 1, "/SCRIPTS/BMP/RSSI02.bmp")
  186.     elseif percent > 0 then
  187.         lcd.drawPixmap(164, 1, "/SCRIPTS/BMP/RSSI01.bmp")
  188.     else
  189.         lcd.drawPixmap(164, 1, "/SCRIPTS/BMP/RSSI00.bmp")
  190.     end
  191.  
  192.         lcd.drawChannel(178, 55, 200, LEFT)                                             -- dB text not needed, included in value
  193.  
  194.  
  195. end
  196.  
  197. return { run=run }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement