diff --git a/conky/conky-7inch b/conky/conky-7inch index a61d6a7..2dfe0b3 100644 --- a/conky/conky-7inch +++ b/conky/conky-7inch @@ -33,9 +33,9 @@ ${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=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} ${color DarkSlateGray}${hr 2} +${color Yellow}LOCAL${alignr}ZULU ${font Arial:bold:size=08}${color White}${time %H:%M:%S}\ ${alignr}${tztime Zulu %H:%M:%S} ${font Arial:bold:size=08}${color White}${time %d%b%y}\ diff --git a/conky/conky-large b/conky/conky-large index a51f840..e8b1fa6 100644 --- a/conky/conky-large +++ b/conky/conky-large @@ -41,11 +41,10 @@ ${font Arial:bold:size=18}${color White}Gridsquare ${alignr}${color Yellow}${exe #${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOA | cut -c1-7} #${font Arial:bold:size=18}${color White}Radio Freq B ${if_match "VFOB" == "${execi 5 $HOME/bin/conky/get-vfo}"}*$endif\ #${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOB | cut -c1-7} - -${color Yellow}LOCAL${alignr}ZULU ${voffset -45} ${color DarkSlateGray}${hr 2} ${voffset -35} +${color Yellow}LOCAL${alignr}ZULU ${font Arial:bold:size=25}${color White}${time %H:%M:%S}\ ${alignr}${tztime Zulu %H:%M:%S} ${font Arial:bold:size=25}${color White}${time %d%b%y}\ diff --git a/conky/conky-medium b/conky/conky-medium index ab24ac9..86a365b 100644 --- a/conky/conky-medium +++ b/conky/conky-medium @@ -40,8 +40,8 @@ ${font Arial:bold:size=12}${color White}Gridsquare ${alignr}${color Yellow}${exe #${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOA | cut -c1-7} #${font Arial:bold:size=12}${color White}Radio Freq B ${if_match "VFOB" == "${execi 5 $HOME/bin/conky/get-vfo}"}*$endif\ #${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOB | cut -c1-7} -${color Yellow}LOCAL${alignr}ZULU ${color DarkSlateGray}${hr 2} +${color Yellow}LOCAL${alignr}ZULU ${font Arial:bold:size=15}${color White}${time %H:%M:%S}\ ${alignr}${tztime Zulu %H:%M:%S} ${font Arial:bold:size=15}${color White}${time %d%b%y}\ diff --git a/conky/conky-small b/conky/conky-small index 716827f..609c1ff 100644 --- a/conky/conky-small +++ b/conky/conky-small @@ -40,9 +40,9 @@ ${font Arial:bold:size=08}${color White}Gridsquare ${alignr}${color Yellow}${exe #${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOA | cut -c1-7} #${font Arial:bold:size=12}${color White}Radio Freq B ${if_match "VFOB" == "${execi 5 $HOME/bin/conky/get-vfo}"}*$endif\ #${alignr}${color Yellow}${execi 5 $HOME/bin/conky/get-freq VFOB | cut -c1-7} -${color Yellow}LOCAL${alignr}ZULU ${voffset -20} ${color DarkSlateGray}${hr 2} +${color Yellow}LOCAL${alignr}ZULU ${font Arial:bold:size=08}${color White}${time %H:%M:%S}\ ${alignr}${tztime Zulu %H:%M:%S} ${font Arial:bold:size=08}${color White}${time %d%b%y}\ diff --git a/conky/get-grid b/conky/get-grid index 20f6100..252b264 100644 --- a/conky/get-grid +++ b/conky/get-grid @@ -1,23 +1,57 @@ -#!/usr/bin/env ruby +#!/usr/bin/env bash +set -e +[ -n "$DEBUG" ] && set -x -require 'gpsd_client' -require 'maidenhead' -require 'socket' -require 'json' +LAT=$1 +LON=$2 +HOST=$3 +PORT=$4 -ft8call_port = 2237 +if [ "$HOST" = "" ]; then + HOST=localhost +fi +if [ "$PORT" = "" ]; then + PORT=2947 +fi -gpsd = GpsdClient::Gpsd.new() -gpsd.start() -apicmd = {} +compile_maidenhead() { + gcc $HOME/bin/conky/maidenhead.c -o $HOME/bin/conky/mh + chmod +x $HOME/bin/conky/mh +} -# 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 +get_maidenhead_with_ruby() { + grid=$(ruby get-grid.rb) +} -puts "#{maid}" +get_maidenhead_with_gpspipe() { + if ! hash gpspipe 2>/dev/null; then + sudo apt install -y gpsd-clients jq + fi + nema=$(gpspipe -w -r $HOST:$PORT | grep -m 1 TPV) + # GPS Coordinate Set + lat=$(echo $nema | jq -r '"\(.lat)"') + [ -z "$lat" ] && echo "Latitude error?" && exit + lon=$(echo $nema | jq -r '"\(.lon)"') + [ -z "$lon" ] && echo "Longitude error?" && exit + grid=$($HOME/bin/conky/mh -a $lat -l $lon) +} + +get_maidenhead_with_args() { + grid=$($HOME/bin/conky/mh -a $LAT -l $LON) +} + +if hash gcc 2>/dev/null; then + compile_maidenhead +fi + +if [ -z "$LAT" ]; then + if hash ruby 2>/dev/null; then + get_maidenhead_with_ruby + else + get_maidenhead_with_gpspipe + fi +else + get_maidenhead_with_args +fi +echo $grid diff --git a/conky/get-grid.rb b/conky/get-grid.rb new file mode 100644 index 0000000..95fc1d5 --- /dev/null +++ b/conky/get-grid.rb @@ -0,0 +1,25 @@ +#!/usr/bin/env ruby + +require 'gpsd_client' +require 'maidenhead' +require 'socket' +require 'json' + +ft8call_port = 2237 + +options = {:host => ARGV[0] ||= ENV["HOST"], :port => ARGV[1] ||= ENV["PORT"] } + +gpsd = GpsdClient::Gpsd.new(options) +gpsd.start() +apicmd = {} + +# 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 + +puts "#{maid}" + diff --git a/conky/get-vfo b/conky/get-vfo old mode 100755 new mode 100644 diff --git a/conky/maidenhead.c b/conky/maidenhead.c new file mode 100644 index 0000000..de96188 --- /dev/null +++ b/conky/maidenhead.c @@ -0,0 +1,134 @@ +/* Taken from https://opensource.com/article/19/5/how-write-good-c-main-function */ +#include +#include +#include +#include +#include +#include +#include + +#define OPTSTR "va:l:h" +#define USAGE_FMT "%s [-v] [-a latitude] [-l longitude] [-h]" +#define ERR_LAT "lat" +#define ERR_LON "lon" +#define ERR_DO_GET_GRID "do_get_grid blew up" +#define DEFAULT_PROGNAME "get_grid" + +extern int errno; +extern char *optarg; +extern int opterr, optind; + +typedef struct { + int verbose; + char *dst; + double lon; + double lat; +} options_t; + +int dumb_global_variable = -11; +void usage(char *progname, int opt); +int do_get_grid(options_t *options); +void calcLocator(char *dst, double lat, double lon); + +int main(int argc, char *argv[]) { + int opt; + options_t options = { 0, 0, 0.0, 0.0 }; + + opterr = 0; + + while ((opt = getopt(argc, argv, OPTSTR)) != EOF) + switch(opt) { + case 'a': + if (!(options.lat = strtod(optarg, &optarg) )) { + perror(ERR_LAT); + exit(EXIT_FAILURE); + /* NOTREACHED */ + } + break; + + case 'l': + if (!(options.lon = strtod(optarg, &optarg) )) { + perror(ERR_LON); + exit(EXIT_FAILURE); + /* NOTREACHED */ + } + break; + + case 'v': + options.verbose += 1; + break; + + case 'h': + default: + usage(basename(argv[0]), opt); + /* NOTREACHED */ + break; + } + + if (do_get_grid(&options) != EXIT_SUCCESS) { + perror(ERR_DO_GET_GRID); + exit(EXIT_FAILURE); + /* NOTREACHED */ + } + fprintf(stdout, "%s", options.dst); + free(options.dst); + return EXIT_SUCCESS; +} + +void usage(char *progname, int opt) { + fprintf(stderr, USAGE_FMT, progname ? progname:DEFAULT_PROGNAME); + exit(EXIT_FAILURE); + /* NOTREACHED */ +} + +int do_get_grid(options_t *options) { + if (!options) { + errno = EINVAL; + return EXIT_FAILURE; + } + + if (!options->lon || !options->lat) { + errno = ENOENT; + return EXIT_FAILURE; + } + + options->dst = malloc((sizeof(char) * 3) + 1); /* + 1 allows for null string terminator. */ + + calcLocator(options->dst, options->lat, options->lon); + return EXIT_SUCCESS; +} + +/* https://ham.stackexchange.com/a/5599 */ +void calcLocator(char *dst, double lat, double lon) { + int o1, o2, o3; + int a1, a2, a3; + double remainder; + // longitude + remainder = lon + 180.0; + o1 = (int)(remainder / 20.0); + remainder = remainder - (double)o1 * 20.0; + o2 = (int)(remainder / 2.0); + remainder = remainder - 2.0 * (double)o2; + o3 = (int)(12.0 * remainder); + + // latitude + remainder = lat + 90.0; + a1 = (int)(remainder / 10.0); + remainder = remainder - (double)a1 * 10.0; + a2 = (int)(remainder); + remainder = remainder - (double)a2; + a3 = (int)(24.0 * remainder); + dst[0] = (char)o1 + 65; + dst[1] = (char)a1 + 65; + dst[2] = (char)o2 + 48; + dst[3] = (char)a2 + 48; + dst[4] = (char)o3 + 97; + dst[5] = (char)a3 + 97; + /* dst[0] = (char)o1 + 'A'; + dst[1] = (char)a1 + 'A'; + dst[2] = (char)o2 + '0'; + dst[3] = (char)a2 + '0'; + dst[4] = (char)o3 + 'A'; + dst[5] = (char)a3 + 'A';*/ + dst[6] = (char)0; +} diff --git a/conky/update b/conky/update new file mode 100644 index 0000000..db3ebba --- /dev/null +++ b/conky/update @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +mkdir -p $HOME/bin/conky +cp -p $HOME/pi-build/conky/* $HOME/bin/conky/ +chmod +x $HOME/bin/conky/get-grid $HOME/bin/conky/get-freq $HOME/bin/conky/grid $HOME/bin/conky/setconky + +#Create files needed for autostart at login +#Fix issue https://github.com/km4ack/pi-build/issues/83 + +cat < $HOME/.local/share/applications/conky.desktop +[Desktop Entry] +Name=Conky +Comment=Conky +GenericName=Conky Screen Background Monitor +Exec=conky +Icon=/home/pi/bin/conky/conky-logo.png +Type=Application +Encoding=UTF-8 +Terminal=false +Categories=HamRadio +Keywords=Radio +EOF + +ln -sf $HOME/.local/share/applications/conky.desktop $HOME/.config/autostart/conky.desktop + +#####Add setconky to main menu +cat < $HOME/.local/share/applications/setconky.desktop +[Desktop Entry] +Name=Conky-Prefs +Comment=Conky-Prefs +GenericName=Change Conky Preferences +Exec=/home/pi/bin/conky/setconky +Icon=/home/pi/bin/conky/conky-logo.png +Type=Application +Encoding=UTF-8 +Terminal=false +Categories=Settings;DesktopSettings;GTK;X-LXDE-Settings; +Keywords=Radio,Conky +EOF diff --git a/functions/additional.function b/functions/additional.function index 72f0a5b..461b532 100644 --- a/functions/additional.function +++ b/functions/additional.function @@ -121,59 +121,25 @@ sudo locale-gen # CONKY ################################## CONKY(){ - if ! hash conky 2>/dev/null; then - sudo apt install -y conky - fi +if ! hash conky 2>/dev/null; then + sudo apt install -y conky +fi touch $HOME/Documents/mylog.txt #conky will fail to load if this file doesn't exist touch /var/lib/misc/dnsmasq.leases #conky will fail to load if this file doesn't exist -sudo apt-get install -y ruby2.5 -sudo gem install gpsd_client -sudo gem install maidenhead +if ! hash gcc 2>/dev/null; then + sudo apt-get install -y ruby2.5 + sudo gem install gpsd_client + sudo gem install maidenhead +fi cp $MYPATH/conky/.conkyrc $HOME/.conkyrc -mkdir -p $HOME/bin/conky -cp $MYPATH/conky/* $HOME/bin/conky/ -chmod +x $HOME/bin/conky/get-grid $HOME/bin/conky/temp-conv $HOME/bin/conky/get-freq $HOME/bin/conky/grid sed -i "s/N0CALL/$CALL/" $HOME/.conkyrc + #Line below is for https://github.com/km4ack/pi-build/issues/198 echo "#Update GPS maidenhead for conky" >> $TEMPCRON echo "*/1 * * * * /home/pi/bin/conky/grid" >> $TEMPCRON -#Create files needed for autostart at login -#Fix issue https://github.com/km4ack/pi-build/issues/83 - -cat < $HOME/.local/share/applications/conky.desktop -[Desktop Entry] -Name=Conky -Comment=Conky -GenericName=Conky Screen Background Monitor -Exec=conky -Icon=/home/pi/pi-build/conky/conky-logo.png -Type=Application -Encoding=UTF-8 -Terminal=false -Categories=HamRadio -Keywords=Radio -EOF - -ln -sf $HOME/.local/share/applications/conky.desktop $HOME/.config/autostart/conky.desktop - -#####Add setconky to main menu -chmod +x $HOME/pi-build/conky/setconky - -cat < $HOME/.local/share/applications/setconky.desktop -[Desktop Entry] -Name=Conky-Prefs -Comment=Conky-Prefs -GenericName=Change Conky Preferences -Exec=/home/pi/pi-build/conky/setconky -Icon=/home/pi/pi-build/conky/conky-logo.png -Type=Application -Encoding=UTF-8 -Terminal=false -Categories=Settings;DesktopSettings;GTK;X-LXDE-Settings; -Keywords=Radio,Conky -EOF - +# Add the rest of the code here so that it can be use for installation and locally +bash $MYPATH/conky/update } ##################################