File tree Expand file tree Collapse file tree 6 files changed +127
-0
lines changed Expand file tree Collapse file tree 6 files changed +127
-0
lines changed Original file line number Diff line number Diff line change 1+ shutdownd
Original file line number Diff line number Diff line change 1+ # syntax=docker/dockerfile:1
2+
3+ FROM j3ff/deadeye-cpp-base:latest
4+ LABEL maintainer=“
[email protected] ”
5+
6+ WORKDIR /build
7+
8+ COPY ./src/ /src/
9+
10+ RUN cmake \
11+ -D CMAKE_BUILD_TYPE=Release \
12+ /src \
13+ && make -j$(nproc)
Original file line number Diff line number Diff line change 1+ IMAGE := deadeye-shutdownd
2+ NS ?= j3ff
3+ VERSION ?= $(shell git rev-parse --short HEAD)
4+ SERVICE := deadeye-shutdown.service
5+
6+ .PHONY : build
7+ build : .built
8+
9+ .built : Dockerfile $(SRC )
10+ docker build -t $(NS ) /$(IMAGE ) :latest -t $(NS ) /$(IMAGE ) :$(VERSION ) -f Dockerfile .
11+ docker cp $(NS ) /$(IMAGE ) :latest:/build/shutdownd ./build/
12+ docker inspect -f ' {{.Id}}' $(NS ) /$(IMAGE ) :latest > $@
13+
14+ .PHONY : push
15+ push : build
16+ docker push $(NS ) /$(IMAGE ) :latest
17+ docker push $(NS ) /$(IMAGE ) :$(VERSION )
18+
19+ .PHONY : copy
20+ copy :
21+ export ID=$(shell docker create ${NS}/${IMAGE}:latest) ; \
22+ docker cp $$ ID:build/shutdownd ./; \
23+ docker rm -v $$ ID
24+
25+ .PHONY : install
26+ install :
27+ ifneq ($(shell id -u) , 0)
28+ @echo "You must be root to perform this action."
29+ else
30+ cp shutdownd /usr/local/sbin/
31+ cp $(SERVICE) /etc/systemd/system/
32+ systemctl daemon-reload
33+ systemctl enable $(SERVICE)
34+ systemctl start $(SERVICE)
35+ endif
36+
37+ .PHONY : clean
38+ clean :
39+ rm -rf .built* shutdownd
Original file line number Diff line number Diff line change 1+ [Unit]
2+ Description =Deadeye System Shutdown Daemon
3+ SuccessAction =poweroff-force
4+
5+ [Service]
6+ ExecStart =/usr/local/sbin/shutdownd
7+
8+ [Install]
9+ WantedBy =multi-user.target
Original file line number Diff line number Diff line change 1+ cmake_minimum_required (VERSION 3.10)
2+
3+ set (CMAKE_CXX_STANDARD 17)
4+ set (CMAKE_CXX_STANDARD_REQUIRED ON )
5+ set (CMAKE_CXX_EXTENSIONS OFF )
6+ set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
7+
8+ if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" )
9+
10+ add_executable (Deadeye_shutdownd
11+ main.cpp
12+ )
13+ add_executable (Deadeye::shutdownd ALIAS Deadeye_shutdownd)
14+ set_target_properties (Deadeye_shutdownd PROPERTIES
15+ OUTPUT_NAME shutdownd
16+ EXPORT_NAME shutdownd
17+ )
18+
19+ target_link_libraries (Deadeye_shutdownd
20+ PRIVATE
21+ libgpiodcxx.a
22+ libgpiod.a
23+ )
24+
25+ include (GNUInstallDirs)
26+ install (TARGETS Deadeye_shutdownd DESTINATION ${CMAKE_INSTALL_BINDIR} )
27+
28+ endif (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" )
Original file line number Diff line number Diff line change 1+ #include < chrono>
2+ #include < gpiod.hpp>
3+ #include < thread>
4+
5+ int main ()
6+ {
7+ using namespace std ::chrono_literals;
8+ using namespace gpiod ;
9+
10+ // deadeye::log::Configure("shutdown");
11+
12+ chip c{" gpiochip0" , chip::OPEN_BY_NAME};
13+ auto line = c.get_line (216 );
14+ line_request lr{" shutdownd" , line_request::DIRECTION_INPUT, 0 };
15+ line.request (lr, 0 );
16+
17+ int count = 0 ;
18+ while (true )
19+ {
20+ int input = line.get_value ();
21+ // spdlog::debug("input={}", input);
22+ if (input)
23+ count++;
24+ else
25+ count = 0 ;
26+
27+ if (count == 3 )
28+ {
29+ // spdlog::warn("Shutdown button triggered shutdown");
30+ return EXIT_SUCCESS;
31+ }
32+
33+ std::this_thread::sleep_for (1s);
34+ }
35+
36+ return EXIT_FAILURE;
37+ }
You can’t perform that action at this time.
0 commit comments