diff --git a/libtempered/temper_type.c b/libtempered/temper_type.c index 5cef273..7bbe47e 100644 --- a/libtempered/temper_type.c +++ b/libtempered/temper_type.c @@ -11,6 +11,7 @@ #include "type_hid/ntc.h" #include "type_hid/si7005.h" #include "type_hid/si7021.h" +#include "type_hid/simple.h" // This is an array of known TEMPer types. struct temper_type known_temper_types[]={ @@ -472,6 +473,85 @@ struct temper_type known_temper_types[]={ NULL // List terminator for subtypes } }, + { + .name="TEMPer2V3.1 or TEMPer2V3.3", + .vendor_id=0x413d, + .product_id=0x2107, + .interface_number=1, + .open = tempered_type_hid_open, + .close = tempered_type_hid_close, + .get_subtype_id = tempered_type_hid_get_subtype_id_from_string, + .get_subtype_data = &(struct tempered_type_hid_subtype_from_string_data) + { + .query = { + .length = 9, + .data = (unsigned char[]){ 0, 1, 0x86, 0xFF, 1, 0, 0, 0, 0 } + }, + .response_count = 2, + .subtype_strings = (char *[]){ + "TEMPerGold_V3.1 ", + "TEMPerX_V3.3 ", + NULL + } + }, + .subtypes = (struct temper_subtype*[]){ + (struct temper_subtype*)&(struct temper_subtype_hid){ + .base = { + .id = 0, + .name = "TEMPerGold_V3.1", + .open = tempered_type_hid_subtype_open, + .read_sensors = tempered_type_hid_read_sensors, + .get_temperature = tempered_type_hid_get_temperature + }, + .sensor_group_count = 1, + .sensor_groups = (struct tempered_type_hid_sensor_group[]){ + { + .query = { + .length = 9, + .data = (unsigned char[]){ 0, 1, 0x80, 0x33, 1, 0, 0, 0, 0 } + }, + .read_sensors = tempered_type_hid_read_sensor_group, + .sensor_count = 1, + .sensors = (struct tempered_type_hid_sensor[]){ + { + .get_temperature = tempered_type_hid_get_temperature_simple, + .temperature_high_byte_offset = 2, + .temperature_low_byte_offset = 3 + } + } + } + } + }, + (struct temper_subtype*)&(struct temper_subtype_hid){ + .base = { + .id = 1, + .name = "TEMPerX_V3.3", + .open = tempered_type_hid_subtype_open, + .read_sensors = tempered_type_hid_read_sensors, + .get_temperature = tempered_type_hid_get_temperature + }, + .sensor_group_count = 1, + .sensor_groups = (struct tempered_type_hid_sensor_group[]){ + { + .query = { + .length = 9, + .data = (unsigned char[]){ 0, 1, 0x80, 0x33, 1, 0, 0, 0, 0 } + }, + .read_sensors = tempered_type_hid_read_sensor_group, + .sensor_count = 1, + .sensors = (struct tempered_type_hid_sensor[]){ + { + .get_temperature = tempered_type_hid_get_temperature_simple, + .temperature_high_byte_offset = 2, + .temperature_low_byte_offset = 3 + } + } + } + } + }, + NULL // List terminator for subtypes + } + }, { .name=NULL } // List terminator for temper types }; diff --git a/libtempered/type_hid/simple.c b/libtempered/type_hid/simple.c new file mode 100644 index 0000000..7620660 --- /dev/null +++ b/libtempered/type_hid/simple.c @@ -0,0 +1,30 @@ +#include +#include + +#include "type-info.h" +#include "../tempered-internal.h" + +bool tempered_type_hid_get_temperature_simple( + tempered_device *device, struct tempered_type_hid_sensor *sensor, + struct tempered_type_hid_query_result *group_data, float *tempC +) { + if ( + group_data->length <= sensor->temperature_high_byte_offset || + group_data->length <= sensor->temperature_low_byte_offset + ) { + tempered_set_error( + device, strdup( "Not enough data was read from the sensor." ) + ); + return false; + } + + int low_byte_offset = sensor->temperature_low_byte_offset; + int high_byte_offset = sensor->temperature_high_byte_offset; + int temp = ( group_data->data[low_byte_offset] & 0xFF ) + + ( (signed char)group_data->data[high_byte_offset] << 8 ) + ; + + *tempC = temp / 100.0; + + return true; +} diff --git a/libtempered/type_hid/simple.h b/libtempered/type_hid/simple.h new file mode 100644 index 0000000..7d0b5ad --- /dev/null +++ b/libtempered/type_hid/simple.h @@ -0,0 +1,13 @@ +#ifndef TEMPERED__TYPE_HID__SIMPLE_H +#define TEMPERED__TYPE_HID__SIMPLE_H + +#include + +#include "type-info.h" + +bool tempered_type_hid_get_temperature_simple( + tempered_device *device, struct tempered_type_hid_sensor *sensor, + struct tempered_type_hid_query_result *group_data, float *tempC +); + +#endif