1010import sys
1111import re
1212
13+ from .libs .sbc import SBCFactory
14+
15+
1316class NavBarPlugin (octoprint .plugin .StartupPlugin ,
1417 octoprint .plugin .TemplatePlugin ,
1518 octoprint .plugin .AssetPlugin ,
1619 octoprint .plugin .SettingsPlugin ):
1720
1821 def __init__ (self ):
19- self .isRaspi = False
20- self .debugMode = False # to simulate temp on Win/Mac
22+ self .piSocTypes = (["BCM2708" , "BCM2709" ,
23+ "BCM2835" ]) # Array of raspberry pi SoC's to check against, saves having a large if/then statement later
24+ self .debugMode = False # to simulate temp on Win/Mac
2125 self .displayRaspiTemp = True
2226 self ._checkTempTimer = None
27+ self .sbc = None
2328
2429 def on_after_startup (self ):
2530 self .displayRaspiTemp = self ._settings .get (["displayRaspiTemp" ])
31+ self .piSocTypes = self ._settings .get (["piSocTypes" ])
2632 self ._logger .debug ("displayRaspiTemp: %s" % self .displayRaspiTemp )
2733
2834 if sys .platform == "linux2" :
29- with open ('/proc/cpuinfo' , 'r' ) as infile :
30- cpuinfo = infile .read ()
31- # Match a line like 'Hardware : BCM2709'
32- match = re .search ('^Hardware\s+:\s+(\w+)$' , cpuinfo , flags = re .MULTILINE | re .IGNORECASE )
33-
34- if match is None :
35- # Couldn't find the hardware, assume it isn't a pi.
36- self .isRaspi = False
37- elif match .group (1 ) == 'BCM2708' :
38- self ._logger .debug ("Pi 1" )
39- self .isRaspi = True
40- elif match .group (1 ) == 'BCM2709' :
41- self ._logger .debug ("Pi 2" )
42- self .isRaspi = True
43- elif match .group (1 ) == 'BCM2835' :
44- self ._logger .debug ("Pi 3" )
45- self .isRaspi = True
46-
47- if self .isRaspi and self .displayRaspiTemp :
35+ self .sbc = SBCFactory ().factory (self ._logger )
36+
37+ if self .sbc .is_supported and self .displayRaspiTemp :
4838 self ._logger .debug ("Let's start RepeatedTimer!" )
4939 self .startTimer (30.0 )
40+ # debug mode doesn't work if the OS is linux on a regular pc
5041 elif self .debugMode :
51- self .isRaspi = True
42+ self .sbc . is_supported = True
5243 if self .displayRaspiTemp :
5344 self .startTimer (5.0 )
5445
55- self ._logger .debug ("is Raspberry Pi ? - %s" % self .isRaspi )
46+ self ._logger .debug ("is supported ? - %s" % self .sbc . is_supported )
5647
5748 def startTimer (self , interval ):
58- self ._checkTempTimer = RepeatedTimer (interval , self .checkRaspiTemp , None , None , True )
49+ self ._checkTempTimer = RepeatedTimer (interval , self .updateSoCTemp , None , None , True )
5950 self ._checkTempTimer .start ()
6051
61- def checkRaspiTemp (self ):
62- from sarge import run , Capture
63-
64- self ._logger .debug ("Checking Raspberry Pi internal temperature" )
65-
66- if sys .platform == "linux2" :
67- p = run ("/opt/vc/bin/vcgencmd measure_temp" , stdout = Capture ())
68- p = p .stdout .text
69-
70- elif self .debugMode :
71- import random
72- def randrange_float (start , stop , step ):
73- return random .randint (0 , int ((stop - start ) / step )) * step + start
74- p = "temp=%s'C" % randrange_float (5 , 60 , 0.1 )
52+ def updateSoCTemp (self ):
53+ temp = self .sbc .checkSoCTemp ()
54+ self ._logger .debug ("match: %s" % temp )
55+ self ._plugin_manager .send_plugin_message (self ._identifier ,
56+ dict (isSupported = self .sbc .is_supported ,
57+ soctemp = temp ))
7558
76- self ._logger .debug ("response from sarge: %s" % p )
77-
78- match = re .search ('=(.*)\' ' , p )
79- if not match :
80- self .isRaspi = False
81- else :
82- temp = match .group (1 )
83- self ._logger .debug ("match: %s" % temp )
84- self ._plugin_manager .send_plugin_message (self ._identifier , dict (israspi = self .isRaspi , raspitemp = temp ))
85-
86-
87- ##~~ SettingsPlugin
59+ ##~~ SettingsPlugin
8860 def get_settings_defaults (self ):
89- return dict (displayRaspiTemp = self .displayRaspiTemp )
61+ return dict (displayRaspiTemp = self .displayRaspiTemp ,
62+ piSocTypes = self .piSocTypes )
9063
9164 def on_settings_save (self , data ):
9265 octoprint .plugin .SettingsPlugin .on_settings_save (self , data )
@@ -104,9 +77,9 @@ def on_settings_save(self, data):
10477 pass
10578 self ._plugin_manager .send_plugin_message (self ._identifier , dict ())
10679
107- ##~~ TemplatePlugin API
80+ ##~~ TemplatePlugin API
10881 def get_template_configs (self ):
109- if self .isRaspi :
82+ if self .sbc . is_supported :
11083 return [
11184 dict (type = "settings" , template = "navbartemp_settings_raspi.jinja2" )
11285 ]
@@ -119,9 +92,10 @@ def get_assets(self):
11992 "js" : ["js/navbartemp.js" ],
12093 "css" : ["css/navbartemp.css" ],
12194 "less" : ["less/navbartemp.less" ]
122- }
95+ }
96+
97+ ##~~ Softwareupdate hook
12398
124- ##~~ Softwareupdate hook
12599 def get_update_information (self ):
126100 return dict (
127101 navbartemp = dict (
@@ -130,22 +104,26 @@ def get_update_information(self):
130104
131105 # version check: github repository
132106 type = "github_release" ,
133- user = "imrahil " ,
107+ user = "ntoff " ,
134108 repo = "OctoPrint-NavbarTemp" ,
135109 current = self ._plugin_version ,
136110
137111 # update method: pip w/ dependency links
138- pip = "https://github.com/imrahil /OctoPrint-NavbarTemp/archive/{target_version}.zip"
112+ pip = "https://github.com/ntoff /OctoPrint-NavbarTemp/archive/{target_version}.zip"
139113 )
140114 )
141115
142- __plugin_name__ = "Navbar Temperature Plugin"
116+
117+ __plugin_name__ = "Navbar Temperature Plugin (ntoff mod)"
118+ __plugin_author__ = "Jarek Szczepanski (modified by ntoff)"
119+ __plugin_url__ = "https://github.com/ntoff/OctoPrint-NavbarTemp"
120+
143121
144122def __plugin_load__ ():
145- global __plugin_implementation__
146- __plugin_implementation__ = NavBarPlugin ()
123+ global __plugin_implementation__
124+ __plugin_implementation__ = NavBarPlugin ()
147125
148- global __plugin_hooks__
149- __plugin_hooks__ = {
150- "octoprint.plugin.softwareupdate.check_config" : __plugin_implementation__ .get_update_information
151- }
126+ global __plugin_hooks__
127+ __plugin_hooks__ = {
128+ "octoprint.plugin.softwareupdate.check_config" : __plugin_implementation__ .get_update_information
129+ }
0 commit comments