-
Notifications
You must be signed in to change notification settings - Fork 1
/
driver.py
91 lines (74 loc) · 2.24 KB
/
driver.py
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
from ctypes import (
CDLL,
c_uint32,
c_float,
)
from enum import IntEnum
PATH_PWM_DRIVER = "./driver/pwm.so"
PATH_ADC_DRIVER = "./driver/adc.so"
class PwmType(IntEnum):
CCS_A = 1,
CCS_B = 2,
class Pwm:
def __init__(
self,
pwm_type: PwmType = PwmType.CCS_A
):
"""
# TODO : PwmType is for Further Development that we could Configure Multiple pwm by the unique function
:param pwm_type:
"""
# Here We Reference Our C driver via ctypes to the python
self.pwm_type = pwm_type
self.PwmDriver = CDLL(PATH_PWM_DRIVER)
self.PwmDriver.ccs_pwm_config.restype = c_uint32
self.PwmDriver.ccs_pwm_set_duty_cycle.argtypes = [c_uint32, c_float]
# Here we Config Our Pwm
self.PwmDriver.ccs_pwm_config(self.pwm_type)
def Pwm_SetDutyCycle(self, duty_cycle: float):
self.PwmDriver.ccs_pwm_set_duty_cycle(self.pwm_type, duty_cycle)
class Adc:
def __init__(self):
self.AdcDriver = CDLL(PATH_ADC_DRIVER)
# Function find_device1()
self.AdcDriver.find_device1.argtype = c_uint32
self.AdcDriver.find_device1.restype = c_uint32
# Function read_mean_raw_device1()
self.AdcDriver.read_mean_raw_device1.argtype = c_uint32
self.AdcDriver.read_mean_raw_device1.restype = c_uint32
# Function read_mean_voltage_device1()
self.AdcDriver.read_mean_voltage_device1.argtype = c_uint32
self.AdcDriver.read_mean_voltage_device1.restype = c_float
self._find_device(2)
def _find_device(self, scale: int):
self.AdcDriver.find_device1(2)
def read_raw(self, _time: int) -> int:
raw = self.AdcDriver.read_mean_raw_device1(_time)
return raw
def read_voltage(self) :
voltage = self.AdcDriver.read_mean_voltage_device1(1)
voltage = voltage*4
return voltage
# def main():
# ccs_a_pwm = Pwm()
# ccs_a_pwm.Pwm_SetDutyCycle(5)
# adc = Adc()
#
# print(adc.read_raw(1))
# val = adc.read_voltage()
#
# print(val)
#
#
# # while True:
# # print(adc.read_raw(2))
# # time.sleep(1)
#
#
# def run():
# # asyncio.run(main())
# main()
#
#
# if __name__ == "__main__":
# run()