Skip to content

Commit

Permalink
added intial functionality to set any hex color
Browse files Browse the repository at this point in the history
  • Loading branch information
bambash committed Aug 14, 2019
1 parent e300225 commit 2574efa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
15 changes: 12 additions & 3 deletions pkg/keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c RGBColor) GetColorInHex() string {
return hex
}

// ColorFileHandler writes a hex value to "f" input, and returns the bytes written
// ColorFileHandler writes a string to colorFiles
func ColorFileHandler(c string) {
_, exists := presetColors[c]
if exists {
Expand All @@ -52,14 +52,23 @@ func ColorFileHandler(c string) {
p := fmt.Sprintf("/sys/class/leds/system76::kbd_backlight/%v", file)
fh, err := os.OpenFile(p, os.O_RDWR, 0755)
if err != nil {
log.Fatal("error: %v", err)
log.Fatal(err)
os.Exit(1)
}
fh.WriteString(color)
fh.Close()
}
} else {
os.Exit(1)
for _, file := range colorFiles {
p := fmt.Sprintf("/sys/class/leds/system76::kbd_backlight/%v", file)
fh, err := os.OpenFile(p, os.O_RDWR, 0755)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
fh.WriteString(c)
fh.Close()
}
}
}

Expand Down
28 changes: 4 additions & 24 deletions pkg/pattern.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package keyboard

import (
"fmt"
"log"
"os"
"strconv"
"time"
)
Expand All @@ -14,32 +11,18 @@ func BrightnessPulse() {
for i := 255; i >= 0; i-- {
s := strconv.Itoa(i)
BrightnessFileHandler(s)
time.Sleep(10 * time.Millisecond)
time.Sleep(25 * time.Millisecond)
}
for i := 0; i <= 255; i++ {
for i := 1; i <= 255; i++ {
s := strconv.Itoa(i)
BrightnessFileHandler(s)
time.Sleep(10 * time.Millisecond)
time.Sleep(25 * time.Millisecond)
}
}
}

// InfiniteRainbow generates... an infinite rainbow
func InfiniteRainbow() {
open := func(files []string) []*os.File {
kbfiles := make([]*os.File, 0, len(files))
for _, file := range files {
p := fmt.Sprintf("/sys/class/leds/system76::kbd_backlight/%v", file)
fh, err := os.OpenFile(p, os.O_RDWR, 0755)
if err != nil {
log.Fatal("error: %v", err)
continue
}
kbfiles = append(kbfiles, fh)
}
return kbfiles
}

colors := make([]string, 0, 6)
// generate range of rainbow values
for i := 0; i <= 255; i++ {
Expand Down Expand Up @@ -72,12 +55,9 @@ func InfiniteRainbow() {
colors = append(colors, c.GetColorInHex())
}

kbfiles := open(colorFiles)
for {
for _, c := range colors {
for _, f := range kbfiles {
f.WriteString(c)
}
ColorFileHandler(c)
time.Sleep(time.Nanosecond)
}
}
Expand Down

0 comments on commit 2574efa

Please sign in to comment.