Skip to content

Commit

Permalink
Merge pull request #54 from LazeMSS/develop
Browse files Browse the repository at this point in the history
0.0.1.5 -
  • Loading branch information
LazeMSS authored Sep 7, 2021
2 parents 50073b9 + ad86ad4 commit 806bd5f
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 43 deletions.
63 changes: 51 additions & 12 deletions octoprint_toptemp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self):

# List of psu
self.psutilList = {
'cpup' : ['CPU usage percentage'],
'cpup' : ['CPU usage %'],
'cpuf' : ['CPU frequency in MHz'],
'loadavg1' : ['Average system load last 1 minute'],
'loadavg5' : ['Average system load last 5 minutes'],
Expand All @@ -47,11 +47,11 @@ def __init__(self):
'memavail' : ['Total available memory in MB'],
'memused' : ['Memory used in MB'],
'memfree' : ['Memory not being used at all in MB'],
'memp' : ['Memory free percentage'],
'memp' : ['Memory free %'],
'swaptotal' : ['Total swap memory in MB'],
'swapused' : ['Used swap memory in MB'],
'swapfree' : ['Free swap memory in MB'],
'swapperc' : ['Free swap percentage']
'swapperc' : ['Free swap %']
}

# Gcode handling
Expand All @@ -71,6 +71,7 @@ def __init__(self):
'fahrenheit' : False,
'leftAlignIcons' : False,
'hideInactiveTemps' : True,
'clickPopover' : False,
'noTools' : self.noTools,
'sortOrder': ['bed','tool0','tool1','chamber','cu0'],
'outerMargin': 4,
Expand Down Expand Up @@ -361,10 +362,10 @@ def buildPsuUtil(self):
partitions = [partition._asdict() for partition in psutil.disk_partitions()]
count = 0
for partition in partitions:
self.psutilList['diskfree_'+str(count)] = ["Disk free "+partition['mountpoint'],partition['mountpoint']]
self.psutilList['disktotal_'+str(count)] = ["Disk total "+partition['mountpoint'],partition['mountpoint']]
self.psutilList['diskused_'+str(count)] = ["Disk used "+partition['mountpoint'],partition['mountpoint']]
self.psutilList['diskperc_'+str(count)] = ["Disk used percent "+partition['mountpoint'],partition['mountpoint']]
self.psutilList['diskfree_'+str(count)] = ["Disk free \""+partition['mountpoint']+"\"",partition['mountpoint']]
self.psutilList['disktotal_'+str(count)] = ["Disk total \""+partition['mountpoint']+"\"",partition['mountpoint']]
self.psutilList['diskused_'+str(count)] = ["Disk used \""+partition['mountpoint']+"\"",partition['mountpoint']]
self.psutilList['diskperc_'+str(count)] = ["Disk used % \""+partition['mountpoint']+"\"",partition['mountpoint']]
count += 1

# temperatures
Expand Down Expand Up @@ -403,7 +404,7 @@ def buildPsuUtil(self):
if hasattr(psutil, "sensors_battery"):
battery = psutil.sensors_battery()
if battery:
self.psutilList['batper'] = ["Battery power left percentage"]
self.psutilList['batper'] = ["Battery power left %"]
self.psutilList['batsec'] = ["Battery power left seconds"]

self.debugOut(self.psutilList)
Expand Down Expand Up @@ -569,6 +570,23 @@ def runPSUtil(self,indx,cmd,returnData = False):
# 'swapused' : ['Used swap memory'],
# 'swapfree' : ['Free swap memory'],
# 'swapperc' : ['Free swap percentage']
# Icons to the above
# <i class="fas fa-microchip"></i>
# <i class="fas fa-microchip"></i>
# <i class="fas fa-tachometer-alt"></i>
# <i class="fas fa-tachometer-alt"></i>
# <i class="fas fa-tachometer-alt"></i>
# <i class="fas fa-memory"></i>
# <i class="fas fa-memory"></i>
# <i class="fas fa-memory"></i>
# <i class="fas fa-memory"></i>
# <i class="fas fa-memory"></i>
# exchange-alt
#
# disk: <i class="fas fa-hdd"></i>
# temp: <i class="fas fa-thermometer-half"></i>
# fan: <i class="fas fa-fan"></i>
# battery: <i class="fas fa-battery-half"></i>
# self.psutilList['diskfree_'+str(count)] = ["Disk free "+partition['mountpoint'],partition['mountpoint']]
# self.psutilList['disktotal_'+str(count)] = ["Disk total "+partition['mountpoint'],partition['mountpoint']]
# self.psutilList['diskused_'+str(count)] = ["Disk used "+partition['mountpoint'],partition['mountpoint']]
Expand Down Expand Up @@ -635,7 +653,7 @@ def runPSUtil(self,indx,cmd,returnData = False):
if returnVal:
self.debugOut("psutil " + cmd + " returned: " + str(returnVal) + " for index :"+indx)
if returnData:
return returnVal;
return returnVal
self.handleCustomData(indx,returnVal,time.time())

