forked from jamieboyd/AutoHeadFix
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAHF_Base.py
More file actions
executable file
·108 lines (91 loc) · 3.61 KB
/
AHF_Base.py
File metadata and controls
executable file
·108 lines (91 loc) · 3.61 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#! /usr/bin/python3
#-*-coding: utf-8 -*-
"""
AHF_Base.py
================================================
The base upon which everything else is built
"""
from abc import ABCMeta, abstractmethod
#This creates a cyclic import - doesn't seem to be a problem on it's own, but
#it is creating problems in debugging.
#import AHF_ClassAndDictUtils as CAD
class AHF_Base(metaclass = ABCMeta):
"""
Defines conventions for classes used for accesing hardware and doing subtasks in AutoHeadFix code
Each class has a static method, config_user_get, to create or edit a settings dictionary, and will be inititialized
with a settings dictionary. The setup function does hardware initialization, or other inititialization.
"""
@staticmethod
@abstractmethod
def about():
"""
Returns a brief message describing your sub-class, used when asking user to pick a sub-class of this class
"""
return 'A description of your sub-class goes here'
@staticmethod
@abstractmethod
def config_user_get(starterDict = {}):
"""
static method that querries user for settings, with default responses from starterDict,
and returns starterDict with settings as edited by the user.
"""
return starterDict
def config_subject_get(self, starterDict = {}):
"""
:returns: dict -- the default dictionary for individualized parameters
"""
return starterDict
def config_user_subject_get(self, starterDict = {}):
"""
Prompts the user for individualized parameters, with default responses
from starterDict, and returns starterDict with settings
as edited by the user.
"""
return starterDict
def __init__(self, taskP, settingsDictP):
"""
Initialization of a subclass object may be just making a link to the settings dict and running setup
so this does not need to be an abstract function - your class can use as is
__init__ will be passed both the settings dict andthe entire Task including the settings dict
Class names need to start with AHF_ and the dictionary must follow convention, named for the class with 'Dict' appended.
Args:
taskP(pointer): Task Pointer - points to the global Task object
settingsDictP(pointer): Points to the global settings dictionary
"""
self.task=taskP
self.settingsDict = settingsDictP
self.setup()
@abstractmethod
def setup(self):
"""
does hardware initialization with(possibly updated) info in self.settingsDict
Run by __init__, or can be run separately after editing the settingsDict
:returns: :code: `bool` whether setup completed without errors
"""
return True
@abstractmethod
def setdown(self):
"""
oppposite of setup. Releases any hardware resouces. can be run before editing settings so GPIO
pins can be reused, for example. This strategy should be used in hardwareTest method.
"""
pass
def __del__(self):
"""
For clean up purposes, releases hardware resources with setdown method
"""
try:
self.setdown()
except Exception as e:
#In case it has already been set down(__del__ is not predictable)
print(str(e))
finally:
del(self)
pass
@abstractmethod
def hardwareTest(self):
"""
Tests functionality, gives user a chance to change settings.
:Returns: bool -- True if any settings have changed
"""
return False