1
0
Fork 0
mirror of https://github.com/Luzifer/streamdeck.git synced 2024-12-20 09:41:19 +00:00

Prevent write collisions

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-11-22 14:00:20 +01:00
parent dce5f619f5
commit 6bbb7dce11
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
3 changed files with 36 additions and 19 deletions

View file

@ -6,11 +6,15 @@ replace github.com/Luzifer/streamdeck => ../../
require (
github.com/Luzifer/rconfig/v2 v2.2.1
github.com/Luzifer/streamdeck v0.0.0-20191122001547-bfc4857847cb
github.com/Luzifer/streamdeck v0.0.0-20191122003228-a2f524a6b22c
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/pkg/errors v0.8.1
github.com/sashko/go-uinput v0.0.0-20180923134002-15fcac7aa54a
github.com/sirupsen/logrus v1.4.2
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e // indirect
gopkg.in/validator.v2 v2.0.0-20191107172027-c3144fdedc21 // indirect
gopkg.in/yaml.v2 v2.2.7
)

View file

@ -7,6 +7,8 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF0
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@ -16,6 +18,8 @@ github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/sstallion/go-hid v0.0.0-20190621001400-1cf4630be9f4 h1:hczfXYN39SDj4FcN5J7sgHBtJm4U7ef2nvlonn6NvVU=
github.com/sstallion/go-hid v0.0.0-20190621001400-1cf4630be9f4/go.mod h1:JwBz6izP5UGcbYDU5VGeLkqpRIpSBDPtCB5/XnVXz9Q=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@ -24,10 +28,14 @@ golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 h1:hVwzHzIUGRjiF7EcUjqNxk3
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e h1:N7DeIrjYszNmSW409R3frPPwglRwMkXSBzwVbkOjLLA=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/validator.v2 v2.0.0-20180514200540-135c24b11c19 h1:WB265cn5OpO+hK3pikC9hpP1zI/KTwmyMFKloW9eOVc=
gopkg.in/validator.v2 v2.0.0-20180514200540-135c24b11c19/go.mod h1:o4V0GXN9/CAmCsvJ0oXYZvrZOe7syiDZSN1GWGZTGzc=
gopkg.in/validator.v2 v2.0.0-20191107172027-c3144fdedc21 h1:2QQcyaEBdpfjjYkF0MXc69jZbHb4IOYuXz2UwsmVM8k=
gopkg.in/validator.v2 v2.0.0-20191107172027-c3144fdedc21/go.mod h1:o4V0GXN9/CAmCsvJ0oXYZvrZOe7syiDZSN1GWGZTGzc=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View file

