-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into audio-new-feature-dev
- Loading branch information
Showing
31 changed files
with
595 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Base class for asyncio modes.""" | ||
import abc | ||
import asyncio | ||
|
||
from mpf.core.mode import Mode | ||
|
||
|
||
class AsyncMode(Mode, metaclass=abc.ABCMeta): | ||
|
||
"""Base class for asyncio modes.""" | ||
|
||
def __init__(self, machine, config, name, path): | ||
"""Initialise async mode.""" | ||
super().__init__(machine, config, name, path) | ||
|
||
self._task = None | ||
|
||
def _started(self): | ||
"""Start main task.""" | ||
super()._started() | ||
|
||
self._task = self.machine.clock.loop.create_task(self._run()) | ||
|
||
def _stopped(self): | ||
"""Cancel task.""" | ||
super()._stopped() | ||
|
||
self._task.cancel() | ||
|
||
@abc.abstractmethod | ||
@asyncio.coroutine | ||
def _run(self): | ||
"""Main task which runs as long as the mode is active. | ||
Overwrite this function in your mode. | ||
Its automatically canceled when the mode stops. You can catch CancelError to handle mode stop. | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"""Base class for MPF controllers.""" | ||
import abc | ||
|
||
|
||
class MpfController(metaclass=abc.ABCMeta): | ||
|
||
"""Base class for MPF controllers.""" | ||
|
||
def __init__(self, machine): | ||
"""Initialise controller. | ||
Args: | ||
machine(mpf.core.machine.MachineController): the machine controller | ||
Returns: | ||
""" | ||
self.machine = machine |
Oops, something went wrong.