summaryrefslogtreecommitdiff
path: root/temper.c
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2018-07-05 13:22:43 +0100
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2018-07-05 13:22:43 +0100
commit7b7086a2ad996daa8cabe44af5a2a7f88d893f60 (patch)
treef710b5fa83ca7adf7556cdfdd1f7366a65ae337f /temper.c
parent03e566b26dca57c73b08966cf56e73348b481efe (diff)
downloadtemper-7b7086a2ad996daa8cabe44af5a2a7f88d893f60.tar.bz2
Temper reader
Diffstat (limited to 'temper.c')
-rw-r--r--temper.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/temper.c b/temper.c
new file mode 100644
index 0000000..9662cbf
--- /dev/null
+++ b/temper.c
@@ -0,0 +1,79 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <hidapi.h>
+
+uint8_t cmd[] = {0x00, 0x01, 0x80, 0x33, 0x01, 0x00, 0x00, 0x00, 0x00};
+
+hid_device *find_hid(uint16_t vid, uint16_t pid, uint16_t iface)
+{
+ struct hid_device_info *list = hid_enumerate(vid, pid);
+ struct hid_device_info *p = list;
+ hid_device *ret = NULL;
+ while (p != NULL)
+ {
+ if (p->interface_number == iface)
+ {
+ ret = hid_open_path(p->path);
+ }
+ p = p->next;
+ }
+ if (list != NULL)
+ hid_free_enumeration(list);
+ return ret;
+}
+
+int main(int argc, char **argv)
+{
+ int res;
+ int retcode = EXIT_FAILURE;
+ uint8_t buf[1024];
+ hid_device *temper;
+
+ res = hid_init();
+
+ temper = find_hid(0x413d, 0x2107, 1);
+
+ if (temper == NULL)
+ {
+ fprintf(stderr, "Unable to open temper device\n");
+ goto close_out;
+ }
+
+ res = hid_write(temper, cmd, 9);
+ if (res != 9)
+ {
+ fprintf(stderr, "Unable to write command to temper\n");
+ goto close_out;
+ }
+
+ res = hid_read_timeout(temper, &buf[0], 1024, 1000);
+ if (res < 0)
+ {
+ fprintf(stderr, "Failure reading from temper\n");
+ goto close_out;
+ }
+ if (res == 0)
+ {
+ fprintf(stderr, "Unable to read from temper, no response\n");
+ goto close_out;
+ }
+
+ if (res < 6)
+ {
+ fprintf(stderr, "Read too few bytes from temper: %d\n", res);
+ goto close_out;
+ }
+
+ float temp = (((float)buf[2]) * 256.0) + ((float)buf[3]);
+ temp = temp / 100;
+
+ printf("%.2f\n", temp);
+
+ retcode = EXIT_SUCCESS;
+close_out:
+ hid_close(temper);
+
+ return retcode;
+} \ No newline at end of file