Hardware/RAM/GenericRAM.cs
author moel.mich
Mon, 23 Jul 2012 21:54:35 +0000
changeset 370 8e4dedc41924
child 372 2de3a3e5f0b5
permissions -rw-r--r--
Added a RAM hardware and sensor, fixed Issue 115.
moel@370
     1
/*
moel@370
     2
 
moel@370
     3
  This Source Code Form is subject to the terms of the Mozilla Public
moel@370
     4
  License, v. 2.0. If a copy of the MPL was not distributed with this
moel@370
     5
  file, You can obtain one at http://mozilla.org/MPL/2.0/.
moel@370
     6
 
moel@370
     7
  Copyright (C) 2012 Michael Möller <mmoeller@openhardwaremonitor.org>
moel@370
     8
	
moel@370
     9
*/
moel@370
    10
moel@370
    11
using Microsoft.VisualBasic.Devices;
moel@370
    12
moel@370
    13
namespace OpenHardwareMonitor.Hardware.RAM {
moel@370
    14
  internal class GenericRAM : Hardware {
moel@370
    15
moel@370
    16
    private Sensor loadSensor;
moel@370
    17
    private Sensor availableMemory;
moel@370
    18
moel@370
    19
    private ComputerInfo computerInfo;
moel@370
    20
moel@370
    21
    public GenericRAM(string name, ISettings settings)
moel@370
    22
      : base(name, new Identifier("ram"), settings)
moel@370
    23
    {   
moel@370
    24
      computerInfo = new ComputerInfo();
moel@370
    25
      loadSensor = new Sensor("Memory", 0, SensorType.Load, this, settings);
moel@370
    26
      ActivateSensor(loadSensor);
moel@370
    27
moel@370
    28
      availableMemory = new Sensor("Available Memory", 0, SensorType.Data, this, settings);
moel@370
    29
      ActivateSensor(availableMemory);
moel@370
    30
    }
moel@370
    31
moel@370
    32
    public override HardwareType HardwareType {
moel@370
    33
      get {
moel@370
    34
        return HardwareType.RAM;
moel@370
    35
      }
moel@370
    36
    }
moel@370
    37
moel@370
    38
    public override void Update() {
moel@370
    39
      loadSensor.Value = 100.0f - 
moel@370
    40
        (100.0f * computerInfo.AvailablePhysicalMemory) / 
moel@370
    41
        computerInfo.TotalPhysicalMemory;
moel@370
    42
moel@370
    43
      availableMemory.Value = (float)computerInfo.AvailablePhysicalMemory /
moel@370
    44
        (1024 * 1024 * 1024);
moel@370
    45
    }
moel@370
    46
  }
moel@370
    47
}