Python machine.enable_irq() Examples
The following are 9
code examples of machine.enable_irq().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
machine
, or try the search function
.
Example #1
Source File: input.py From micropython-m5stack with MIT License | 6 votes |
def _callback(self, pin): irq_state = machine.disable_irq() while True: self._register[0] <<= 1 self._register[0] |= pin.value() #print("{:08b}".format(self._register[0])) # All bits set, button has been released for 8 loops if self._register[0] is 0b11111111: self._current_state = False break # All bits unset, button has been pressed for 8 loops if self._register[0] is 0b00000000: self._current_state = True break # Handle edge case of two consequent rising interrupts if self._current_state is not self._previous_state: self._previous_state = self._current_state self._user_callback(self._pin, self._current_state) machine.enable_irq(irq_state)
Example #2
Source File: as_tGPS.py From micropython-async with MIT License | 6 votes |
def get_t_split(self): state = machine.disable_irq() t = self.t_ms acquired = self.acquired machine.enable_irq(state) isecs, ims = divmod(t, 1000) # Get integer secs and ms x, secs = divmod(isecs, 60) hrs, mins = divmod(x, 60) dt = utime.ticks_diff(utime.ticks_us(), acquired) # μs to time now ds, us = divmod(dt, 1000000) # If dt > 1e6 can add to secs without risk of rollover: see above. self._time[0] = hrs self._time[1] = mins self._time[2] = secs + ds self._time[3] = us + ims*1000 return self._time
Example #3
Source File: as_tGPS.py From micropython-async with MIT License | 6 votes |
def get_t_split(self): state = machine.disable_irq() t = self.t_ms acquired = self.acquired machine.enable_irq(state) isecs, ims = divmod(t, 1000) # Get integer secs and ms x, secs = divmod(isecs, 60) hrs, mins = divmod(x, 60) dt = utime.ticks_diff(utime.ticks_us(), acquired) # μs to time now ds, us = divmod(dt, 1000000) # If dt > 1e6 can add to secs without risk of rollover: see above. self._time[0] = hrs self._time[1] = mins self._time[2] = secs + ds self._time[3] = us + ims*1000 return self._time
Example #4
Source File: __init__.py From platypush with MIT License | 5 votes |
def enable_irq(self, **kwargs): """ Enable interrupt requests. :param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.execute`. """ code = ''' import machine machine.enable_irq() ''' return self.execute(code, **kwargs).output
Example #5
Source File: unetrepl.py From ulnoiot-upy with MIT License | 5 votes |
def acquire_out_buffer(self): while self.out_buffer_lock == True: time.sleep_ms(1) # Wait for release self.irqstate = machine.disable_irq() if self.out_buffer_lock == True: # TODO: check if this locking is enough machine.enable_irq(self.irqstate) return False self.out_buffer_lock = True return True
Example #6
Source File: unetrepl.py From ulnoiot-upy with MIT License | 5 votes |
def release_out_buffer(self): self.out_buffer_lock = False machine.enable_irq(self.irqstate)
Example #7
Source File: as_tGPS.py From micropython-async with MIT License | 5 votes |
def get_ms(self): state = machine.disable_irq() t = self.t_ms acquired = self.acquired machine.enable_irq(state) return t + utime.ticks_diff(utime.ticks_us(), acquired) // 1000 # Return accurate GPS time of day (hrs: int, mins: int, secs: int, μs: int) # The ISR can skip an update of .secs if a day rollover would occur. Next # RMC handles this, so if updates are at 1s intervals the subsequent ISR # will see hms = 0, 0, 1 and a value of .acquired > 1000000. # Even at the slowest update rate of 10s this can't overflow into minutes.
Example #8
Source File: as_tGPS.py From micropython-async with MIT License | 5 votes |
def get_ms(self): state = machine.disable_irq() t = self.t_ms acquired = self.acquired machine.enable_irq(state) return t + utime.ticks_diff(utime.ticks_us(), acquired) // 1000 # Return accurate GPS time of day (hrs: int, mins: int, secs: int, μs: int) # The ISR can skip an update of .secs if a day rollover would occur. Next # RMC handles this, so if updates are at 1s intervals the subsequent ISR # will see hms = 0, 0, 1 and a value of .acquired > 1000000. # Even at the slowest update rate of 10s this can't overflow into minutes.
Example #9
Source File: compat.py From terkin-datalogger with GNU Affero General Public License v3.0 | 5 votes |
def monkeypatch_machine(): from mock import Mock import uuid import machine # Some primitives. machine.enable_irq = Mock() machine.disable_irq = Mock() machine.unique_id = lambda: str(uuid.uuid4().fields[-1])[:5].encode() machine.freq = Mock(return_value=42000000) machine.idle = Mock() # Reset cause and wake reason. machine.PWRON_RESET = 0 machine.HARD_RESET = 1 machine.WDT_RESET = 2 machine.DEEPSLEEP_RESET = 3 machine.SOFT_RESET = 4 machine.BROWN_OUT_RESET = 5 machine.PWRON_WAKE = 0 machine.GPIO_WAKE = 1 machine.RTC_WAKE = 2 machine.ULP_WAKE = 3 machine.reset_cause = Mock(return_value=0) machine.wake_reason = wake_reason