# Disk
Expand Down Expand Up @@ -677,11 +695,11 @@ def runPSUtil(self,indx,cmd,returnData = False):
if returnVal:
self.debugOut("psutil " + cmd + " returned: " + str(returnVal) + " for index :"+indx)
if returnData:
return returnVal;
return returnVal
self.handleCustomData(indx,returnVal,time.time())

if returnData:
return None;
return None

def handleCustomData(self,indx,out,time):
self.debugOut("Got custom data: " + str(out))
Expand Down Expand Up @@ -709,7 +727,8 @@ def get_api_commands(self):
monitorService=[],
getCustomHistory=[],
getDefaultSettings=[],
getPredefined=['reload']
getPredefined=['reload'],
getItems=[]
)

# handle api calls
Expand All @@ -727,6 +746,26 @@ def on_api_command(self, command, data):
self.debugOut("Sending options")
return flask.jsonify({'cmds' : self.tempCmds,'psutil' : self.psutilList})

if command == "getItems":
self._logger.info("Sending items monitored")
sortOrder = self._settings.get(["sortOrder"],merged=True,asdict=True)
custom = self._settings.get(["customMon"],merged=True,asdict=True)
curTemps = self._printer.get_current_temperatures();
returnList = {}
lastValues = {}
for item in sortOrder:
lastVal = None
if item in custom:
returnList[item] = custom[item]
if item in self.customHistory:
lastVal = self.customHistory[item] and self.customHistory[item][-1][1] or None
else:
if item in curTemps:
lastVal = curTemps[item]['actual']
returnList[item] = self._settings.get([item],merged=True,asdict=True)
lastValues[item] = lastVal
return flask.jsonify({'items' : returnList,'lastValues': lastValues})

# Get history data
if command == "getCustomHistory":
self.debugOut("Sending custom history")
Expand Down
21 changes: 21 additions & 0 deletions octoprint_toptemp/static/css/TopTemp.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@
height: 100%;
overflow: hidden;
}
#navbar_plugin_toptemp div.TopTempPrinter.popclick, #navbar_plugin_toptemp div.TopTempCustom.popclick{
cursor: pointer;
}

@media (max-width: 767px){
#navbar_plugin_toptemp div.TopTempPrinter div.navbar-text, #navbar_plugin_toptemp div.TopTempCustom div.navbar-text{
height: 100%;
margin-top: 6px;
line-height: initial;
}
}

#navbar_plugin_toptemp div .TopTempIcon{
display: block;
Expand Down Expand Up @@ -152,6 +163,12 @@ div.popover.toptempPopover {
z-index: 1030;
}

div.popover.toptempPopover .popover-title a{
float: left;
margin-right: 5px;
margin-left: -8px;
}

#navbar_plugin_toptemp div.TopTempGraph .ct-line {
stroke-width: 1px;
stroke-opacity: 0.4;
Expand Down Expand Up @@ -214,4 +231,8 @@ body.TopTemPreviewON div#settings_dialog {
color: #333;
}

#navbar_plugin_toptemp > div:not(.IconsLeft) .navbar-text{
line-height: 15px;
}

