fix pixels staying on after render

This commit is contained in:
2023-12-21 18:27:10 -05:00
parent babd5d8253
commit 6516c40862
5 changed files with 51 additions and 3 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ setup:
cd go-rpi-rgb-led-matrix/lib/rpi-rgb-led-matrix && make cd go-rpi-rgb-led-matrix/lib/rpi-rgb-led-matrix && make
run: run:
sudo go run cmd/rpi/main.go --led-slowdown-gpio=2 sudo go run cmd/rpi/main.go --led-slowdown-gpio=2 --led-pwm-dither-bits=1
build: build:
go build cmd/rpi/main.go go build cmd/rpi/main.go
+6 -1
View File
@@ -61,6 +61,11 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
currentPrice, err := mp.CurrentPrice()
if err != nil {
log.Fatal(err)
}
var blockHeight int var blockHeight int
blockHeightMutex := &sync.Mutex{} blockHeightMutex := &sync.Mutex{}
var fees mempool.Fees var fees mempool.Fees
@@ -72,6 +77,7 @@ func main() {
fees.FastestFee = highfee fees.FastestFee = highfee
fees.HalfHourFee = medfee fees.HalfHourFee = medfee
fees.HourFee = lowfee fees.HourFee = lowfee
price = currentPrice
go mp.Listen(ctx, msgs, errs, mdone) go mp.Listen(ctx, msgs, errs, mdone)
@@ -105,7 +111,6 @@ func main() {
return return
case <-ticker.C: case <-ticker.C:
d.Clear() d.Clear()
d.Render()
err = updateSlots(d, price, blockHeight, fees.HourFee, fees.HalfHourFee, fees.FastestFee) err = updateSlots(d, price, blockHeight, fees.HourFee, fees.HalfHourFee, fees.FastestFee)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
+1
View File
@@ -27,6 +27,7 @@ func (s *Segment) Draw(canvas *rgbmatrix.Canvas, x, y int) {
func drawRow(canvas *rgbmatrix.Canvas, row []color.RGBA, x, y int) { func drawRow(canvas *rgbmatrix.Canvas, row []color.RGBA, x, y int) {
for i := 0; i < len(row); i++ { for i := 0; i < len(row); i++ {
canvas.Set(x+i, y, color.Black)
canvas.Set(x+i, y, row[i]) canvas.Set(x+i, y, row[i])
} }
} }
+1 -1
View File
@@ -26,7 +26,7 @@ func (f Font) ToColor(char string, c color.RGBA) ([][]color.RGBA, error) {
crowColor.R = crowColor.R * pixel crowColor.R = crowColor.R * pixel
crowColor.G = crowColor.G * pixel crowColor.G = crowColor.G * pixel
crowColor.B = crowColor.B * pixel crowColor.B = crowColor.B * pixel
crowColor.A = 0xff * pixel crowColor.A = 0xff
crow = append(crow, crowColor) crow = append(crow, crowColor)
} }
+42
View File
@@ -9,6 +9,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
@@ -134,6 +135,47 @@ func (m *mempool) CurrentFees() (int, int, int, error) {
return data.Fastest, data.HalfHour, data.Hour, err return data.Fastest, data.HalfHour, data.Hour, err
} }
func (m *mempool) CurrentPrice() (int, error) {
req, err := http.NewRequest(http.MethodGet, "https://api.coincap.io/v2/assets/bitcoin", nil)
if err != nil {
return 0, err
}
resp, err := m.httpClient.Do(req)
if err != nil {
return 0, err
}
defer resp.Body.Close()
if resp.StatusCode >= http.StatusInternalServerError {
return 0, err
}
if resp.StatusCode >= http.StatusBadRequest {
return 0, err
}
b, err := io.ReadAll(resp.Body)
if err != nil {
return 0, err
}
var data struct {
Data struct {
PriceUSD string `json:"priceUsd"`
} `json:"data"`
}
err = json.Unmarshal(b, &data)
if err != nil {
return 0, err
}
parts := strings.Split(data.Data.PriceUSD, ".")
i, err := strconv.Atoi(parts[0])
return i, err
}
func (m *mempool) Listen(ctx context.Context, messages chan Message, errs chan error, done chan struct{}) { func (m *mempool) Listen(ctx context.Context, messages chan Message, errs chan error, done chan struct{}) {
for { for {
select { select {