summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Gediminas Jakutis <gediminas@varciai.lt> 2018-04-27 10:04:26 +0300
committerGravatar Gediminas Jakutis <gediminas@varciai.lt> 2018-04-27 10:04:26 +0300
commit23d06a17f8a4033be57ca46079e5c3e65fa9e845 (patch)
tree7bfec5a9deedcc1e7de7c9ecd54ecf36020212c8 /src
parent884013b71ba9abd9ab0c9d0a8f90a769aff9b6a9 (diff)
downloadcoffeetemp-23d06a17f8a4033be57ca46079e5c3e65fa9e845.tar.gz
coffeetemp-23d06a17f8a4033be57ca46079e5c3e65fa9e845.tar.bz2
coffeetemp-23d06a17f8a4033be57ca46079e5c3e65fa9e845.zip
various minor improvements.
Diffstat (limited to 'src')
-rw-r--r--src/server/main.c23
-rw-r--r--src/server/net.c2
-rw-r--r--src/tempmodule/indicator.c9
-rw-r--r--src/tempmodule/indicator.h2
-rw-r--r--src/tempmodule/main.ino65
-rw-r--r--src/tempmodule/temperature.c2
-rw-r--r--src/tempmodule/temperature.h2
7 files changed, 80 insertions, 25 deletions
diff --git a/src/server/main.c b/src/server/main.c
index 1b36c2f..ec096c1 100644
--- a/src/server/main.c
+++ b/src/server/main.c
@@ -41,9 +41,9 @@ static float digest_temp(const short int rawdata);
int main(void)
{
struct netstate *state;
- char data[8] = {0};
+ char data[32] = {0};
int status;
- struct timespec wait = {0, 500 * 1000 * 1000};
+ struct timespec wait = {0, 100 * 1000 * 1000};
state = init(2191);
@@ -93,7 +93,13 @@ static void draw_idle(void)
mvprintw(1, 0, "thermistor temp: [waiting for ESP8266...]");
move(2, 0);
clrtoeol();
- mvprintw(2, 0, "press 'q' to exit");
+ mvprintw(2, 0, "thermistor resistance: [waiting for ESP8266...]");
+ move(3, 0);
+ clrtoeol();
+ mvprintw(3, 0, "tap voltage: [waiting for ESP8266...]");
+ move(4, 0);
+ clrtoeol();
+ mvprintw(4, 0, "press 'q' to exit");
refresh();
}
@@ -101,11 +107,14 @@ static void draw_busy(const char * const data)
{
unsigned int sequence;
short int thermistor_data;
+ short int voltage;
float temp;
memcpy(&sequence, data + 2, sizeof(sequence));
memcpy(&thermistor_data, data + 6, sizeof(thermistor_data));
temp = digest_temp(thermistor_data);
+ memcpy(&thermistor_data, data + 10, sizeof(thermistor_data));
+ memcpy(&voltage, data + 12, sizeof(voltage));
move(0, 0);
clrtoeol();
@@ -115,7 +124,13 @@ static void draw_busy(const char * const data)
mvprintw(1, 0, "thermistor temp: %.1fC", temp);
move(2, 0);
clrtoeol();
- mvprintw(2, 0, "press 'q' to exit");
+ mvprintw(2, 0, "thermistor resistance: %hd", thermistor_data);
+ move(3, 0);
+ clrtoeol();
+ mvprintw(3, 0, "tap voltage: %hd", voltage);
+ move(4, 0);
+ clrtoeol();
+ mvprintw(4, 0, "press 'q' to exit");
refresh();
}
diff --git a/src/server/net.c b/src/server/net.c
index cecf10c..5441be4 100644
--- a/src/server/net.c
+++ b/src/server/net.c
@@ -95,7 +95,7 @@ static int dolisten(char * const data, struct netstate_internal * const state)
ret = NET_NONEWDATA; /* consume packet and lie about it */
continue;
} else {
- memcpy(data, buff, 8ul);
+ memcpy(data, buff, 14);
}
break;
default:
diff --git a/src/tempmodule/indicator.c b/src/tempmodule/indicator.c
index 774c801..4c1b958 100644
--- a/src/tempmodule/indicator.c
+++ b/src/tempmodule/indicator.c
@@ -57,8 +57,13 @@ void indicator_init(unsigned int temp, unsigned int const * const calibration)
}
-void indicator_update(unsigned int temp)
+void indicator_update(const unsigned int temp, const unsigned int on)
{
+ if (!on) {
+ indicator_set_state(0, 0, 0);
+ return;
+ }
+
if (temp > state.calibration[0]) {
indicator_set_state(1, 0, 0);
} else if (temp > state.calibration[1]) {
@@ -75,7 +80,7 @@ void indicator_update(unsigned int temp)
void indicator_calibrate(unsigned int const * const calibration)
{
memcpy(state.calibration, calibration, sizeof(state.calibration));
- indicator_update(state.current_temp);
+ indicator_update(state.current_temp, 1);
}
static void indicator_set_state(unsigned int red, unsigned int green, unsigned int blue)
diff --git a/src/tempmodule/indicator.h b/src/tempmodule/indicator.h
index db7bcce..d44b7fe 100644
--- a/src/tempmodule/indicator.h
+++ b/src/tempmodule/indicator.h
@@ -26,7 +26,7 @@ extern "C" {
#endif
void indicator_init(unsigned int temp, unsigned int const * const calibration);
-void indicator_update(unsigned int temp);
+void indicator_update(const unsigned int temp, const unsigned int on);
void indicator_calibrate(unsigned int const * const calibration);
#ifdef __cplusplus
diff --git a/src/tempmodule/main.ino b/src/tempmodule/main.ino
index 6057b66..58e3dfc 100644
--- a/src/tempmodule/main.ino
+++ b/src/tempmodule/main.ino
@@ -26,15 +26,16 @@
#include "indicator.h"
#include "temperature.h"
-static const unsigned int iled = 2; /* D4 */
-static const unsigned int wifiled = 12; /* D6 */
-static const unsigned int wifibutton = 13; /* D7 */
+static const unsigned int iled = 2; /* D4 */
+static const unsigned int wifiled = 12; /* D6 */
+static const unsigned int wifibutton = 15; /* D8 */
+static const unsigned int thermistorvcc = 13; /* D7 */
static const unsigned int analog = A0;
static volatile unsigned int wifidesired = 0;
static unsigned int wifistate = 0;
static unsigned int wifiledstate = 0;
static const int port = 2191;
-static const int splitter_res = 9900;
+static const int splitter_res = 4680;
static char udppacketbuffer[32] = {0};
static char *udppacketcursor = NULL;
IPAddress ip;
@@ -47,6 +48,7 @@ static int wifi_connect(const char * const ssid, const char * const password, co
static void wifi_disconnect(void);
static void blink_led(const int pin, const int ontime, const int offtime);
static void discover_client(void);
+static void get_data(short int * const data);
void toggle_wifi(void);
void wifiled_toggle(void);
@@ -54,10 +56,28 @@ void setup(void)
{
pinMode(iled, OUTPUT);
digitalWrite(iled, HIGH);
+
pinMode(wifiled, OUTPUT);
+ digitalWrite(wifiled, LOW);
+
pinMode(wifibutton, INPUT);
+
+ pinMode(thermistorvcc, OUTPUT);
+ digitalWrite(thermistorvcc, LOW);
+
indicator_init(0, NULL);
+
WiFi.forceSleepBegin();
+ indicator_update(3450, 1);
+ delay(1000);
+ indicator_update(3350, 1);
+ delay(1000);
+ indicator_update(3250, 1);
+ delay(1000);
+ indicator_update(3150, 1);
+ delay(1000);
+ indicator_update(3050, 1);
+ delay(1000);
attachInterrupt(digitalPinToInterrupt(wifibutton), toggle_wifi, RISING);
}
@@ -66,7 +86,7 @@ void loop(void)
static const char * const ssid = "SSID";
static const char * const password = "password";
static unsigned int ticker = 0;
- short int data;
+ short int data[3];
size_t i;
udp_init_packet(ip, port);
@@ -78,30 +98,28 @@ void loop(void)
}
}
- if (!wifidesired && wifistate) {
+ if (!wifidesired) {
wifi_disconnect();
}
if (wifistate) {
- data = 0;
- udp_push(&data, sizeof(data));
+ data[0] = 0;
+ udp_push(data, sizeof(data[0]));
udp_push(&ticker, sizeof(ticker));
}
- data = analogRead(analog);
- data = get_temperature(get_resistance(data, splitter_res));
+ get_data(data);
if (wifistate) {
- udp_push(&data, sizeof(data));
-
+ udp_push(data, sizeof(data));
/* if flushing fails, disconnect WiFi */
if (!(udp_flush())) {
wifidesired = 0;
}
}
- indicator_update(data);
- delay(1000);
+ indicator_update(data[0], 1);
+ delay(245);
++ticker;
}
@@ -126,6 +144,9 @@ static int udp_flush(void)
static int wifi_connect(const char * const ssid, const char * const password, const char doblink, const int ledpin)
{
+ if (wifistate) {
+ return 1;
+ }
wifiled_toggle();
WiFi.forceSleepWake();
@@ -150,6 +171,10 @@ static int wifi_connect(const char * const ssid, const char * const password, co
static void wifi_disconnect(void)
{
+ if (!wifistate) {
+ return;
+ }
+
wifiled_toggle();
Udp.stop();
WiFi.disconnect(1);
@@ -191,9 +216,19 @@ static void discover_client(void)
} while (!done);
}
+static void get_data(short int * const data)
+{
+ digitalWrite(thermistorvcc, HIGH);
+ delay(5); /* make sure the voltage settles down */
+ data[2] = analogRead(analog);
+ digitalWrite(thermistorvcc, LOW);
+ data[1] = get_resistance(data[2], splitter_res);
+ data[0] = get_temperature(data[1]);
+}
+
void toggle_wifi(void)
{
- static const unsigned int timeout = 2000000; /* 2 seconds */
+ static const unsigned int timeout = 2 * 1000 * 1000; /* 2 seconds */
static volatile unsigned int lastswitch;
volatile unsigned int switchtime;
diff --git a/src/tempmodule/temperature.c b/src/tempmodule/temperature.c
index 684f654..c95807b 100644
--- a/src/tempmodule/temperature.c
+++ b/src/tempmodule/temperature.c
@@ -81,7 +81,7 @@ int get_temperature(int res)
}
/* Returns the last 0-10 part of the temperature, in 0.1°K. */
-int get_temp_subrange(short a, short b, int res)
+int get_temp_subrange(int a, int b, int res)
{
return (res - a) * 100 / (b - a);
}
diff --git a/src/tempmodule/temperature.h b/src/tempmodule/temperature.h
index 2882514..1f7e33e 100644
--- a/src/tempmodule/temperature.h
+++ b/src/tempmodule/temperature.h
@@ -27,7 +27,7 @@ extern "C" {
int get_resistance(int vt, int ra);
int get_temperature(int res);
-int get_temp_subrange(short a, short b, int res);
+int get_temp_subrange(int a, int b, int res);
#ifdef __cplusplus
}