Skip to content

Commit

Permalink
Merge pull request #10 from spdermn02/AddingDataConversion
Browse files Browse the repository at this point in the history
Adding data conversion
  • Loading branch information
spdermn02 authored Jun 5, 2023
2 parents bc6f4b8 + 5aa99bc commit 4f7998d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ There are currently 3 settings for this plugin
1) Default: No
2) Valid Values: `No` or `Yes`
3) How: This takes the throughput values and divides by 1024, until the value is less than 1024, counts how many times it does the calc to know Unit, will now create a unit based state as well for those that are converted
5) `Normalize Data (MB, GB)` - Normalize SmallData values to smaller more Visually pleasing values
1) Default: No
2) Valid Values: `No` or `Yes`
3) How: This takes the SmallData values and divides by 1024, until the value is less than 1024, counts how many times it does the calc to know Unit, will now create a unit based state as well for those that are converted

## Examples

Expand Down Expand Up @@ -135,7 +139,11 @@ Event: This generates the dynamic gauge icon
- Read hardware attempts multiple tries before dying.
1.1.5 - Bug Fix
- Bug:
- Make sure that each sensor has unique Identifier name, as some appear to use the same base name
- Make sure that each sensor has unique Identifier name, as some appear to use the same base name+
1.2.0 - Data conversion Feature
- Feature:
- Added in SmallData conversion for things like Video Card RAM and any other sensor that is small data type.
-Note: This is controlled by a setting that is default No, to turn on go to the Plugin Settings in Touch Portal and change the value to Yes
```
## Build It
If you are looking to build it yourself instead of the pre-setup .tpp file
Expand Down
8 changes: 7 additions & 1 deletion base/entry.tp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": 6,
"version": 1105,
"version": 1200,
"name": "Touch Portal Hardware Monitor",
"id": "TP_HM",
"plugin_start_cmd": "\"%TP_PLUGIN_FOLDER%touchportal-hardwaremonitor\\touchportal-hardwaremonitor.exe\"",
Expand Down Expand Up @@ -33,6 +33,12 @@
"default":"No",
"type":"text",
"maxLength":3
},
{
"name":"Normalize Data (MB, GB)",
"default":"No",
"type":"text",
"maxLength":3
}
],
"categories": [
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "touchportal-hardwaremonitor",
"version": "1.1.5",
"version": "1.2.0",
"description": "Touch Portal plugin to read data from Open Hardware Monitor",
"main": "src/index.js",
"bin": "src/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
CAPTURE_INTERVAL_SETTING : 'Sensor Capture Time (ms)',
TEMP_READOUT_SETTING : 'Temperature Unit (C/F)',
NORMALIZE_THROUGHPUT : 'Normalize Throughput (B/s, KB/s, MB/s, GB/s)',
NORMALIZE_DATA: 'Normalize Data (MB, GB)',
MAX_WAIT_TIME: 60000,
updateUrl: 'https://raw.githubusercontent.com/spdermn02/TouchPortal-HardwareMonitor/main/package.json',
releaseUrl: 'https://github.com/spdermn02/TouchPortal-HardwareMonitor/releases'
Expand Down
26 changes: 21 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const hardware = {}
const pluginSettings = {
[Constants.CAPTURE_INTERVAL_SETTING] : prevCaptureInterval,
[Constants.TEMP_READOUT_SETTING]: 'C',
[Constants.NORMALIZE_THROUGHPUT]: 'No'
[Constants.NORMALIZE_THROUGHPUT]: 'No',
[Constants.NORMALIZE_DATA]: 'No'
}
let firstRun = 1
let waitTime = 1000
Expand Down Expand Up @@ -96,16 +97,31 @@ const runSensorConversions = (sensor) => {
sensor.Value = currValue
sensor.Unit = unit
}
else if( sensor.SensorType === 'SmallData' && pluginSettings[Constants.NORMALIZE_DATA].toLowerCase() === 'yes') {
let currValue = sensor.Value
let count = 2 //Start at 2 because Libre Hardware Monitor already reads these as MB at minimum - TODO: Check Open Hardware Monitor
while( currValue > 1024.0 ) {
currValue = currValue / 1024.0
count++
}
const unit = getUnit(count)
sensor.Value = currValue;
sensor.Unit = unit
console.log(JSON.stringify(sensor))
}
}

const getThroughputUnit = (count) => {
const getUnit = (count) => {
let unitScale = ""
switch(count) {
case 3: unitScale="G"; break;
case 2: unitScale="M"; break;
case 1: unitScale="K"; break;
}
return unitScale+"B/s"
return unitScale+"B";
}

const getThroughputUnit = (count) => {
return getUnit(count)+"/s"
}

const startCapture = () => {
Expand Down Expand Up @@ -136,7 +152,7 @@ const startCapture = () => {

runSensorConversions(sensor)

sensor.Value = parseFloat(sensor.Value).toFixed(1)
sensor.Value = sensor.Value % 1 !== 0 ? parseFloat(sensor.Value).toFixed(1) : sensor.Value

if( hardware[hardwareKey].Sensors[sensor.Identifier] == undefined ) {
sensor.StateId.defaultValue = sensor.Value;
Expand Down

0 comments on commit 4f7998d

Please sign in to comment.