Skip to content

Commit

Permalink
Merge pull request #6 from mwerezak/weber-software-master
Browse files Browse the repository at this point in the history
Added support for 413d:2107 TEMPerGold_V3.1
  • Loading branch information
mwerezak authored Dec 29, 2022
2 parents b71c6c3 + 357427d commit afe902d
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
80 changes: 80 additions & 0 deletions libtempered/temper_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[]={
Expand Down Expand Up @@ -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
};

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

0 comments on commit afe902d

Please sign in to comment.