/* TopTemp END */
78 changes: 54 additions & 24 deletions octoprint_toptemp/static/js/TopTemp.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ $(function() {
'gcOut': {
'Cooling fan speed' : '^M106.*?S([^ ]+)',
'Feedrate %' : '^M220 S([^ ]+)',
'% Completed' : '^M73.*?P(\\d+)',
// 'Extruder feed rate' : '^(?:G0|G1).*?F([^ ]+)'
}
};
Expand Down Expand Up @@ -101,7 +102,7 @@ $(function() {
}
}else{
var reval = 0;
graphData = {'series' : [OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[name].actual.slice(-300).map(function(val,i){return val[1]})]};
graphData = {'series' : [self.tempModel.temperatures[name].actual.slice(-300).map(function(val,i){return val[1]})]};
}
// DO we have what we need
if (graphData != null && typeof Chartist == "object"){
Expand Down Expand Up @@ -267,7 +268,7 @@ $(function() {
}
}

// CPU Temps
// Custom data
self.onDataUpdaterPluginMessage = function(plugin, data) {
if (plugin != "toptemp"){
return;
Expand Down Expand Up @@ -1038,7 +1039,6 @@ $(function() {
}
if (self.isCustom(name)){
self.buildContainer(name,'TopTempCustom TopTempLoad');

}else{
self.buildContainer(name,'TopTempPrinter TopTempLoad');
}
Expand Down Expand Up @@ -1078,10 +1078,16 @@ $(function() {
return;
}

// How should we show popovers
var popoverDmethod = 'manual';
if (self.settings.clickPopover()){
popoverDmethod = "click";
}

// Initial creation
if (!$this.data('popover') != null || !$this.data('popover').enabled){
$this.popover({
'trigger': 'manual',
'trigger': popoverDmethod,
'placement' : 'bottom',
'container': '#page-container-main',
'html' : true,
Expand All @@ -1092,19 +1098,19 @@ $(function() {
if (iconClone.length){
iconstr = iconClone.clone().addClass('pull-right').wrap('<p>').parent().html()
}
if (self.settings.clickPopover()){
iconstr += '<a onclick="javascript:$(\'#navbar_plugin_toptemp_'+$thisID+'\').popover(\'hide\');"><i class="far fa-times-circle"></i></a>';
}
return self.getTempName($thisID)+iconstr;
},
'content': '<div id="TopTempPopoverText_'+$thisID+'" class="TopTempPopoverText clearfix">Wait&hellip;</div><div id="TopTempPopoverGraph_'+$thisID+'" class="TopTempPopoverGraph"></div>'
});
}

// Show the popover and update content
$this.off('mouseenter').on('mouseenter',function(){
if ($this.hasClass('TopTempLoad')){
return;
// On show
$this.on('shown',function(){
if (self.popoverOpen && self.settings.clickPopover()){
$('#navbar_plugin_toptemp >div').not($this).popover('hide')
}
// Fix offset problems
$this.popover('show');
self.popoverOpen = true;
// Fix arrows hacks for small screens
if ($(window).width() <=767){
Expand All @@ -1114,12 +1120,29 @@ $(function() {
}
// Build contents
self.updatePopover($thisID,$isCustom,isettings);
});

// On hidden
$this.on('hidden',function(){
self.popoverOpen = false;
})

// Show the popover and update content
$this.off('mouseenter').on('mouseenter',function(){
if ($this.hasClass('TopTempLoad')){
return;
}
// Fix offset problems
if (popoverDmethod == "manual"){
$this.popover('show');
}
}).off('mouseleave').on('mouseleave',function(){
if ($this.hasClass('TopTempLoad')){
return;
}
self.popoverOpen = false;
$this.popover('hide');
if (popoverDmethod == "manual"){
$this.popover('hide');
}
}).attr('title',"Show more information");
});
}
Expand All @@ -1143,8 +1166,8 @@ $(function() {
$('#TopTempPopoverText_'+$thisID).html(output);
}
}else{
var actual = OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].actual[OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].actual.length-1][1];
var target = OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].target[OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].target.length-1][1];
var actual = self.tempModel.temperatures[$thisID].actual[self.tempModel.temperatures[$thisID].actual.length-1][1];
var target = self.tempModel.temperatures[$thisID].target[self.tempModel.temperatures[$thisID].target.length-1][1];
var output = '<div class="pull-left"><small>Actual: '+self.formatTempLabel($thisID,actual,iSettings)+'</small></div><div class="pull-right"><small>Target: ';
if (target == 0){
output += 'Off';
Expand Down Expand Up @@ -1261,8 +1284,8 @@ $(function() {
// Assign it
graphData = {
'series' : [
{'data':buildSeries([...OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].actual]),'className':'ct-series-a'},
{'data':buildSeries([...OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].target]),'className':'ct-series-g'},
{'data':buildSeries([...self.tempModel.temperatures[$thisID].actual]),'className':'ct-series-a'},
{'data':buildSeries([...self.tempModel.temperatures[$thisID].target]),'className':'ct-series-g'},
]
};
}
Expand Down Expand Up @@ -1367,33 +1390,40 @@ $(function() {
// Build a single container
self.buildContainer = function(name,className){
var elname = 'navbar_plugin_toptemp_'+name;
var settings = self.getSettings(name);
var localSettings = self.getSettings(name);
// Get name
prettyName = self.getTempName(name);
// Set type
var isCust = false;
if (self.isCustom(name)){
isCust = true;
if (settings.waitForPrint()){
if (localSettings.waitForPrint()){
className += " TopTempWaitPrinter";
}
}
if (self.settings.leftAlignIcons()){
className += " IconsLeft";
}
var textClass = "TopTempText";
if (!localSettings.graphSettings.show()){
textClass = "navbar-text";
}
// Remove old
$('#'+elname).remove();
// Build new
$('#navbar_plugin_toptemp').append('<div title="'+prettyName+'" id="'+elname+'" class="'+className+'" data-toptempid="'+name+'" data-toptempcust="'+isCust+'"><div id="TopTempGraph_'+name+'_graph" class="TopTempGraph"></div><div id="navbar_plugin_toptemp_'+name+'_text" class="TopTempText"></div></div>');
if (!settings.show()){
if (self.settings.clickPopover() && localSettings.graphSettings.show()){
className += " popclick";
}
$('#navbar_plugin_toptemp').append('<div title="'+prettyName+'" id="'+elname+'" class="'+className+'" data-toptempid="'+name+'" data-toptempcust="'+isCust+'"><div id="TopTempGraph_'+name+'_graph" class="TopTempGraph"></div><div id="navbar_plugin_toptemp_'+name+'_text" class="'+textClass+'"></div></div>');
if (!localSettings.show()){
$('#'+elname).hide();
}
// Set fixed width if entered
if (settings.width() > 0){
$('#'+elname).css({'width':settings.width()+'px'});
if (localSettings.width() > 0){
$('#'+elname).css({'width':localSettings.width()+'px'});
}

self.setGraphStyle(name,settings.graphSettings);
self.setGraphStyle(name,localSettings.graphSettings);
return elname;
}

Expand Down
Loading

0 comments on commit 806bd5f

Please sign in to comment.