@ -7,6 +7,7 @@ import (
"image/color"
"image/jpeg"
"strings"
"sync"
"github.com/disintegration/imaging"
"github.com/pkg/errors"
@ -19,7 +20,8 @@ const (
)
type deckConfigOriginalV2 struct {
dev *hid.Device
dev *hid.Device
writeLock sync.Mutex
keyState []EventType
}
@ -33,19 +35,19 @@ func newDeckConfigOriginalV2() *deckConfigOriginalV2 {
func (d *deckConfigOriginalV2) SetDevice(dev *hid.Device) { d.dev = dev }
func (d deckConfigOriginalV2) NumKeys() int { return 15 }
func (d deckConfigOriginalV2) KeyColumns() int { return 5 }
func (d deckConfigOriginalV2) KeyRows() int { return 3 }
func (d deckConfigOriginalV2) KeyDirection() keyDirection { return keyDirectionLTR }
func (d deckConfigOriginalV2) KeyDataOffset() int { return 4 }
func (d deckConfigOriginalV2) TransformKeyIndex(keyIdx int) int { return keyIdx }
func (d *deckConfigOriginalV2) NumKeys() int { return 15 }
func (d *deckConfigOriginalV2) KeyColumns() int { return 5 }
func (d *deckConfigOriginalV2) KeyRows() int { return 3 }
func (d *deckConfigOriginalV2) KeyDirection() keyDirection { return keyDirectionLTR }
func (d *deckConfigOriginalV2) KeyDataOffset() int { return 4 }
func (d *deckConfigOriginalV2) TransformKeyIndex(keyIdx int) int { return keyIdx }
func (d deckConfigOriginalV2) IconSize() int { return 72 }
func (d deckConfigOriginalV2) IconBytes() int { return d.IconSize() * d.IconSize() * 3 }
func (d *deckConfigOriginalV2) IconSize() int { return 72 }
func (d *deckConfigOriginalV2) IconBytes() int { return d.IconSize() * d.IconSize() * 3 }
func (d deckConfigOriginalV2) Model() uint16 { return StreamDeckOriginalV2 }
func (d *deckConfigOriginalV2) Model() uint16 { return StreamDeckOriginalV2 }
func (d deckConfigOriginalV2) FillColor(keyIdx int, col color.RGBA) error {
func (d *deckConfigOriginalV2) FillColor(keyIdx int, col color.RGBA) error {
img := image.NewRGBA(image.Rect(0, 0, d.IconSize(), d.IconSize()))
for x := 0; x < d.IconSize(); x++ {
@ -57,7 +59,10 @@ func (d deckConfigOriginalV2) FillColor(keyIdx int, col color.RGBA) error {
return d.FillImage(keyIdx, img)
}
func (d deckConfigOriginalV2) FillImage(keyIdx int, img image.Image) error {
func (d *deckConfigOriginalV2) FillImage(keyIdx int, img image.Image) error {
d.writeLock.Lock()
defer d.writeLock.Unlock()
buf := new(bytes.Buffer)
// We need to rotate the image or it will be presented upside down
@ -96,7 +101,7 @@ func (d deckConfigOriginalV2) FillImage(keyIdx int, img image.Image) error {
return nil
}
func (d deckConfigOriginalV2) FillPanel(img image.RGBA) error {
func (d *deckConfigOriginalV2) FillPanel(img image.RGBA) error {
if img.Bounds().Size().X < d.KeyColumns()*d.IconSize() || img.Bounds().Size().Y < d.KeyRows()*d.IconSize() {
return errors.New("Image is too small")
}
@ -115,11 +120,11 @@ func (d deckConfigOriginalV2) FillPanel(img image.RGBA) error {
return nil
}
func (d deckConfigOriginalV2) ClearKey(keyIdx int) error {
func (d *deckConfigOriginalV2) ClearKey(keyIdx int) error {
return d.FillColor(keyIdx, color.RGBA{0x0, 0x0, 0x0, 0xff})
}
func (d deckConfigOriginalV2) ClearAllKeys() error {
func (d *deckConfigOriginalV2) ClearAllKeys() error {
for i := 0; i < d.NumKeys(); i++ {
if err := d.ClearKey(i); err != nil {
return errors.Wrap(err, "Unable to clear key")
@ -128,7 +133,7 @@ func (d deckConfigOriginalV2) ClearAllKeys() error {
return nil
}
func (d deckConfigOriginalV2) SetBrightness(pct int) error {
func (d *deckConfigOriginalV2) SetBrightness(pct int) error {
if pct < 0 || pct > 100 {
return errors.New("Percentage out of bounds")
}
@ -143,7 +148,7 @@ func (d deckConfigOriginalV2) SetBrightness(pct int) error {
return errors.Wrap(err, "Unable to send feature report")
}
func (d deckConfigOriginalV2) ResetToLogo() error {
func (d *deckConfigOriginalV2) ResetToLogo() error {
_, err := d.dev.SendFeatureReport([]byte{
0x03,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -155,7 +160,7 @@ func (d deckConfigOriginalV2) ResetToLogo() error {
return errors.Wrap(err, "Unable to send feature report")
}
func (d deckConfigOriginalV2) GetFimwareVersion() (string, error) {
func (d *deckConfigOriginalV2) GetFimwareVersion() (string, error) {
fw := make([]byte, 32)
fw[0] = 5