Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conky/conky-7inch
Original file line number Diff line number Diff line change
Expand Up @@ -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}\
Expand Down
3 changes: 1 addition & 2 deletions conky/conky-large
Original file line number Diff line number Diff line change
Expand Up @@ -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}\
Expand Down
2 changes: 1 addition & 1 deletion conky/conky-medium
Original file line number Diff line number Diff line change
Expand Up @@ -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}\
Expand Down
2 changes: 1 addition & 1 deletion conky/conky-small
Original file line number Diff line number Diff line change
Expand Up @@ -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}\
Expand Down
2 changes: 2 additions & 0 deletions conky/cronfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Update GPS maidenhead for conky
*/1 * * * * /home/pi/bin/conky/grid
72 changes: 55 additions & 17 deletions conky/get-grid
Original file line number Diff line number Diff line change
@@ -1,23 +1,61 @@
#!/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
if timeout 5 gpspipe -w -r $HOST:$PORT | grep -m 1 TPV &>/dev/null; then
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)
else
grid="NO GPS"
fi
}

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

25 changes: 25 additions & 0 deletions conky/get-grid.rb
Original file line number Diff line number Diff line change
@@ -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}"

Empty file modified conky/get-vfo
100755 → 100644
Empty file.
11 changes: 9 additions & 2 deletions conky/grid
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ FILE=/run/user/$UID/gridinfo.txt

if [ -z "$GRIDCH" ]
then
echo $GRID > $FILE
# + = Grid from GPS (GPS online)
# - = Grid from Cache (GPS offline)
if [ "$GRID" != "NO GPS" ]; then
echo "$GRID +" > $FILE
else
cache=$(cat $FILE | sed 's/ //g;s/+//g;s/-//g')
echo "$cache -" > $FILE
fi
else
echo "NO GPS" > $FILE
fi
fi
134 changes: 134 additions & 0 deletions conky/maidenhead.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/* Taken from https://opensource.com/article/19/5/how-write-good-c-main-function */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <libgen.h>
#include <errno.h>
#include <string.h>
#include <getopt.h>

#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;
}
39 changes: 39 additions & 0 deletions conky/update
Original file line number Diff line number Diff line change
@@ -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 <<EOF > $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 <<EOF > $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
Loading