aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--LICENSE2
-rw-r--r--src/temperature.c16
-rw-r--r--src/temperature.h2
4 files changed, 13 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
index 0e2f1ed..a61f635 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,3 @@
.ccls
a.out
out/
-*.zip
-fp-info-cache
-*.lck
diff --git a/LICENSE b/LICENSE
index 713d8cf..a6b6a02 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2024 Akshay Nair
+Copyright (c) 2026 Akshay Nair
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/src/temperature.c b/src/temperature.c
index b804fc9..72e4875 100644
--- a/src/temperature.c
+++ b/src/temperature.c
@@ -37,13 +37,17 @@ uint16_t spi_read16(void) {
float temperature_read(void) {
THERMO_PORT &= ~(1 << THERMO_CS);
- uint16_t v = spi_read16();
+ uint16_t out = spi_read16();
THERMO_PORT |= (1 << THERMO_CS);
- // invalid temp
- if (v & 0x4)
- return 999.9;
+ // thermocouple open (invalid read) D2 bit
+ if (out & 0b100)
+ return 0.0;
- v >>= 3;
- return v * 0.25;
+ out >>= 3; // Skip D0,D1,D2
+
+ float temperature = out * THERMO_RESOLUTION;
+ if (temperature > 100)
+ temperature *= 1.05;
+ return temperature;
}
diff --git a/src/temperature.h b/src/temperature.h
index 31fa92a..c15fe22 100644
--- a/src/temperature.h
+++ b/src/temperature.h
@@ -4,6 +4,8 @@
#define THERMO_PORT PORTA
#define THERMO_DDR DDRA
+#define THERMO_RESOLUTION 0.25
+
#define SPI_DELAY_US 10
void temperature_init(void);