Last active
November 26, 2018 00:34
-
-
Save DaneGardner/41c0b02fcdea013519c87cb96b916257 to your computer and use it in GitHub Desktop.
Setting Celestron hand controller location via IP geolocation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
readonly serial=/dev/ttyS0 | |
latlon="$(curl -s ipinfo.io | jq -r '.loc')" | |
lat=$(cut -d, -f1 <<< ${latlon}) | |
lon=$(cut -d, -f2 <<< ${latlon}) | |
location=$(./latlon2celestron.py "${lat}" "${lon}") | |
if [ ${?} != 0 ]; then exit; fi | |
stty -F ${serial} 9600 | |
HEX="\\\\x%02X" | |
unset FORMAT | |
for i in {1..8}; do | |
FORMAT="${FORMAT}${HEX}" | |
done | |
hex_text="$(printf "W${FORMAT}" ${location})" | |
echo -ne "${hex_text}" > ${serial} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
lat = float(sys.argv[1]) | |
lon = float(sys.argv[2]) | |
def dms(deg): | |
m = (abs(deg) - int(abs(deg))) * 60.0 | |
s = (abs(m) - int(abs(m))) * 60.0 | |
return (int(deg), int(m), int(s)) | |
def celestron(deg): | |
c = dms(deg) | |
return "{0:d} {1:d} {2:d} {3:d}".format(abs(c[0]), c[1], c[2], 0 if(c[0] >= 0) else 1) | |
print "{0} {1}".format(celestron(lat), celestron(lon)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment