From b490dd9fff08e634f44613e801ab6350f42a2504 Mon Sep 17 00:00:00 2001 From: June Tate-Gans Date: Sun, 25 Apr 2021 00:34:49 -0500 Subject: [PATCH] cleanups: Migrate source files to appropriate dirs and fix names This cleans things up significantly in the source tree and makes this easier to manage longer term. In the next few commits, we'll migrate the build to CMake in prep for packaging support. - Move bindings into bindings - Move system configs and misc files into etc - Move LCD apps into contrib/ - Move all source files into srcs - Rename helper extensions to match GNU extension naming, fix the #includes as well - Adjust Makefile to be less verbose and more programmatic --- .gitignore | 8 +-- Makefile | 64 +++++++++----------- eve-online.bind => bindings/eve-online.bind | 0 hon.bind => bindings/hon.bind | 0 spring.bind => bindings/spring.bind | 0 starcraft2.bind => bindings/starcraft2.bind | 0 war.bind => bindings/war.bind | 0 clock.sh => contrib/clock.sh | 0 contrib/g13_test.py | 47 ++++++++++++++ 91-g13.rules => etc/91-g13.rules | 0 g13.png => etc/g13.png | Bin g13.svg => etc/g13.svg | 0 g13d.service => etc/g13d.service | 0 hello.lpbm => etc/hello.lpbm | Bin logo.lpbm => etc/logo.lpbm | Bin starcraft.lpbm => etc/starcraft.lpbm | Bin g13_test.py | 41 ------------- g13.cc => src/g13.cc | 0 g13.h => src/g13.h | 2 +- g13_fonts.cc => src/g13_fonts.cc | 0 g13_keys.cc => src/g13_keys.cc | 0 g13_lcd.cc => src/g13_lcd.cc | 0 g13_log.cc => src/g13_log.cc | 0 g13_main.cc => src/g13_main.cc | 0 g13_stick.cc => src/g13_stick.cc | 0 helper.cpp => src/helper.cc | 2 +- helper.hpp => src/helper.h | 0 logo.h => src/logo.h | 0 pbm2lpbm.c => src/pbm2lpbm.c | 0 29 files changed, 77 insertions(+), 87 deletions(-) rename eve-online.bind => bindings/eve-online.bind (100%) rename hon.bind => bindings/hon.bind (100%) rename spring.bind => bindings/spring.bind (100%) rename starcraft2.bind => bindings/starcraft2.bind (100%) rename war.bind => bindings/war.bind (100%) rename clock.sh => contrib/clock.sh (100%) create mode 100755 contrib/g13_test.py rename 91-g13.rules => etc/91-g13.rules (100%) rename g13.png => etc/g13.png (100%) rename g13.svg => etc/g13.svg (100%) rename g13d.service => etc/g13d.service (100%) rename hello.lpbm => etc/hello.lpbm (100%) rename logo.lpbm => etc/logo.lpbm (100%) rename starcraft.lpbm => etc/starcraft.lpbm (100%) delete mode 100755 g13_test.py rename g13.cc => src/g13.cc (100%) rename g13.h => src/g13.h (99%) rename g13_fonts.cc => src/g13_fonts.cc (100%) rename g13_keys.cc => src/g13_keys.cc (100%) rename g13_lcd.cc => src/g13_lcd.cc (100%) rename g13_log.cc => src/g13_log.cc (100%) rename g13_main.cc => src/g13_main.cc (100%) rename g13_stick.cc => src/g13_stick.cc (100%) rename helper.cpp => src/helper.cc (98%) rename helper.hpp => src/helper.h (100%) rename logo.h => src/logo.h (100%) rename pbm2lpbm.c => src/pbm2lpbm.c (100%) diff --git a/.gitignore b/.gitignore index 00acc1f..567609b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1 @@ -/g13d -.cproject -.project -.pydevproject -*.o -pbm2lpbm -.settings/* +build/ diff --git a/Makefile b/Makefile index d558d19..229824a 100644 --- a/Makefile +++ b/Makefile @@ -1,52 +1,42 @@ -all: g13d pbm2lpbm +CXXFLAGS := $(CXXFLAGS) -DBOOST_LOG_DYN_LINK=1 -std=c++0x +LIBS := -lusb-1.0 -lboost_program_options -lboost_log -lboost_system -lpthread +PREFIX ?= /usr/local -FLAGS=$(CXXFLAGS) -DBOOST_LOG_DYN_LINK -std=c++0x -LIBS=-lusb-1.0 -lboost_log -lboost_log_setup-mt -lboost_thread -lboost_system-mt -lpthread +G13D_SRCS := \ + src/g13.cc \ + src/g13_fonts.cc \ + src/g13_keys.cc \ + src/g13_lcd.cc \ + src/g13_log.cc \ + src/g13_main.cc \ + src/g13_stick.cc \ + src/helper.cc -g13.o: g13.h helper.hpp g13.cc - g++ $(FLAGS) -c g13.cc +G13D_OBJS := $(patsubst src/%.cc,build/%.o,$(G13D_SRCS)) -g13_main.o: g13.h helper.hpp g13_main.cc - g++ $(FLAGS) -c g13_main.cc +all: build build/g13d build/pbm2lpbm +build: + mkdir -p build -g13_log.o: g13.h helper.hpp g13_log.cc - g++ $(FLAGS) -c g13_log.cc +build/g13d: $(G13D_OBJS) | build + $(CXX) $(G13D_OBJS) -o build/g13d $(LIBS) -g13_fonts.o: g13.h helper.hpp g13_fonts.cc - g++ $(FLAGS) -c g13_fonts.cc +build/pbm2lpbm: src/pbm2lpbm.c | build + $(CXX) $(CXXFLAGS) src/pbm2lpbm.c -o build/pbm2lpbm -g13_lcd.o: g13.h helper.hpp g13_lcd.cc - g++ $(FLAGS) -c g13_lcd.cc - -g13_stick.o: g13.h helper.hpp g13_stick.cc - g++ $(FLAGS) -c g13_stick.cc - -g13_keys.o: g13.h helper.hpp g13_keys.cc - g++ $(FLAGS) -c g13_keys.cc - -helper.o: helper.hpp helper.cpp - g++ $(FLAGS) -c helper.cpp - - -g13d: g13_main.o g13.o g13_log.o g13_fonts.o g13_lcd.o g13_stick.o g13_keys.o helper.o - g++ -o g13d -std=c++0x \ - g13_main.o g13.o g13_log.o g13_fonts.o g13_lcd.o g13_stick.o g13_keys.o helper.o \ - -lusb-1.0 -lboost_program_options \ - -lboost_log \ - -lboost_system -lpthread - -pbm2lpbm: pbm2lpbm.c - g++ -o pbm2lpbm pbm2lpbm.c +build/%.o: src/%.cc + $(CXX) -c -o $@ $< $(CXXFLAGS) clean: - rm -f g13 pbm2lpbm + rm -rf build -install: +install: build/g13d build/pbm2lpbm install -d ${HOME}/.local/bin install -m700 -d ${HOME}/.local/var/g13d install -d ${HOME}/.config/systemd/user - cat g13d.service |sed "s,@HOME@,${HOME},g" > ${HOME}/.config/systemd/user/g13d.service - install -m755 g13d ${HOME}/.local/bin/g13d + cat etc/g13d.service |sed "s,@HOME@,${HOME},g" > ${HOME}/.config/systemd/user/g13d.service + install -m755 build/g13d ${HOME}/.local/bin/g13d + install -m755 build/pbm2lpbm ${HOME}/.local/bin/pbm2lpbm .PHONY: all clean install diff --git a/eve-online.bind b/bindings/eve-online.bind similarity index 100% rename from eve-online.bind rename to bindings/eve-online.bind diff --git a/hon.bind b/bindings/hon.bind similarity index 100% rename from hon.bind rename to bindings/hon.bind diff --git a/spring.bind b/bindings/spring.bind similarity index 100% rename from spring.bind rename to bindings/spring.bind diff --git a/starcraft2.bind b/bindings/starcraft2.bind similarity index 100% rename from starcraft2.bind rename to bindings/starcraft2.bind diff --git a/war.bind b/bindings/war.bind similarity index 100% rename from war.bind rename to bindings/war.bind diff --git a/clock.sh b/contrib/clock.sh similarity index 100% rename from clock.sh rename to contrib/clock.sh diff --git a/contrib/g13_test.py b/contrib/g13_test.py new file mode 100755 index 0000000..ae9186a --- /dev/null +++ b/contrib/g13_test.py @@ -0,0 +1,47 @@ +#!/usr/bin/python + +""" +simple test script to update G13 LCD with temperature values from lm-sensors +""" + +import subprocess +import re +import time + + +def doCmd(*cmd): + # print("cmd = %r" % (cmd,)) + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = p.communicate() + return out #, err + + +def get_sensors(): + sensor_lines = doCmd('sensors').split('\n') + print("sensor_lines = %r" % (sensor_lines,)) + temp_re = re.compile(r'''([a-zA-Z])[a-zA-Z s]+([0-9])\:\s*\+([0-9.]+)[\xc2\xb0C]*C.*''') + + temps = [] + for line in sensor_lines: + m = temp_re.match(line) + if m: + tag, index, value = m.groups() + print("%s%s = %s" % (tag, index, value)) + # temps.append("%s%s:%s" % (tag, index, value)) + temps.append("%s" % (value,)) + # else: + # print("failed to match %r" % (line,)) + + with open('/home/jtgans/.local/var/g13d/in', 'w') as p: + p.write('pos 0 0 \n') + p.write('out %s\n' % (' '.join(temps))) + + +def main(): + while True: + get_sensors() + time.sleep(1.0) + + +if __name__ == '__main__': + main() diff --git a/91-g13.rules b/etc/91-g13.rules similarity index 100% rename from 91-g13.rules rename to etc/91-g13.rules diff --git a/g13.png b/etc/g13.png similarity index 100% rename from g13.png rename to etc/g13.png diff --git a/g13.svg b/etc/g13.svg similarity index 100% rename from g13.svg rename to etc/g13.svg diff --git a/g13d.service b/etc/g13d.service similarity index 100% rename from g13d.service rename to etc/g13d.service diff --git a/hello.lpbm b/etc/hello.lpbm similarity index 100% rename from hello.lpbm rename to etc/hello.lpbm diff --git a/logo.lpbm b/etc/logo.lpbm similarity index 100% rename from logo.lpbm rename to etc/logo.lpbm diff --git a/starcraft.lpbm b/etc/starcraft.lpbm similarity index 100% rename from starcraft.lpbm rename to etc/starcraft.lpbm diff --git a/g13_test.py b/g13_test.py deleted file mode 100755 index 5b9b402..0000000 --- a/g13_test.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/python2.7 -import subprocess, re, os, time - -# simple test script to update G13 LCD with temperature values from lm-sensors - -def doCmd( *cmd ): - #print( "cmd = %r" % (cmd,) ) - p = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) - out, err = p.communicate() - return out #, err - -def get_sensors(): - sensor_lines = doCmd( 'sensors' ).split('\n') - print( "sensor_lines = %r" % (sensor_lines,) ) - temp_re = re.compile( r'''([a-zA-Z])[a-zA-Z s]+([0-9])\:\s*\+([0-9.]+)[\xc2\xb0C]*C.*''' ) - - temps = [] - for line in sensor_lines: - m = temp_re.match(line) - if m: - tag, index, value = m.groups() - print( "%s%s = %s" % (tag, index, value)) - #temps.append( "%s%s:%s" % (tag, index, value) ) - temps.append( "%s" % (value,) ) - # else: - # print( "failed to match %r" % (line,)) - - - with open( '/tmp/g13-0', 'w') as p: - p.write( 'pos 0 0 \n' ) - p.write( 'out %s\n' % (' '.join(temps)) ) - - -def main(): - while 1: - get_sensors() - time.sleep(1.0) - -main() - - diff --git a/g13.cc b/src/g13.cc similarity index 100% rename from g13.cc rename to src/g13.cc diff --git a/g13.h b/src/g13.h similarity index 99% rename from g13.h rename to src/g13.h index c29dfe5..114d33f 100644 --- a/g13.h +++ b/src/g13.h @@ -2,7 +2,7 @@ #define __G13_H__ -#include "helper.hpp" +#include "helper.h" #include diff --git a/g13_fonts.cc b/src/g13_fonts.cc similarity index 100% rename from g13_fonts.cc rename to src/g13_fonts.cc diff --git a/g13_keys.cc b/src/g13_keys.cc similarity index 100% rename from g13_keys.cc rename to src/g13_keys.cc diff --git a/g13_lcd.cc b/src/g13_lcd.cc similarity index 100% rename from g13_lcd.cc rename to src/g13_lcd.cc diff --git a/g13_log.cc b/src/g13_log.cc similarity index 100% rename from g13_log.cc rename to src/g13_log.cc diff --git a/g13_main.cc b/src/g13_main.cc similarity index 100% rename from g13_main.cc rename to src/g13_main.cc diff --git a/g13_stick.cc b/src/g13_stick.cc similarity index 100% rename from g13_stick.cc rename to src/g13_stick.cc diff --git a/helper.cpp b/src/helper.cc similarity index 98% rename from helper.cpp rename to src/helper.cc index 51372e2..0925cb0 100644 --- a/helper.cpp +++ b/src/helper.cc @@ -26,7 +26,7 @@ * */ -#include "helper.hpp" +#include "helper.h" // ************************************************************************* diff --git a/helper.hpp b/src/helper.h similarity index 100% rename from helper.hpp rename to src/helper.h diff --git a/logo.h b/src/logo.h similarity index 100% rename from logo.h rename to src/logo.h diff --git a/pbm2lpbm.c b/src/pbm2lpbm.c similarity index 100% rename from pbm2lpbm.c rename to src/pbm2lpbm.c