From 8446e69bce5dd62036573af2826f6c32d8ee9ef0 Mon Sep 17 00:00:00 2001 From: Christian Haeusler <794584+corvus-ch@users.noreply.github.com> Date: Sat, 12 Oct 2024 21:35:19 +0200 Subject: [PATCH 1/3] Streamline fetching of GPS grid * Directly write to cache file * Ignore errors while communicating with gpds * Calculate gird only on eactive GPS fix * Remove unused imports * Reduce grid presicion --- data/conky/get-grid | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) mode change 100644 => 100755 data/conky/get-grid diff --git a/data/conky/get-grid b/data/conky/get-grid old mode 100644 new mode 100755 index 20f6100..1e5151b --- a/data/conky/get-grid +++ b/data/conky/get-grid @@ -2,22 +2,21 @@ require 'gpsd_client' require 'maidenhead' -require 'socket' -require 'json' -ft8call_port = 2237 +output = "No GPS" -gpsd = GpsdClient::Gpsd.new() -gpsd.start() -apicmd = {} +begin + gpsd = GpsdClient::Gpsd.new() + gpsd.start() -# get maidenhead if gps is ready -if gpsd.started? - pos = gpsd.get_position - maid = Maidenhead.to_maidenhead(pos[:lat], pos[:lon], precision = 5) -# puts "lat = #{pos[:lat]}, lon = #{pos[:lon]}, grid = #{maid}" - apicmd = {:type => "STATION.SET_GRID", :value => maid} -end + if gpsd.started? + pos = gpsd.get_position + unless pos[:lat].nil? or pos[:lon].nil? + output = Maidenhead.to_maidenhead(pos[:lat], pos[:lon], precision = 4) + end + end -puts "#{maid}" + gpsd.stop() +end +File.write(File.join("/run/user", Process.uid.to_s, "gridinfo.txt"), output) From 30299b02269f0995a1fff7f70f4b6417e2ceeff6 Mon Sep 17 00:00:00 2001 From: Christian Haeusler <794584+corvus-ch@users.noreply.github.com> Date: Sat, 12 Oct 2024 21:38:51 +0200 Subject: [PATCH 2/3] Remove bash wrapper --- data/conky/get-grid | 22 ---------------------- data/conky/grid | 32 +++++++++++++++++++------------- 2 files changed, 19 insertions(+), 35 deletions(-) delete mode 100755 data/conky/get-grid mode change 100644 => 100755 data/conky/grid diff --git a/data/conky/get-grid b/data/conky/get-grid deleted file mode 100755 index 1e5151b..0000000 --- a/data/conky/get-grid +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env ruby - -require 'gpsd_client' -require 'maidenhead' - -output = "No GPS" - -begin - gpsd = GpsdClient::Gpsd.new() - gpsd.start() - - if gpsd.started? - pos = gpsd.get_position - unless pos[:lat].nil? or pos[:lon].nil? - output = Maidenhead.to_maidenhead(pos[:lat], pos[:lon], precision = 4) - end - end - - gpsd.stop() -end - -File.write(File.join("/run/user", Process.uid.to_s, "gridinfo.txt"), output) diff --git a/data/conky/grid b/data/conky/grid old mode 100644 new mode 100755 index 5cb0de8..1e5151b --- a/data/conky/grid +++ b/data/conky/grid @@ -1,16 +1,22 @@ -#!/bin/bash +#!/usr/bin/env ruby -#script get maidenhead from GPS for display in conky -#called by cronjob -#04FEB2021 KM4ACK +require 'gpsd_client' +require 'maidenhead' -GRID=$($HOME/bin/conky/get-grid) -GRIDCH=$(echo $GRID | grep -i JJ00) -FILE=/run/user/$UID/gridinfo.txt +output = "No GPS" -if [ -z "$GRIDCH" ] -then -echo $GRID > $FILE -else -echo "NO GPS" > $FILE -fi \ No newline at end of file +begin + gpsd = GpsdClient::Gpsd.new() + gpsd.start() + + if gpsd.started? + pos = gpsd.get_position + unless pos[:lat].nil? or pos[:lon].nil? + output = Maidenhead.to_maidenhead(pos[:lat], pos[:lon], precision = 4) + end + end + + gpsd.stop() +end + +File.write(File.join("/run/user", Process.uid.to_s, "gridinfo.txt"), output) From d65eb843857b09b58a49d063620feef824cf8fef Mon Sep 17 00:00:00 2001 From: Christian Haeusler <794584+corvus-ch@users.noreply.github.com> Date: Sat, 12 Oct 2024 21:48:47 +0200 Subject: [PATCH 3/3] Use Conky's cat instead of execi --- data/conky/7inchscreen.pi | 2 +- data/conky/default.86 | 2 +- data/conky/laptop.86 | 2 +- data/conky/large.pi | 2 +- data/conky/medium.pi | 2 +- data/conky/radio.86 | 2 +- data/conky/small.pi | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/data/conky/7inchscreen.pi b/data/conky/7inchscreen.pi index 7e97fe6..7ac3bcb 100644 --- a/data/conky/7inchscreen.pi +++ b/data/conky/7inchscreen.pi @@ -34,7 +34,7 @@ conky.text = [[ ${font Arial:size=12}${color Yellow}${alignc}N0CALL ${voffset -30} -${font Arial:bold:size=08}${color White}Gridsquare ${alignr}${color Yellow}${execi 60 cat /run/user/1000/gridinfo.txt | cut -c1-8} +${font Arial:bold:size=08}${color White}Gridsquare ${alignr}${color Yellow}${cat /run/user/1000/gridinfo.txt} #${font Arial:bold:size=12}${color White}Radio Freq ${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq | cut -c1-6} ${color Yellow}LOCAL${alignr}ZULU ${voffset -20} diff --git a/data/conky/default.86 b/data/conky/default.86 index fa939d3..8dfaee4 100755 --- a/data/conky/default.86 +++ b/data/conky/default.86 @@ -35,7 +35,7 @@ conky.text = [[ ${voffset -20} ${font Arial:size=30}${color Yellow}${alignc}N0CALL ${voffset -45} -#${font Arial:bold:size=14}${color White}Gridsquare ${alignr}${color Yellow}${execi 60 cat /run/user/1000/gridinfo.txt | cut -c1-8} +${font Arial:bold:size=14}${color White}Gridsquare ${alignr}${color Yellow}${cat /run/user/1000/gridinfo.txt} #${font Arial:bold:size=14}${color White}Radio Freq ${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq | cut -c1-6} #${font Arial:bold:size=14}${color White}Radio Freq A ${if_match "VFOA" == "${execi 5 $HOME/bin/conky/get-vfo}"}*$endif\ #${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOA | cut -c1-7} diff --git a/data/conky/laptop.86 b/data/conky/laptop.86 index 777dd3f..c6ff94b 100755 --- a/data/conky/laptop.86 +++ b/data/conky/laptop.86 @@ -35,7 +35,7 @@ conky.text = [[ ${voffset -20} ${font Arial:size=30}${color Yellow}${alignc}N0CALL ${voffset -45} -${font Arial:bold:size=14}${color White}Gridsquare ${alignr}${color Yellow}${execi 60 cat /run/user/1000/gridinfo.txt | cut -c1-8} +${font Arial:bold:size=14}${color White}Gridsquare ${alignr}${color Yellow}${cat /run/user/1000/gridinfo.txt} #${font Arial:bold:size=14}${color White}Radio Freq ${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq | cut -c1-6} #${font Arial:bold:size=14}${color White}Radio Freq A ${if_match "VFOA" == "${execi 5 $HOME/bin/conky/get-vfo}"}*$endif\ #${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOA | cut -c1-7} diff --git a/data/conky/large.pi b/data/conky/large.pi index 113339b..58d42b7 100644 --- a/data/conky/large.pi +++ b/data/conky/large.pi @@ -35,7 +35,7 @@ conky.text = [[ ${voffset 15} ${font Arial:size=30}${color Yellow}${alignc}N0CALL ${voffset -45} -${font Arial:bold:size=18}${color White}Gridsquare ${alignr}${color Yellow}${execi 60 cat /run/user/1000/gridinfo.txt | cut -c1-8} +${font Arial:bold:size=18}${color White}Gridsquare ${alignr}${color Yellow}${cat /run/user/1000/gridinfo.txt} #${font Arial:bold:size=18}${color White}Radio Freq ${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq | cut -c1-6} #${font Arial:bold:size=18}${color White}Radio Freq A ${if_match "VFOA" == "${execi 5 $HOME/bin/conky/get-vfo}"}*$endif\ #${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOA | cut -c1-7} diff --git a/data/conky/medium.pi b/data/conky/medium.pi index 762a8cb..dc01905 100644 --- a/data/conky/medium.pi +++ b/data/conky/medium.pi @@ -34,7 +34,7 @@ conky.text = [[ ${font Arial:size=18}${color Yellow}${alignc}N0CALL ${voffset -25} -${font Arial:bold:size=12}${color White}Gridsquare ${alignr}${color Yellow}${execi 60 cat /run/user/1000/gridinfo.txt | cut -c1-8} +${font Arial:bold:size=12}${color White}Gridsquare ${alignr}${color Yellow}${cat /run/user/1000/gridinfo.txt} #${font Arial:bold:size=12}${color White}Radio Freq ${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq | cut -c1-6} #${font Arial:bold:size=12}${color White}Radio Freq A ${if_match "VFOA" == "${execi 5 $HOME/bin/conky/get-vfo}"}*$endif\ #${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOA | cut -c1-7} diff --git a/data/conky/radio.86 b/data/conky/radio.86 index 2746e7c..a794c86 100755 --- a/data/conky/radio.86 +++ b/data/conky/radio.86 @@ -35,7 +35,7 @@ conky.text = [[ ${voffset -20} ${font Arial:size=30}${color Yellow}${alignc}N0CALL ${voffset -45} -#${font Arial:bold:size=14}${color White}Gridsquare ${alignr}${color Yellow}${execi 60 cat /run/user/1000/gridinfo.txt | cut -c1-8} +${font Arial:bold:size=14}${color White}Gridsquare ${alignr}${color Yellow}${cat /run/user/1000/gridinfo.txt} ${font Arial:bold:size=14}${color White}Radio Freq ${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq | cut -c1-6} ${font Arial:bold:size=14}${color Yellow}LOCAL${alignr}ZULU diff --git a/data/conky/small.pi b/data/conky/small.pi index 508ea85..1fd8fdd 100644 --- a/data/conky/small.pi +++ b/data/conky/small.pi @@ -34,7 +34,7 @@ conky.text = [[ ${font Arial:size=12}${color Yellow}${alignc}N0CALL ${voffset -20} -${font Arial:bold:size=08}${color White}Gridsquare ${alignr}${color Yellow}${execi 60 cat /run/user/1000/gridinfo.txt | cut -c1-8} +${font Arial:bold:size=08}${color White}Gridsquare ${alignr}${color Yellow}${cat /run/user/1000/gridinfo.txt} #${font Arial:bold:size=12}${color White}Radio Freq ${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq | cut -c1-6} #${font Arial:bold:size=12}${color White}Radio Freq A ${if_match "VFOA" == "${execi 5 $HOME/bin/conky/get-vfo}"}*$endif\ #${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOA | cut -c1-7}