-
-
Notifications
You must be signed in to change notification settings - Fork 18
Implementation of vialrgb #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
PercyJW-2
wants to merge
33
commits into
sago35:main
Choose a base branch
from
PercyJW-2:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 24 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
7063b9b
implemented kbexpander
PercyJW-2 ff6ae1c
stuff
PercyJW-2 efb31c4
Merge branch 'sago35:main' into main
PercyJW-2 1f4c656
updated stuff
PercyJW-2 28d016d
more stuff
PercyJW-2 665cbb1
Merge branch 'main' of github.com:PercyJW-2/tinygo-keyboard
PercyJW-2 c84952c
Merge branch 'sago35:main' into main
PercyJW-2 34cba97
updated module
PercyJW-2 e195de3
Fixed kbexpander and reduced debounce time
PercyJW-2 059d332
Removed own keyboard
PercyJW-2 40757fc
Removed debug log prints
PercyJW-2 e222842
Added explicitly ignoring possible errors
PercyJW-2 2020ea4
Started to implement vialrgb
PercyJW-2 60417d3
Continued implementation, need to finish writing part
PercyJW-2 a8bdcd2
Finished untested vialrgb communication
PercyJW-2 e3941c8
Finished untested vialrgb implementation with a few animations
PercyJW-2 49a8c32
Made struct elements public
PercyJW-2 1bf0544
Fixed RGB communication
PercyJW-2 30bfea4
Finished RGB implementation
PercyJW-2 6704554
Fixed saving and loading rgb settings
PercyJW-2 40d471d
Implemented new rgb animation
PercyJW-2 567a997
Merge branch 'sago35:main' into main
PercyJW-2 9f797ef
Implemented gradient rgb effect
PercyJW-2 02dff8c
implemented Breathing effect, TODO: rework animation speed
PercyJW-2 d920ff4
adding comment to rgb.go to pass ci
PercyJW-2 094577e
reworkted animation speed for breathing animation
PercyJW-2 0a7da42
Merge branch 'sago35:main' into main
PercyJW-2 8f1eb30
Merge remote-tracking branch 'origin/main'
PercyJW-2 5c16bf8
implemented 4/6 Band Animations
PercyJW-2 f874931
implemented 6/6 Band Animations
PercyJW-2 ef7aafb
implemented All Cycle Animations
PercyJW-2 39bb188
implemented All Beacon Animations
PercyJW-2 381c069
implemented All Animations that are no rain or reactive effects
PercyJW-2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -2,3 +2,7 @@ | |
**/production/*.csv | ||
**/production/*.ipc | ||
**/production/ | ||
*.elf | ||
*.uf2 | ||
.idea | ||
.vscode |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,267 @@ | ||
package keyboard | ||
|
||
import ( | ||
"image/color" | ||
"time" | ||
"tinygo.org/x/drivers/ws2812" | ||
) | ||
|
||
type RGBMatrix struct { | ||
maximumBrightness uint8 | ||
ledCount uint16 | ||
LedMatrixMapping []LedMatrixPosition | ||
implementedEffects []RgbAnimation | ||
currentEffect RgbAnimation | ||
CurrentSpeed uint8 | ||
CurrentHue uint8 | ||
CurrentSaturation uint8 | ||
CurrentValue uint8 | ||
LedMatrixDirectVals []LedMatrixDirectModeColor | ||
LedMatrixVals []color.RGBA | ||
ledDriver *ws2812.Device | ||
} | ||
|
||
type LedMatrixPosition struct { | ||
PhysicalX uint8 | ||
PhysicalY uint8 | ||
KbIndex uint8 | ||
MatrixIndex uint8 | ||
LedFlags uint8 | ||
} | ||
|
||
type LedMatrixDirectModeColor struct { | ||
H uint8 | ||
S uint8 | ||
V uint8 | ||
} | ||
|
||
type RgbAnimationFunc func(matrix *RGBMatrix) | ||
|
||
type RgbAnimation struct { | ||
AnimationFunc RgbAnimationFunc | ||
AnimationType uint16 | ||
} | ||
|
||
const ( | ||
// LED Flags | ||
LED_FLAG_NONE uint8 = 0x00 // If this LED has no flags | ||
LED_FLAG_ALL uint8 = 0xFF // if this LED has all flags | ||
LED_FLAG_MODIFIER uint8 = 0x01 // if the Key for this LED is a modifier | ||
LED_FLAG_UNDERGLOW uint8 = 0x02 // if the LED is for underglow | ||
LED_FLAG_KEYLIGHT uint8 = 0x04 // if the LED is for key backlight | ||
) | ||
|
||
const ( | ||
// RGB Modes | ||
VIALRGB_EFFECT_OFF = iota | ||
VIALRGB_EFFECT_DIRECT | ||
VIALRGB_EFFECT_SOLID_COLOR | ||
VIALRGB_EFFECT_ALPHAS_MODS | ||
VIALRGB_EFFECT_GRADIENT_UP_DOWN | ||
VIALRGB_EFFECT_GRADIENT_LEFT_RIGHT | ||
VIALRGB_EFFECT_BREATHING | ||
VIALRGB_EFFECT_BAND_SAT | ||
VIALRGB_EFFECT_BAND_VAL | ||
VIALRGB_EFFECT_BAND_PINWHEEL_SAT | ||
VIALRGB_EFFECT_BAND_PINWHEEL_VAL | ||
VIALRGB_EFFECT_BAND_SPIRAL_SAT | ||
VIALRGB_EFFECT_BAND_SPIRAL_VAL | ||
VIALRGB_EFFECT_CYCLE_ALL | ||
VIALRGB_EFFECT_CYCLE_LEFT_RIGHT | ||
VIALRGB_EFFECT_CYCLE_UP_DOWN | ||
VIALRGB_EFFECT_RAINBOW_MOVING_CHEVRON | ||
VIALRGB_EFFECT_CYCLE_OUT_IN | ||
VIALRGB_EFFECT_CYCLE_OUT_IN_DUAL | ||
VIALRGB_EFFECT_CYCLE_PINWHEEL | ||
VIALRGB_EFFECT_CYCLE_SPIRAL | ||
VIALRGB_EFFECT_DUAL_BEACON | ||
VIALRGB_EFFECT_RAINBOW_BEACON | ||
VIALRGB_EFFECT_RAINBOW_PINWHEELS | ||
VIALRGB_EFFECT_RAINDROPS | ||
VIALRGB_EFFECT_JELLYBEAN_RAINDROPS | ||
VIALRGB_EFFECT_HUE_BREATHING | ||
VIALRGB_EFFECT_HUE_PENDULUM | ||
VIALRGB_EFFECT_HUE_WAVE | ||
VIALRGB_EFFECT_TYPING_HEATMAP | ||
VIALRGB_EFFECT_DIGITAL_RAIN | ||
VIALRGB_EFFECT_SOLID_REACTIVE_SIMPLE | ||
VIALRGB_EFFECT_SOLID_REACTIVE | ||
VIALRGB_EFFECT_SOLID_REACTIVE_WIDE | ||
VIALRGB_EFFECT_SOLID_REACTIVE_MULTIWIDE | ||
VIALRGB_EFFECT_SOLID_REACTIVE_CROSS | ||
VIALRGB_EFFECT_SOLID_REACTIVE_MULTICROSS | ||
VIALRGB_EFFECT_SOLID_REACTIVE_NEXUS | ||
VIALRGB_EFFECT_SOLID_REACTIVE_MULTINEXUS | ||
VIALRGB_EFFECT_SPLASH | ||
VIALRGB_EFFECT_MULTISPLASH | ||
VIALRGB_EFFECT_SOLID_SPLASH | ||
VIALRGB_EFFECT_SOLID_MULTISPLASH | ||
VIALRGB_EFFECT_PIXEL_RAIN | ||
VIALRGB_EFFECT_PIXEL_FRACTAL | ||
) | ||
|
||
func (d *Device) AddRGBMatrix(brightness uint8, ledCount uint16, ledMatrixMapping []LedMatrixPosition, animations []RgbAnimation, ledDriver *ws2812.Device) { | ||
if int(ledCount) != len(ledMatrixMapping) { | ||
panic("LedMatrixMapping must have length equal to number of LedMatrixMapping") | ||
} | ||
effectOffAnimation := RgbAnimation{ | ||
AnimationFunc: func(matrix *RGBMatrix) { | ||
matrix.ledDriver.WriteColors(matrix.LedMatrixVals) | ||
}, | ||
AnimationType: VIALRGB_EFFECT_OFF, | ||
} | ||
rgbMatrix := RGBMatrix{ | ||
maximumBrightness: brightness, | ||
ledCount: ledCount, | ||
LedMatrixMapping: ledMatrixMapping, | ||
implementedEffects: []RgbAnimation{ | ||
effectOffAnimation, | ||
}, | ||
currentEffect: effectOffAnimation, | ||
CurrentSpeed: 0x00, | ||
CurrentHue: 0xFF, | ||
CurrentSaturation: 0xFF, | ||
CurrentValue: brightness, | ||
LedMatrixVals: make([]color.RGBA, ledCount), | ||
ledDriver: ledDriver, | ||
} | ||
rgbMatrix.implementedEffects = append(rgbMatrix.implementedEffects, animations...) | ||
for _, animation := range animations { | ||
if animation.AnimationType == VIALRGB_EFFECT_DIRECT { | ||
rgbMatrix.LedMatrixDirectVals = make([]LedMatrixDirectModeColor, ledCount) | ||
} | ||
} | ||
d.rgbMat = &rgbMatrix | ||
} | ||
|
||
func (d *Device) GetRGBMatrixMaximumBrightness() uint8 { | ||
if !d.IsRGBMatrixEnabled() { | ||
return 0 | ||
} | ||
return d.rgbMat.maximumBrightness | ||
} | ||
|
||
func (d *Device) GetRGBMatrixLEDCount() uint16 { | ||
if !d.IsRGBMatrixEnabled() { | ||
return 0 | ||
} | ||
return d.rgbMat.ledCount | ||
} | ||
|
||
func (d *Device) GetRGBMatrixLEDMapping(ledIndex uint16) LedMatrixPosition { | ||
invalidPosition := LedMatrixPosition{ | ||
KbIndex: 0xFF, | ||
MatrixIndex: 0xFF, | ||
} | ||
if !d.IsRGBMatrixEnabled() || ledIndex >= d.rgbMat.ledCount { | ||
return invalidPosition | ||
} | ||
return d.rgbMat.LedMatrixMapping[ledIndex] | ||
} | ||
|
||
func (d *Device) GetSupportedRGBModes() []RgbAnimation { | ||
if !d.IsRGBMatrixEnabled() { | ||
return []RgbAnimation{} | ||
} | ||
return d.rgbMat.implementedEffects | ||
} | ||
|
||
func (d *Device) GetCurrentRGBMode() uint16 { | ||
if !d.IsRGBMatrixEnabled() { | ||
return 0 | ||
} | ||
return d.rgbMat.currentEffect.AnimationType | ||
} | ||
|
||
func (d *Device) SetCurrentRGBMode(mode uint16) { | ||
if !d.IsRGBMatrixEnabled() { | ||
return | ||
} | ||
for _, e := range d.rgbMat.implementedEffects { | ||
if e.AnimationType == mode { | ||
d.rgbMat.currentEffect = e | ||
} | ||
} | ||
} | ||
|
||
func (d *Device) GetCurrentSpeed() uint8 { | ||
if !d.IsRGBMatrixEnabled() { | ||
return 0 | ||
} | ||
return d.rgbMat.CurrentSpeed | ||
} | ||
|
||
func (d *Device) SetCurrentSpeed(speed uint8) { | ||
if !d.IsRGBMatrixEnabled() { | ||
return | ||
} | ||
d.rgbMat.CurrentSpeed = speed | ||
} | ||
|
||
func (d *Device) GetCurrentHue() uint8 { | ||
if !d.IsRGBMatrixEnabled() { | ||
return 0 | ||
} | ||
return d.rgbMat.CurrentHue | ||
} | ||
|
||
func (d *Device) GetCurrentSaturation() uint8 { | ||
if !d.IsRGBMatrixEnabled() { | ||
return 0 | ||
} | ||
return d.rgbMat.CurrentSaturation | ||
} | ||
|
||
func (d *Device) GetCurrentValue() uint8 { | ||
if !d.IsRGBMatrixEnabled() { | ||
return 0 | ||
} | ||
return d.rgbMat.CurrentValue | ||
} | ||
|
||
func (d *Device) SetCurrentHSV(hue uint8, saturation uint8, value uint8) { | ||
if !d.IsRGBMatrixEnabled() { | ||
return | ||
} | ||
d.rgbMat.CurrentHue = hue | ||
d.rgbMat.CurrentSaturation = saturation | ||
d.rgbMat.CurrentValue = value | ||
} | ||
|
||
func (d *Device) SetDirectHSV(hue uint8, saturation uint8, value uint8, ledIndex uint16) { | ||
if !d.IsDirectModeEnabled() { | ||
return | ||
} | ||
rgb := d.rgbMat | ||
var actualValue uint8 | ||
if value > rgb.maximumBrightness { | ||
actualValue = rgb.maximumBrightness | ||
} else { | ||
actualValue = value | ||
} | ||
rgb.LedMatrixDirectVals[ledIndex] = LedMatrixDirectModeColor{ | ||
H: hue, | ||
S: saturation, | ||
V: actualValue, | ||
} | ||
} | ||
|
||
func (d *Device) updateRGBTask() { | ||
if !d.IsRGBMatrixEnabled() { | ||
return | ||
} | ||
rgb := d.rgbMat | ||
for { | ||
time.Sleep(time.Millisecond * time.Duration(0x100-uint16(rgb.CurrentSpeed))) | ||
rgb.currentEffect.AnimationFunc(rgb) | ||
_ = rgb.ledDriver.WriteColors(rgb.LedMatrixVals) | ||
} | ||
} | ||
|
||
func (d *Device) IsRGBMatrixEnabled() bool { | ||
return d.rgbMat != nil | ||
} | ||
|
||
func (d *Device) IsDirectModeEnabled() bool { | ||
return d.IsRGBMatrixEnabled() && d.rgbMat.LedMatrixDirectVals != nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.