-
Notifications
You must be signed in to change notification settings - Fork 189
/
hal.py
133 lines (130 loc) · 4.36 KB
/
hal.py
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# This implementation allows to use different hardware.
# Imported module contains functions for hardware access fo some board/SoC.
# List of HAL methods that should be implemented in each module:
# def init():
# """ Initialize GPIO pins and machine itself.
# """
# do_something()
#
#
# def spindle_control(percent):
# """ Spindle control implementation.
# :param percent: Spindle speed in percent 0..100. 0 turns spindle off.
# """
# do_something()
#
#
# def fan_control(on_off):
# """
# Cooling fan control.
# :param on_off: boolean value if fan is enabled.
# """
# do_something()
#
#
# def extruder_heater_control(percent):
# """ Extruder heater control.
# :param percent: heater power in percent 0..100. 0 turns heater off.
# """
# do_something()
#
#
# def bed_heater_control(percent):
# """ Hot bed heater control.
# :param percent: heater power in percent 0..100. 0 turns heater off.
# """
# do_something()
#
#
# def get_extruder_temperature():
# """ Measure extruder temperature.
# Can raise OSError or IOError on any issue with sensor.
# :return: temperature in Celsius.
# """
# return measure()
#
#
# def get_bed_temperature():
# """ Measure bed temperature.
# Can raise OSError or IOError on any issue with sensor.
# :return: temperature in Celsius.
# """
# return measure()
#
#
# def disable_steppers():
# """ Disable all steppers until any movement occurs.
# """
# do_something()
#
#
# def calibrate(x, y, z):
# """ Move head to home position till end stop switch will be triggered.
# Do not return till all procedures are completed.
# :param x: boolean, True to calibrate X axis.
# :param y: boolean, True to calibrate Y axis.
# :param z: boolean, True to calibrate Z axis.
# :return: boolean, True if all specified end stops were triggered.
# """
# return do_something()
#
#
# def move(generator):
# """ Move head to according pulses in PulseGenerator.
# :param generator: PulseGenerator object
# """
# do_something()
#
#
# def join():
# """ Wait till motors work.
# """
# do_something()
#
#
# def deinit():
# """ De-initialise hal, stop any hardware.
# """
# do_something()
#
#
# def watchdog_feed():
# """ Feed hardware watchdog. This method should be called at least
# once in 15 seconds. Also, this method can do no operation in hal
# implementation and there will not be emergency stop for heaters.
# """
# do_something()
# check which module to import
try:
from cnc.hal_raspberry.hal import *
except ImportError:
print("----- Hardware not detected, using virtual environment -----")
print("----- Use M111 command to enable more detailed debug -----")
from cnc.hal_virtual import *
# check if all methods that is needed is implemented
if 'init' not in locals():
raise NotImplementedError("hal.init() not implemented")
if 'spindle_control' not in locals():
raise NotImplementedError("hal.spindle_control() not implemented")
if 'fan_control' not in locals():
raise NotImplementedError("hal.fan_control() not implemented")
if 'extruder_heater_control' not in locals():
raise NotImplementedError("hal.extruder_heater_control() not implemented")
if 'bed_heater_control' not in locals():
raise NotImplementedError("hal.bed_heater_control() not implemented")
if 'get_extruder_temperature' not in locals():
raise NotImplementedError("hal.get_extruder_temperature() not implemented")
if 'get_bed_temperature' not in locals():
raise NotImplementedError("hal.get_bed_temperature() not implemented")
if 'disable_steppers' not in locals():
raise NotImplementedError("hal.disable_steppers() not implemented")
if 'calibrate' not in locals():
raise NotImplementedError("hal.calibrate() not implemented")
if 'move' not in locals():
raise NotImplementedError("hal.move() not implemented")
if 'join' not in locals():
raise NotImplementedError("hal.join() not implemented")
if 'deinit' not in locals():
raise NotImplementedError("hal.deinit() not implemented")
if 'watchdog_feed' not in locals():
raise NotImplementedError("hal.watchdog_feed() not implemented")