device: Add simple temperature model for devices

This temperature model has three states:
 * COLD
 * WARM
 * HOT

Device drivers can define the time it requires for the device to get HOT
and COLD. The underlying model assumes an exponential warming and
cooling process and enforces a cool-off time after the device has
reached the HOT state. This cool down period is however shorter than the
specified time in the driver.
This commit is contained in:
Benjamin Berg
2021-04-21 17:16:03 +02:00
parent 96e5888110
commit a2d950044d
8 changed files with 243 additions and 0 deletions

View File

@@ -22,6 +22,23 @@
#include "fpi-device.h"
/* Chosen so that if we turn on after WARM -> COLD, it takes exactly one time
* constant to go from COLD -> HOT.
* TEMP_COLD_THRESH = 1 / (e + 1)
*/
#define TEMP_COLD_THRESH (0.26894142136999512075)
#define TEMP_WARM_HOT_THRESH (1.0 - TEMP_COLD_THRESH)
#define TEMP_HOT_WARM_THRESH (0.5)
/* Delay updates by 100ms to avoid hitting the border exactly */
#define TEMP_DELAY_SECONDS 0.1
/* Hopefully 3min is long enough to not get in the way, while also not
* properly overheating any devices.
*/
#define DEFAULT_TEMP_HOT_SECONDS (3 * 60)
#define DEFAULT_TEMP_COLD_SECONDS (9 * 60)
typedef struct
{
FpDeviceType type;
@@ -58,6 +75,15 @@ typedef struct
/* State for tasks */
gboolean wait_for_finger;
FpFingerStatusFlags finger_status;
/* Device temperature model information and state */
GSource *temp_timeout;
FpTemperature temp_current;
gint32 temp_hot_seconds;
gint32 temp_cold_seconds;
gint64 temp_last_update;
gboolean temp_last_active;
gdouble temp_current_ratio;
} FpDevicePrivate;
@@ -88,3 +114,6 @@ typedef struct
} FpMatchData;
void match_data_free (FpMatchData *match_data);
void fpi_device_update_temp (FpDevice *device,
gboolean is_active);