micropython/python3 compatible modules
Posted: Sat Jun 18, 2022 6:11 pm
I am working on a module that will normally run under micopython but can be used with python3
After finding many ways to include the time.ticks_* upython functions in python3, this is the only coding that worked. Is this acceptable or is there a better approach?
In my module's example applications there is code I want to leave out code (machine.WDT for example) if not running with upython. Is there a way to determine it the application is running with upython?
Thanks,
Curt
After finding many ways to include the time.ticks_* upython functions in python3, this is the only coding that worked. Is this acceptable or is there a better approach?
Code: Select all
try :
import utime as time
except :
from types import MethodType
import time as time
def ticks_ms(self):
return int (round (time.time () * 1000))
def ticks_add(self, ms_1, ms_2):
return ms_1 + ms_2
def ticks_diff(self, ms_1, ms_2):
return ms_1 - ms_2
def sleep_ms (self, ms_1) :
return time.sleep (ms_1 / 1000)
time.ticks_ms = MethodType (ticks_ms, time)
time.ticks_add = MethodType (ticks_add, time)
time.ticks_diff = MethodType (ticks_diff, time)
time.sleep_ms = MethodType (sleep_ms, time)
Thanks,
Curt