Skip to content

Commit

Permalink
Fix classvar usage in message class
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeharker committed Nov 6, 2023
1 parent 4d22046 commit 11f39ba
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions adafruit_seesaw/keypad.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
"""

import struct
from dataclasses import dataclass
from enum import IntEnum
from typing import NamedTuple
from typing import ClassVar

try:
from micropython import const
Expand Down Expand Up @@ -61,11 +62,12 @@ class ResponseType(IntEnum):
TYPE_INVALID = 0xff


class SeesawKeyResponse(NamedTuple):
@dataclass
class SeesawKeyResponse:
response_type: ResponseType
data: int

unpacker: struct.Struct = struct.Struct('<BB')
unpacker: ClassVar[struct.Struct] = struct.Struct('>BB')

@classmethod
def unpack(cls, buf: bytearray):
Expand Down Expand Up @@ -133,7 +135,7 @@ def count(self):
"""Retrieve or set the number of keys"""
buf = self.readn(_KEYPAD_BASE, _KEYPAD_COUNT, 2)
d = SeesawKeyResponse.unpack(buf)
if d.response_type != self.TYPE_COUNT:
if d.response_type != ResponseType.TYPE_COUNT:
return 0
return d.data

Expand Down Expand Up @@ -169,5 +171,6 @@ def read_keypad(self, num):
buf = bytearray(num * 2)
self.read(_KEYPAD_BASE, _KEYPAD_FIFO, buf)

return [SeesawKeyResponse.unpack_from(buf, i)
return [SeesawKeyResponse.unpack_from(buf, i * 2)
for i in range(0, num)]

0 comments on commit 11f39ba

Please sign in to comment.