Skip to content

Commit

Permalink
avoid initializing with 0 brightness, update Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
markusressel committed Aug 25, 2024
1 parent e393455 commit 2a185d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
27 changes: 21 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
BINARY_NAME=keyboard-backlight-daemon
OUTPUT_DIR=bin/
.PHONY: help test build run deploy clean

build:
go build -o ${OUTPUT_DIR}${BINARY_NAME} main.go
BINARY_NAME = keyboard-backlight-daemon
OUTPUT_DIR = bin/
GO_FLAGS ?=
NAME := keyboard-backlight-daemon
PACKAGE := github.com/markusressel/$(NAME)
GIT_REV ?= $(shell git rev-parse --short HEAD)
SOURCE_DATE_EPOCH ?= $(shell date +%s)
DATE ?= $(shell date -u -d @${SOURCE_DATE_EPOCH} +"%Y-%m-%dT%H:%M:%SZ")
VERSION ?= 1.1.0

test: ## Run all tests
@go clean --testcache && go test -v ./...

run:
build: clean
go build -o ${OUTPUT_DIR}${BINARY_NAME} main.go

run: build
./${OUTPUT_DIR}${BINARY_NAME}

deploy: build
mkdir -p ~/.custom/bin/
cp ./${OUTPUT_DIR}${BINARY_NAME} ~/.custom/bin/${BINARY_NAME}

clean:
go clean
rm ${OUTPUT_DIR}${BINARY_NAME}
rm -rf ${OUTPUT_DIR}${BINARY_NAME}
13 changes: 6 additions & 7 deletions internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func NewKbdService(c config.Configuration, l light.Light) *KbdService {
func (s *KbdService) Run() {

b, err := s.light.GetBrightness()
if err != nil {
panic(err)
if err != nil || b <= 0 {
b = 255
}
s.targetBrightness = b

Expand Down Expand Up @@ -128,16 +128,14 @@ func (s KbdService) onUserInteraction() {

func (s *KbdService) updateState(userIdle bool) {
if s.initialized == false {
s.initialized = true
defer func() { s.initialized = true }()
} else if s.userIdle == userIdle {
return
}

s.userIdle = userIdle
// TODO: verbose
//fmt.Printf("UserIdle: %t\n", userIdle)

if userIdle {
if userIdle && s.initialized {
// update the target brightness to the
// last brightness before detecting "idle" state
b, err := s.light.GetBrightness()
Expand All @@ -152,7 +150,8 @@ func (s *KbdService) updateState(userIdle bool) {
}

// listenToEvents listens to incoming events on the given file
// and notifies the given channel ch for each one.
//
// and notifies the given channel ch for each one.
func (s KbdService) listenToEvents(path string, ch chan Event) error {
f, err := os.Open(path)
if err != nil {
Expand Down

0 comments on commit 2a185d8

Please sign in to comment.