Skip to content
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

Added keypad functionality #19

Merged
merged 1 commit into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ChromaPython/ChromaApp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import requests
from .ChromaBinary import ChromaBcaHandler
from .ChromaDevices import Keyboard, Mouse, Mousepad, ChromaLink, Headset
from .ChromaDevices import Keyboard, Keypad, Mouse, Mousepad, ChromaLink, Headset
from .ChromaDatatypes import Heartbeat, ChromaAppInfo


Expand All @@ -23,6 +23,7 @@ def __init__(self, Info: ChromaAppInfo):
self.SessionID, self.URI = response.json()['sessionid'], response.json()['uri']
self.heartbeat = Heartbeat(self.URI)
self.Keyboard = Keyboard(self.URI)
self.Keypad = Keypad(self.URI)
self.Mouse = Mouse(self.URI)
self.Mousepad = Mousepad(self.URI)
self.Headset = Headset(self.URI)
Expand Down
4 changes: 2 additions & 2 deletions ChromaPython/ChromaDatatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def getHexRGB(self):

class ChromaGrid:
def __init__(self, type: str):
self._types = {'Keyboard': [22, 6], 'Mouse': [7, 9], 'Mousepad': [15], 'ChromaLink': [5], 'Keypad': [4, 5],
self._types = {'Keyboard': [22, 6], 'Mouse': [7, 9], 'Mousepad': [15], 'ChromaLink': [5], 'Keypad': [5, 4],
'Headset': [2]}
try:
self.rearrange(type=type)
Expand All @@ -145,7 +145,7 @@ def __len__(self):
def rearrange(self, type: str):
if not type in self._types:
print('Unexpected Error!')
raise
raise Exception('Device type not found!')
else:
self._type = self._types[type]
if len(self._type) == 1:
Expand Down
7 changes: 4 additions & 3 deletions ChromaPython/ChromaDevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ class Keypad:
def __init__(self, uri: str):
self._MaxRow = 4
self._MaxColumn = 5
self._ColorGrid = [[ChromaColor(red=0, green=0, blue=0) for x in range(22)] for y in range(6)]
self._ColorGrid = [[ChromaColor(red=0, green=0, blue=0) for x in range(5)] for y in range(4)]
self._Keys = KeyboardKeys()

try:
Expand Down Expand Up @@ -529,16 +529,17 @@ def setCustomGrid(self, grid):
raise

def applyGrid(self):
tmp = [[0 for x in range(22)] for y in range(6)]
tmp = [[0 for x in range(5)] for y in range(4)]

for i in range(0, len(self._ColorGrid)):
for j in range(0, len(self._ColorGrid[i])):
tmp[i][j] = int(self._ColorGrid[i][j].getHexBGR(), 16)

data = {
"effect": "CHROMA_CUSTOM",
"param": [tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]]
"param": [tmp[0], tmp[1], tmp[2], tmp[3]]
}

try:
return checkresult(requests.put(url=self._URI, json=data).json())
except:
Expand Down
18 changes: 16 additions & 2 deletions Tests/checkall.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Info.DeveloperName = 'Rick Sanchez'
Info.DeveloperContact = 'Wubba-lubba@dub-dub.com'
Info.Category = 'application'
Info.SupportedDevices = ['keyboard', 'mouse', 'mousepad']
Info.SupportedDevices = ['keyboard', 'mouse', 'mousepad', 'keypad']
Info.Description = 'Oh Rick, I don\'t know if that\'s a good idea.'
Info.Title = 'Mr Meeseeks Box'

Expand All @@ -17,11 +17,12 @@
print(App.Version())
print('\n')

print('Setting Keyboard to green, Mouse to yellow and Mousepad to blue')
print('Setting Keyboard to green, Keypad to purple, Mouse to yellow, and Mousepad to blue')

print(App.Keyboard.setStatic(Colors.GREEN))
print(App.Mousepad.setStatic(Colors.BLUE))
print(App.Mouse.setStatic(Colors.YELLOW))
print(App.Keypad.setStatic(Colors.PURPLE))

sleep(2)
# Oldschool
Expand All @@ -30,19 +31,23 @@
# MousepadGrid = [ChromaColor(red=255, blue=0, green=0) for x in range(15)]
# New
KeyboardGrid = ChromaGrid('Keyboard')
KeypadGrid = ChromaGrid('Keypad')
MouseGrid = ChromaGrid('Mouse')
MousepadGrid = ChromaGrid('Mousepad')

print('Setting all devices to red')
KeyboardGrid.set(hexcolor="#FF0000")
KeypadGrid.set(hexcolor="0xFF0000")
MousepadGrid.set(red=255, blue=0, green=0)
MouseGrid.set(hexcolor="0xFF0000")
print(App.Mousepad.setCustomGrid(MousepadGrid))
print(App.Mouse.setCustomGrid(MouseGrid))
print(App.Keyboard.setCustomGrid(KeyboardGrid))
print(App.Keypad.setCustomGrid(KeypadGrid))
print(App.Mouse.applyGrid())
print(App.Mousepad.applyGrid())
print(App.Keyboard.applyGrid())
print(App.Keypad.applyGrid())

sleep(2)

Expand All @@ -64,6 +69,14 @@
App.Keyboard.applyGrid()
sleep(0.1)

print('Running keypad-animation')
for i in range(0, len(KeypadGrid)):
for j in range(0, len(KeypadGrid[i])):
KeypadGrid[i][j].set(red=255, green=255, blue=0)
App.Keypad.setCustomGrid(KeypadGrid)
App.Keypad.applyGrid()
sleep(0.1)

print('Running mousepad-animation')
for i in range(0, len(MousepadGrid)):
MousepadGrid[i].set(red=255, green=255, blue=0)
Expand All @@ -75,6 +88,7 @@

print("Setting all devices to none")
App.Keyboard.setNone()
App.Keypad.setNone()
App.Mouse.setNone()
App.Mousepad.setNone()

Expand Down