from typing import List, Optional
from ctypes import Structure, sizeof, c_float, c_uint32, c_uint16


class DynamicYddsComTs(Structure):
    _pack_ = 1  # 按 1 字节对齐
    _fields_ = [
        ("nf", c_float),
        ("nfCap", c_uint32),
        ("tf", c_float),
        ("tfCap", c_uint32),
        ("tfDir", c_uint16),
        ("prox", c_uint32),
    ]

class DynamicYddsU16Ts(Structure):
    _pack_ = 1  # 按 1 字节对齐
    _fields_ = [
        ("nf", c_uint16),
        ("tf", c_uint16),
        ("tfDir", c_uint16),
    ]

#todo 其他三维力类型待补充


class FingerHeatMap:
    def __init__(self, rows: int, cols: int, file_path: str, cap_count: int, cap_indices: List[int]):
        self.rows = rows
        self.cols = cols
        self.file_path = file_path
        self.cap_count = cap_count
        self.cap_indices = cap_indices

class FingerParamTS:
    def __init__(self, prg: int, pack_len: int, sensor_num: int, touch_num: int, ydds_num: int,
                 s_prox_num: int, m_prox_num: int, cap_byte: int, ydds_type: int, had_err: int,
                 cali_num: int, name: str, display_type_para: str, p_heat_map: Optional[List[FingerHeatMap]]):
        self.prg = prg
        self.pack_len = pack_len
        self.sensor_num = sensor_num
        self.touch_num = touch_num
        self.ydds_num = ydds_num
        self.s_prox_num = s_prox_num
        self.m_prox_num = m_prox_num
        self.cap_byte = cap_byte
        self.ydds_type = ydds_type
        self.had_err = had_err
        self.cali_num = cali_num
        self.name = name
        self.display_type_para = display_type_para
        self.p_heat_map = p_heat_map

# 定义 fingerHeatMap 数据
finger2_power_cap_index = [
    FingerHeatMap(16, 8, "TS-F-A/heatMapPara16_8.dat", 7, [0, 1, 2, 3, 4, 5, 6, 255, 255, 255, 255, 255, 255, 255, 255, 255])
]

finger17_power_cap_index = [
    FingerHeatMap(6, 7, "TS-T-A/weight6X7X6.dat", 6, [0, 1, 4, 5, 6, 7, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]),
    FingerHeatMap(6, 7, "TS-T-A/weight6X7X6.dat", 6, [2, 3, 8, 9, 10, 11, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255])
]

# 定义 fingerParams 数据
finger_params = [
    FingerParamTS(2, 62, 8, 7, 1, 1, 0, 4, 2, 0, 22, "通用手指", "TypeA", finger2_power_cap_index),
    FingerParamTS(17, 78, 16, 13, 2, 2, 1, 3, 4, 1, 22, "两指-大包", "TypeB", finger17_power_cap_index),
]
