Browse Source

Add support for deleting sensor object from list

master
Frank Driessen 2 years ago
parent
commit
771d59506f
3 changed files with 29 additions and 4 deletions
  1. 3
    1
      src/mbpfanctl.c
  2. 22
    2
      src/sensors.c
  3. 4
    1
      src/sensors.h

+ 3
- 1
src/mbpfanctl.c View File

@@ -18,10 +18,12 @@
#include "global.h"
#include "sensors.h"

sensor_t *sensors;

int
main (int argc, char** argv)
{
init_sensors ();
sensors = init_sensors ();

return EXIT_SUCCESS;
}

+ 22
- 2
src/sensors.c View File

@@ -14,9 +14,9 @@ init_sensors (void)
char path[PATH_LENGTH];
FILE *fp;

for (int i = 0; i <= MAX_SENSORS; ++i)
for (int i = 1; i <= MAX_SENSORS; ++i)
{
sprintf (path, "%s/temp/%d_input", SENSOR_BASE_PATH, i);
sprintf (path, "%s/temp%d_input", SENSOR_BASE_PATH, i);
if (fp = fopen (path, "r"))
{
sensor_t *new = (sensor_t*) malloc (sizeof (sensor_t));
@@ -101,3 +101,23 @@ average_temp (sensor_t *sensor)

return temp / n;
}

/* Delete a Node from the list */
sensor_t*
delete_sensor (sensor_t **head, int id)
{
sensor_t **tmp = head;

while (*tmp && (**tmp).id != id)
tmp = &(*tmp)->next;

if (*tmp == NULL)
return NULL;

sensor_t *deleted = *tmp;
*tmp = deleted->next;
deleted->next = NULL;

return deleted;
}


+ 4
- 1
src/sensors.h View File

@@ -1,7 +1,7 @@
#ifndef _SENSORS_H_
#define _SENSORS_H_

#define SENSOR_BASE_PATH "/sys/class/hwmon/hwmon0"
#define SENSOR_BASE_PATH "/sys/class/hwmon/hwmon1"
#define MAX_SENSORS 10

/* Build a list of temperature sensors */
@@ -13,4 +13,7 @@ void update_sensors (sensor_t *sensor);
/* Average temperature reading across all sensors */
int average_temp (sensor_t *sensor);

/* Delete sensor node */
sensor_t* delete_sensor (sensor_t **head, int id);

#endif

Loading…
Cancel
Save