-- Script for displaying GPS location of a model as a QR code. https://github.com/alufers/edgetx-gps-qrcode local function a(b,c)local d=""while b>0 do rest=math.fmod(b,2)d=d..rest;b=math.floor((b-rest)/2)end;for e=#d+1,c do d=d.."0"end;return string.reverse(d)end;local function f(g,h,i,j)if h=="1"then g[i][j]=2 else g[i][j]=-2 end end;local k={19,34,55,80,108,136,156,194,232,274,324}local function l(m)local n=4;local c,o,p,q;local r=40;for s=1,#k do c=k[s]*8;c=c-4;if s<10 then o=8 elseif s<27 then o=10 end;p=c-o;q=math.floor(p*1/13)if q>=m then if s<=r then r=s end;break end end;return r end;local function t(s,u)local v,w;local x=k[s]*8;v=math.min(4,x-#u)if v>0 then u=u..string.rep("0",v)end;if math.fmod(#u,8)~=0 then w=8-math.fmod(#u,8)u=u..string.rep("0",w)end;while#u=C do E=B(C,D)local S=Q[D]for e=D,D-C,-1 do if S~=256 then if E[e]+S>=255 then E[e]=math.fmod(E[e]+S,255)else E[e]=E[e]+S end else E[e]=256 end end;for e=D-C-1,0,-1 do E[e]=256 end;P=J(E)R=J(Q)N={}for e=D,0,-1 do N[e]=bit32.bxor(P[e],R[e])end;O=D;for e=O,0,-1 do if e#g then i=i-2;if i==7 then i=6 end;if az==1 then az=3;j=1 else az=1;j=#g end end end;return T,i,j,az end;local function aC(g,u,an)local ab=#g;local i,j,aD;local aE,aF,aG;local az=1;local aH=0;i,j=ab,ab;for aI=1,#u,8 do byte_end_idx=math.min(aI+7,#u)local aA=string.sub(u,aI,byte_end_idx)aH=aH+1;aD,i,j,az=ay(g,i,j,az,aA)for e=1,#aA do aE=aD[e][1]aF=aD[e][2]aG=av(an,aE,aF,string.sub(aA,e,e))if debugging then g[aE][aF]=aG*(e+10)else g[aE][aF]=aG end end end end;local function aJ(g)local aK,aL,aM=0,0,0;local ab=#g;local aN=0;local aO;local aP;local aQ;for i=1,ab do aQ=0;aO=nil;for j=1,ab do if g[i][j]>0 then aN=aN+1;aP=false else aP=true end;if aO==aP then aQ=aQ+1 else if aQ>=5 then aK=aK+aQ-2 end;aQ=1 end;aO=aP end;if aQ>=5 then aK=aK+aQ-2 end end;for j=1,ab do aQ=0;aO=nil;for i=1,ab do aP=g[i][j]<0;if aO==aP then aQ=aQ+1 else if aQ>=5 then aK=aK+aQ-2 end;aQ=1 end;aO=aP end;if aQ>=5 then aK=aK+aQ-2 end end;for i=1,ab do for j=1,ab do if j0 and g[i+1][j]>0 and g[i][j+1]>0 and g[i+1][j+1]>0)then aL=aL+3 end;if j+60 and g[i][j+1]<0 and g[i][j+2]>0 and g[i][j+3]>0 and g[i][j+4]>0 and g[i][j+5]<0 and g[i][j+6]>0 and(j+10=1 and g[i][j-1]<0 and g[i][j-2]<0 and g[i][j-3]<0 and g[i][j-4]<0)then aM=aM+40 end;if i+6<=ab and g[i][j]>0 and g[i+1][j]<0 and g[i+2][j]>0 and g[i+3][j]>0 and g[i+4][j]>0 and g[i+5][j]<0 and g[i+6][j]>0 and(i+10<=ab and g[i+7][j]<0 and g[i+8][j]<0 and g[i+9][j]<0 and g[i+10][j]<0 or i-4>=1 and g[i-1][j]<0 and g[i-2][j]<0 and g[i-3][j]<0 and g[i-4][j]<0)then aM=aM+40 end end end;local aR=aN/(ab*ab)local aS=math.floor(math.abs(aR*100-50))*2;return aK+aL+aM+aS end;local function aT(s,u,an)local H=au(s,an)aC(H,u,an)local aU=aJ(H)return H,aU end;local function aV(s,u)local H,aU;local aW,aX;aW,aX=aT(s,u,0)for e=1,7 do H,aU=aT(s,u,e)if aU 27 not supported")end;local a_=a(#aZ,o)local b0="0100"..a_;for e=1,#aZ do b0=b0 ..a(string.byte(string.sub(aZ,e,e)),8)end;b0=t(s,b0)local a7=W(s,b0)if math.fmod(#a7,8)~=0 then return nil end;a7=a7 ..string.rep("0",V[s])local H=aV(s,a7)return H end;local b1=false;local b2=15*100;local b3=LCD_W/2;local b4=nil;local b5=false;local b6,b7=0.0,0.0;local b8,b9=0.0,0.0;local ba=false;local bb=nil;local bc=0;local function bd()b4=getFieldInfo("GPS")and getFieldInfo("GPS").id or nil end;local function be()if b4 and getValue(b4)~=0 then local bf=getValue(b4)b8=string.format("%.6f",bf.lat)b9=string.format("%.6f",bf.lon)b5=true end;if ba then ba=false;bb=aY("geo:"..b6 ..","..b7)end end;local function bg()lcd.clear()if not b4 then lcd.drawText(b3-40,LCD_H/2-5,"No GPS sensor")lcd.drawText(b3-45,LCD_H/2+5,"Please discover")return 0 end;if not b5 then lcd.drawText(b3-40,LCD_H/2-5,"No GPS data yet")return 0 end;if b1==true then lcd.drawFilledRectangle(0,0,LCD_W,LCD_H,INVERS)end;local bh=getTime()if not bb or(b6~=b8 or b7~=b9)and bh-bc>=b2 then ba=true;b6=b8;b7=b9;bc=bh end;local bi=64;if bb then bi=#bb*2+4;for i=1,#bb do for j=1,#bb[i]do if bb[i][j]>0 then lcd.drawFilledRectangle(i*2,j*2,2,2)end end end else lcd.drawText(0,20,"QR...")end;if b1==true then lcd.drawFilledRectangle(bi,0,LCD_W-bi,LCD_H,0)end;bi=bi+2;lcd.drawText(bi,5,"Lat")lcd.drawText(bi,15,b8)lcd.drawText(bi,25,"Lon")lcd.drawText(bi,35,b9)lcd.drawText(bi,50,string.format("%.0fs ago",(bh-bc)/100))return 0 end;return{run=bg,init=bd,background=be}