GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — python-validity/validitysensor/table_types.py at master · uunicorn/python-validity Expand file tree/ Copy pathtable_types.pyMore file actions 102 lines (79 loc) · 3.2 KB / Copy pathtable_types.pyFile metadata and controls102 lines (79 loc) · 3.2 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 import typing from binascii import hexlify, unhexlify class SensorTypeInfo: table: typing.List["SensorTypeInfo"] = [] @classmethod def get_by_type(cls, sensor_type: int) -> typing.Optional["SensorTypeInfo"]: # noinspection PyUnresolvedReferences from . import generated_tables for i in cls.table: if i.sensor_type == sensor_type: return i def __init__(self, sensor_type: int, bytes_per_line: int, repeat_multiplier: int, lines_per_calibration_data: int, line_width: int, calibration_blob: str): self.sensor_type = sensor_type self.repeat_multiplier = repeat_multiplier self.lines_per_calibration_data = lines_per_calibration_data self.line_width = line_width self.bytes_per_line = bytes_per_line self.calibration_blob = unhexlify(calibration_blob) def __repr__(self): calibration_blob = hexlify(self.calibration_blob).decode() return 'SensorTypeInfo(sensor_type=0x%04x, bytes_per_line=0x%x, repeat_multiplier=%d, lines_per_calibration_data=%d, line_width=%d, calibration_blob=%s)' % ( self.sensor_type, self.bytes_per_line, self.repeat_multiplier, self.lines_per_calibration_data, self.line_width, repr(calibration_blob)) def fuzzy(expected, actual): if expected == actual: return 2 elif expected == 0xffff: return 1 else: return 0 def metric(i, rominfo): metric = 0 metric |= fuzzy(i.major, rominfo.major) metric <<= 2 metric |= fuzzy(i.minor, rominfo.minor) metric <<= 2 metric |= fuzzy(i.build, rominfo.build) metric <<= 2 metric |= fuzzy(i.u1, rominfo.u1) return metric class SensorCaptureProg: table: typing.List["SensorCaptureProg"] = [] @classmethod def get(cls, rominfo, sensor_type: int, a0: int, a1: int): # noinspection PyUnresolvedReferences from . import generated_tables maximum = 0 found = None for i in SensorCaptureProg.table: if i.major != 0xffff and i.major != rominfo.major: continue if i.dev_type != 0xffff and i.dev_type != sensor_type: continue if i.a0 != 0xffff and i.a0 != a0: continue if i.a1 != 0xffff and i.a1 != a1: continue m = metric(i, rominfo) if m > maximum: found = i maximum = m if found is not None: return b''.join(found.blobs) def __init__(self, major: int, minor: int, build: int, u1: int, dev_type: int, a0: int, a1: int, blobs: typing.Sequence[str]): self.major = major self.minor = minor self.build = build self.u1 = u1 self.dev_type = dev_type self.a0 = a0 self.a1 = a1 self.blobs = [unhexlify(b) for b in blobs] def __repr__(self): blobs = [hexlify(b).decode() for b in self.blobs] return 'SensorCaptureProg(major=0x%x, minor=0x%x, build=0x%x, u1=0x%x, dev_type=0x%x, a0=0x%x, a1=0x%x, blobs=%s)' % ( self.major, self.minor, self.build, self.u1, self.dev_type, self.a0, self.a1, repr(blobs)) |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |