33 lines
No EOL
983 B
Python
33 lines
No EOL
983 B
Python
import datetime, megaind, asyncio
|
|
from src.variables.service import set_variable
|
|
|
|
|
|
|
|
async def run():
|
|
impuls_count_per_rpm: int = 4
|
|
|
|
last1: bool = False
|
|
last1_time: datetime.datetime = datetime.datetime.now()
|
|
|
|
lock = asyncio.Lock()
|
|
average = []
|
|
while True:
|
|
puls = megaind.getOptoCh(0, 1)
|
|
if puls == 1 and last1 == False:
|
|
last1 = True
|
|
pulse_time = datetime.datetime.now()
|
|
delay = pulse_time - last1_time
|
|
last1_time = pulse_time
|
|
rising_per_second = 1 / (delay.microseconds / 1000000)
|
|
average.append((rising_per_second / impuls_count_per_rpm) * 60)
|
|
if len(average) > 4:
|
|
average.remove(average[0])
|
|
|
|
averaged = 0
|
|
for i in average:
|
|
averaged += i
|
|
async with lock:
|
|
set_variable("actual_rpm", round(averaged / len(average), 1), False)
|
|
|
|
elif puls == 0:
|
|
last1 = False |