-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add flags * Setup htmx * Rename files and functions
- Loading branch information
Showing
20 changed files
with
345 additions
and
126 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## Led-Matrix-UI | ||
|
||
WebUI to manage HUB75 LED Matrix Panels with the hzeller/rpi-rgb-led-matrix library | ||
|
||
Build with: | ||
* Go-Gin | ||
* Bootstrap | ||
* htmx | ||
|
||
## Usage | ||
|
||
Run as root to get access to the /dev GPIO | ||
Configure it through the app flags | ||
|
||
## Build | ||
|
||
TODO | ||
|
||
|
||
__Please feel free to report any issues or suggestions__ |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package api | ||
|
||
import ( | ||
"image" | ||
"image/draw" | ||
"log" | ||
"os" | ||
|
||
"github.com/disintegration/imaging" | ||
"github.com/gin-gonic/gin" | ||
"github.com/zaggash/led-matrix-ui/display" | ||
) | ||
|
||
type Display struct { | ||
*display.Config | ||
} | ||
|
||
func New(c *display.Config) *Display { | ||
return &Display{c} | ||
} | ||
|
||
func drawImage(d *Display, p string) gin.HandlerFunc { | ||
return gin.HandlerFunc(func(ctx *gin.Context) { | ||
|
||
imgPath := ctx.PostForm("Path") | ||
|
||
f, err := os.Open(imgPath) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
defer f.Close() | ||
|
||
img, _, err := image.Decode(f) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
w, h := d.Matrix.Geometry() | ||
d.Toolkit.Canvas.Clear() // Clear current display | ||
img = imaging.Fill(img, w, h, imaging.Center, imaging.Lanczos) | ||
draw.Draw(d.Toolkit.Canvas, d.Toolkit.Canvas.Bounds(), img, image.ZP, draw.Over) | ||
d.Matrix.Render() | ||
|
||
// DEBUG: Print POST body request | ||
// body, _ := io.ReadAll(ctx.Request.Body) | ||
// println(string(body)) | ||
}) | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package api | ||
|
||
import ( | ||
"io/fs" | ||
"log" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/gabriel-vasile/mimetype" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type localImage struct { | ||
Name string | ||
Path string | ||
Size int64 // Size in bytes | ||
MimeType string | ||
} | ||
|
||
func listImages(rootFolder string) gin.HandlerFunc { | ||
return gin.HandlerFunc(func(ctx *gin.Context) { | ||
whitelistedMime := []string{""} | ||
requestedMime := strings.ToLower(ctx.Param("mime")) | ||
var images []localImage | ||
|
||
err := filepath.WalkDir(rootFolder, func(filename string, file fs.DirEntry, err error) error { | ||
if !file.IsDir() { | ||
switch requestedMime { | ||
case "": | ||
whitelistedMime = []string{"image/png", "image/gif", "image/jpeg"} | ||
case "png": | ||
whitelistedMime = []string{"image/png"} | ||
case "gif": | ||
whitelistedMime = []string{"image/gif"} | ||
} | ||
|
||
fileMime, err := mimetype.DetectFile(filename) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
|
||
if mimetype.EqualsAny(fileMime.String(), whitelistedMime...) { | ||
info, err := os.Stat(filename) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
images = append(images, localImage{ | ||
Name: info.Name(), | ||
Path: filename, | ||
Size: info.Size(), | ||
MimeType: fileMime.String(), | ||
}) | ||
} | ||
} | ||
return nil | ||
}) | ||
|
||
if err != nil { | ||
log.Println(err) | ||
} | ||
ctx.JSON(http.StatusOK, images) | ||
|
||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func uploadFile(ctx *gin.Context) { | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package display | ||
|
||
import ( | ||
"flag" | ||
|
||
rgbmatrix "github.com/zaggash/go-rpi-rgb-led-matrix" | ||
) | ||
|
||
var ( | ||
rows = flag.Int("led-rows", 32, "number of rows supported") | ||
cols = flag.Int("led-cols", 32, "number of columns supported") | ||
parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels") | ||
chainLength = flag.Int("led-chain", 1, "number of displays daisy-chained") | ||
pwm_bits = flag.Int("pwm-bits", 11, "set PWM bits used for output") | ||
pwm_lsb_nanoseconds = flag.Int("pwm-lsb-nanoseconds", 130, "set base time-unit for the on-time in the lowest significant bit") | ||
brightness = flag.Int("brightness", 80, "brightness (0-100)") | ||
pixelMapperConfig = flag.String("pixel-mapper-config", "", "semicolon-separated list of pixel-mappers to arrange pixels") | ||
hardware_mapping = flag.String("led-gpio-mapping", "adafruit-hat-pwm", "name of GPIO mapping used.") | ||
show_refresh = flag.Bool("led-show-refresh", false, "show refresh rate.") | ||
inverse_colors = flag.Bool("led-inverse", false, "switch if your matrix has inverse colors on") | ||
disable_hardware_pulsing = flag.Bool("led-no-hardware-pulse", false, "don't use hardware pin-pulse generation") | ||
) | ||
|
||
type Config struct { | ||
Matrix rgbmatrix.Matrix | ||
Toolkit *rgbmatrix.ToolKit | ||
Hardware rgbmatrix.HardwareConfig | ||
} | ||
|
||
func New() (*Config, error) { | ||
c := Config{} | ||
|
||
hwConfig := &rgbmatrix.DefaultConfig | ||
hwConfig.Rows = *rows | ||
hwConfig.Cols = *cols | ||
hwConfig.Parallel = *parallel | ||
hwConfig.ChainLength = *chainLength | ||
hwConfig.PWMBits = *pwm_bits | ||
hwConfig.PWMLSBNanoseconds = *pwm_lsb_nanoseconds | ||
hwConfig.Brightness = *brightness | ||
hwConfig.PixelMapperConfig = *pixelMapperConfig | ||
hwConfig.HardwareMapping = *hardware_mapping | ||
hwConfig.ShowRefreshRate = *show_refresh | ||
hwConfig.InverseColors = *inverse_colors | ||
hwConfig.DisableHardwarePulsing = *disable_hardware_pulsing | ||
|
||
c.Hardware = *hwConfig | ||
|
||
// create a new Matrix instance with the DefaultConfig | ||
matrix, err := rgbmatrix.NewRGBLedMatrix(hwConfig) | ||
c.Matrix = matrix | ||
if err != nil { | ||
return &c, err | ||
} | ||
|
||
// create a ToolKit instance | ||
toolkit := rgbmatrix.NewToolKit(matrix) | ||
c.Toolkit = toolkit | ||
|
||
// clear canvas | ||
err = toolkit.Canvas.Clear() | ||
return &c, err | ||
} |
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
Oops, something went wrong.