/*
 * GNOME lm_sensors panel applet
 * (C) 1999 The Free Software Foundation
 *
 * Author: Fabrice Bellet <Fabrice.Bellet@imag.fr>
 *         adapted from wmlm (by ben jarvis<bjarvis@bresnanlink.net>)
 *
 *
 */

#include <sensors/sensors.h>
#include <sensors/chips.h>
#include <sensors/error.h>
#include <gnome.h>
#include <applet-widget.h>

#undef DEBUG
#define LM_VERSION "0.3"
/* Nice value to avoid eating CPU when it is needed */
#define NICE_VALUE 5
#define TEMP_HISTORY_SIZE 39
#define	EPSILON 1e-6

enum { CELCIUS, FAHRENHEIT, KELVIN };
enum {
	LM75,
	LM78,
	LM78J,
	LM79,
	LM80,
	W83781D,
	W83782D,
	W83783S
};

enum { MB_TEMP, CPU_TEMP };

typedef struct _LmSensorsData LmSensorsData;
struct _LmSensorsData {
	const sensors_chip_name *name;
	gshort chiptype;
	gshort fan_number;
	gshort temp_number;
};

typedef struct _LmSensorsApplet LmSensorsApplet;
struct _LmSensorsApplet {
	/* Applet */
	GtkWidget *applet;
	GtkWidget *darea;
	GtkWidget *pbox;
	GtkWidget *timeout_spin;
	GtkWidget *temp_curve_ll_spin;
	GtkWidget *temp_curve_ul_spin;
	GtkAdjustment *temp_curve_ll_adj;
	GtkAdjustment *temp_curve_ul_adj;
	guint timeout_handler_id;
	GdkPixmap *lm_master;
	GdkBitmap *lm_mask;

	/* Properties */
	gint temp_unit;
	gint fan_number;
	gint temp1_number;
	gint temp2_number;
	gint temp1_type;
	gint temp2_type;
	gint update_timeout;
	gdouble temp_curve_ll;
	gdouble temp_curve_ul;
	gboolean display_temp_curves;
	gboolean use_adaptive_limits;
	gboolean reset_adaptive_limits;
	gboolean changing_unit;

	gint p_temp_unit;
	gint p_fan_number;
	gint p_temp1_number;
	gint p_temp2_number;
	gboolean p_temp1_type;
	gboolean p_temp2_type;
	gint p_update_timeout;
	gdouble p_temp_curve_ll;
	gdouble p_temp_curve_ul;
	gboolean p_display_temp_curves;
	gboolean p_use_adaptive_limits;

	/* Sensor */
	LmSensorsData chip;
	gdouble in_ll[7],in_ul[7];
	gdouble fan_ll[3],fan_ul[3];
	gdouble temp_ll[3],temp_ul[3];

	gdouble in[7];
	gdouble fan[3];
	gdouble temp[3];

	gdouble temp_history[2][TEMP_HISTORY_SIZE];
	gint	temp_history_nb;
	gint	temp_history_idx;
};

/*
 * forward declarations to keep the compiler happy
 */
inline void copy_xpm_area (gint,gint,gint,gint,gint,gint,LmSensorsApplet *);
gint sensors_update (LmSensorsApplet *);
void sensors_config (LmSensorsApplet *);
void frame_update (LmSensorsApplet *);
void create_pixmap (LmSensorsApplet *);
void update_pixmap (LmSensorsApplet *);
gdouble temp_convert (gdouble, gint);
gdouble invert_temp_convert (gdouble, gint);
