Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for 413d:2107 TEMPerGold_V3.1 #53

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions libtempered/temper_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "type_hid/sht1x.h"
#include "type_hid/ntc.h"
#include "type_hid/si7005.h"
#include "type_hid/simple.h"

// This is an array of known TEMPer types.
struct temper_type known_temper_types[]={
Expand Down Expand Up @@ -407,6 +408,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
};

Expand Down
30 changes: 30 additions & 0 deletions libtempered/type_hid/simple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdbool.h>
#include <string.h>

#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;
}
13 changes: 13 additions & 0 deletions libtempered/type_hid/simple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef TEMPERED__TYPE_HID__SIMPLE_H
#define TEMPERED__TYPE_HID__SIMPLE_H

#include <stdbool.h>

#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