annotate tempctrl.c @ 31:03592ca4d37e

Port tempctrl.c from AVR. I removed the beep code as I don't have a beeper on the STM32 board. Reworked the heat/cool stuff so it can use separate ports.
author Daniel O'Connor <darius@dons.net.au>
date Tue, 27 Nov 2012 13:20:52 +1030
parents
children d3b7d4964807
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 /*
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2 * Temperature control logic, copied from AVR version
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 *
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 * Copyright (c) 2012
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 * Daniel O'Connor <darius@dons.net.au>. All rights reserved.
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 *
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 * Redistribution and use in source and binary forms, with or without
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 * modification, are permitted provided that the following conditions
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 * are met:
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10 * 1. Redistributions of source code must retain the above copyright
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer.
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 *
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 * SUCH DAMAGE.
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27 */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 #include <assert.h>
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30 #include <stdio.h>
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 #include <stdint.h>
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32 #include <stdlib.h>
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33 #include <string.h>
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 #include <sys/time.h>
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 #include <time.h>
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36 #include "stm32f10x.h"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38 #include "1wire.h"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39 #include "flash.h"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40 #include "tempctrl.h"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42 /* Holds all the settings needed */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
43 typedef struct {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 uint8_t fermenter_ROM[8];
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
45 uint8_t fridge_ROM[8];
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
46 uint8_t ambient_ROM[8];
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
47 int16_t target_temp;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
48 uint16_t hysteresis;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
49 /* How much to under/overshoot on heating/cooling */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
50 int16_t minheatovershoot;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
51 int16_t mincoolovershoot;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 /* Minimum time the cooler can be on/off */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
54 int16_t mincoolontime;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
55 int16_t mincoolofftime;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
57 /* Minimum time the heater can be on/off */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
58 int16_t minheatontime;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
59 int16_t minheatofftime;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
60
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
61 #define TC_MODE_AUTO 'a' /* Automatic control */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62 #define TC_MODE_HEAT 'h' /* Force heating */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
63 #define TC_MODE_COOL 'c' /* Force cooling */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
64 #define TC_MODE_IDLE 'i' /* Force idle */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65 #define TC_MODE_NOTHING 'n' /* Do nothing (like idle but log nothing) */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
66 char mode;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
67
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
68 /* GPIO port the heater & cooler are on */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
69 GPIO_TypeDef *coolport;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70 uint16_t coolpin;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
72 GPIO_TypeDef *heatport;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
73 uint16_t heatpin;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
74
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75 /* Check/stale times */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
76 int16_t check_interval;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77 int16_t stale_factor;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
78
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
79 uint8_t pad[3]; /* Pad to multiple of 4 bytes */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80 } settings_t;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82 /* Current settings in RAM */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83 static settings_t settings;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85 /* Defaults that are shoved into SPI flash if it isn't inited */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86 const settings_t default_settings = {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
87 .fermenter_ROM = { 0x10, 0x4c, 0x7d, 0x53, 0x01, 0x08, 0x00, 0xff },
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
88 .fridge_ROM = { 0x10, 0x6d, 0x40, 0x53, 0x01, 0x08, 0x00, 0x16 },
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
89 .ambient_ROM = { 0x10, 0x76, 0x05, 0x53, 0x01, 0x08, 0x00, 0x8e },
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
90 .target_temp = 1000,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
91 .hysteresis = 100,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92 .minheatovershoot = 50,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
93 .mincoolovershoot = -50,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94 .mincoolontime = 300,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95 .mincoolofftime = 600,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
96 .minheatontime = 60,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
97 .minheatofftime = 60,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
98 .mode = TC_MODE_AUTO,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
99 .coolport = GPIOE,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
100 .coolpin = GPIO_Pin_4,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
101 .heatport = GPIOE,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
102 .heatpin = GPIO_Pin_5,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
103 .check_interval = 10,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
104 .stale_factor = 3,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105 };
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
106
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
107 /* Local variable declarations */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
108
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
109 /* Local function prototypes */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
110 static void tempctrl_load_or_init_settings(void);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
111 static void tempctrl_default_settings(void);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
112 static void tempctrl_write_settings(void);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
113 static void setstate(char state);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
114 static const char * state2long(char s);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
115 static void printtemp(const char *name, int tmp, const char *trailer);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
116
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
117 /*
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
118 * tempctrl_init
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
119 *
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
120 */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
121 void
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
122 tempctrl_init(void) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
123 tempctrl_load_or_init_settings();
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
124 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
125
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
126 /*
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
127 * tempctrl_update
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
128 *
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
129 * Should be called in a normal context, could run things that take a long time.
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
130 * (ie 1wire bus stuff)
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
131 *
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
132 */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
133 void
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
134 tempctrl_update(void) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
135 /* State variables */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
136 static int32_t checktime = 0; // Time of next check
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
137 static int32_t lastdata = INT32_MIN; // Last time we got data
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
138
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
139 static int16_t fermenter_temp = 0; // Fermenter temperature
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
140 static int16_t fridge_temp = 0; // Fridge temperature
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
141 static int16_t ambient_temp = 0; // Ambient temperature
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
142 static int32_t lastheaton = INT32_MIN; // Last time the heater was on
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
143 static int32_t lastheatoff = INT32_MIN;// Last time the heater was off
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
144 static int32_t lastcoolon = INT32_MIN; // Last time the cooler was on
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
145 static int32_t lastcooloff = INT32_MIN;// Last time the cooler was off
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
146 static char currstate = 'i'; // Current state
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
147 /* We init to times to INT32_MIN so that things function properly when
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
148 * now < settings.minheat/cool/on/offtime */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
149
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
150 /* Temporary variables */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
151 int32_t tempt;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
152 int16_t diff;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
153 char nextstate;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
154 int forced;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
155 int stale;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
156 time_t t;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
157 struct tm tm;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
158 char buf[23];
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
159
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
160 t = time(NULL);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
161
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
162 /* Time to check temperatures? */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
163 if (t < checktime)
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
164 return;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
165
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
166 checktime = t + settings.check_interval;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
167
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
168 /* Don't do any logging, just force idle and leave */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
169 if (settings.mode == TC_MODE_NOTHING) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
170 nextstate = 'i';
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
171 goto setstate;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
172 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
173
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
174 /* Update our temperatures
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
175 * Can take a while (800ms each!)
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
176 */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
177 tempt = OWGetTemp(settings.fermenter_ROM);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
178 fridge_temp = OWGetTemp(settings.fridge_ROM);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
179 ambient_temp = OWGetTemp(settings.ambient_ROM);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
180
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
181 /* We only care about this one, only update the value we decide on
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
182 * only if it is valid
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
183 */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
184 if (tempt > OW_TEMP_BADVAL) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
185 fermenter_temp = tempt;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
186 lastdata = t;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
187 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
188
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
189 /* Check for stale data */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
190 if (lastdata + (settings.check_interval * settings.stale_factor) < t)
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
191 stale = 1;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
192 else
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
193 stale = 0;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
194
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
195 /* Default to remaining as we are */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
196 nextstate = '-';
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
197
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
198 /* Temperature diff, -ve => too cold, +ve => too warm */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
199 diff = fermenter_temp - settings.target_temp;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
200
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
201 switch (currstate) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
202 case 'i':
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
203 /* If we're idle then only heat or cool if the temperate difference is out of the
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
204 * hysteresis band
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
205 */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
206 if (abs(diff) > settings.hysteresis) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
207 if (diff < 0 && settings.minheatofftime + lastheatoff < t)
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
208 nextstate = 'h';
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
209 else if (diff > 0 && settings.mincoolofftime + lastcooloff < t)
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
210 nextstate = 'c';
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
211 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
212 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
213
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
214 case 'c':
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
215 /* Work out if we should go idle (based on min on time & overshoot) */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
216 if (diff + settings.mincoolovershoot < 0 &&
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
217 settings.mincoolontime + lastcoolon < t)
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
218 nextstate = 'i';
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
219 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
220
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
221 case 'h':
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
222 if (diff - settings.minheatovershoot > 0 &&
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
223 settings.minheatontime + lastheaton < t)
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
224 nextstate = 'i';
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
225 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
226
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
227 default:
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
228 printf("\r\nUnknown state %c, going to idle\n", currstate);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
229 nextstate = 'i';
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
230 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
231 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
232
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
233 /* Override if we have stale data */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
234 if (stale)
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
235 nextstate = 'i';
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
236
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
237 /* Handle state forcing */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
238 if (settings.mode != TC_MODE_AUTO)
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
239 forced = 1;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
240 else
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
241 forced = 0;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
242
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
243 if (settings.mode == TC_MODE_IDLE)
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
244 nextstate = 'i';
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
245 else if (settings.mode == TC_MODE_HEAT)
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
246 nextstate = 'h';
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
247 else if (settings.mode == TC_MODE_COOL)
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
248 nextstate = 'c';
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
249
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
250 // Keep track of when we last turned things on or off
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
251 switch (nextstate) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
252 case 'c':
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
253 if (currstate == 'h')
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
254 lastheatoff = t;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
255 lastcoolon = t;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
256 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
257
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
258 case 'h':
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
259 if (currstate == 'c')
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
260 lastcooloff = t;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
261 lastheaton = t;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
262 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
263
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
264 default:
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
265 if (currstate == 'c')
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
266 lastcooloff = t;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
267 if (currstate == 'h')
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
268 lastheatoff = t;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
269 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
270
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
271 if (nextstate != '-')
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
272 currstate = nextstate;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
273
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
274
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
275 gmtime_r(&t, &tm);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
276 assert(strftime(buf, sizeof(buf) - 1, "%Y/%m/%d %H:%M:%S: ", &tm) != 0);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
277 fputs(buf, stdout);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
278 printtemp("Tr", settings.target_temp, ", ");
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
279 printtemp("Fm", tempt, ", "); // Use actual value from sensor
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
280 printtemp("Fr", fridge_temp, ", ");
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
281 printtemp("Am", ambient_temp, ", ");
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
282 printf("St: %s, Fl: %s%s\r\n", state2long(currstate),
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
283 forced ? "F" : "",
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
284 stale ? "S" : "");
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
285
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
286 setstate:
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
287 setstate(currstate);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
288 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
289
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
290 /*
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
291 * Print out temperature (or short error code) with specified trailer
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
292 */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
293 static void
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
294 printtemp(const char *name, int tmp, const char *trailer) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
295 if (tmp > OW_TEMP_BADVAL)
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
296 printf("%s: %d.%02d%s", name, GETWHOLE(tmp), GETFRAC(tmp), trailer);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
297 else
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
298 printf("%s: %s%s", name, OWTempStatusStr(tmp, 1), trailer);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
299 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
300
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
301 /* Read the settings from SPI flash
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
302 * If the CRC fails then reload from onboard flash
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
303 */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
304 static void
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
305 tempctrl_load_or_init_settings(void) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
306 /* XXX: todo */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
307 if (!flashreadblock(0, sizeof(settings), &settings)) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
308 fputs("CRC fails, loading defaults\r\n", stdout);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
309 tempctrl_default_settings();
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
310 tempctrl_write_settings();
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
311 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
312 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
313
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
314 /* Load in the defaults from flash */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
315 static void
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
316 tempctrl_default_settings(void) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
317 memcpy(&settings, &default_settings, sizeof(settings_t));
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
318 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
319
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
320 /* Write the current settings out to SPI flash */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
321 static void
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
322 tempctrl_write_settings(void) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
323 flashwriteblock(0, sizeof(settings), &settings);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
324 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
325
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
326 /* Set the relays to match the desired state */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
327 static void
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
328 setstate(char state) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
329 switch (state) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
330 case 'c':
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
331 GPIO_ResetBits(settings.heatport, settings.heatpin);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
332 GPIO_SetBits(settings.coolport, settings.coolpin);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
333 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
334
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
335 case 'h':
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
336 GPIO_ResetBits(settings.coolport, settings.coolpin);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
337 GPIO_SetBits(settings.heatport, settings.heatpin);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
338 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
339
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
340 default:
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
341 printf("Unknown state %c, setting idle\r\n", state);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
342 /* fallthrough */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
343
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
344 case 'i':
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
345 GPIO_ResetBits(settings.coolport, settings.coolpin);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
346 GPIO_ResetBits(settings.heatport, settings.heatpin);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
347 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
348 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
349 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
350
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
351 /* Handle user command
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
352 *
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
353 */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
354 void
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
355 tempctrl_cmd(int argc, char **argv) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
356 int16_t data;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
357 uint8_t ROM[8];
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
358
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
359 if (argc < 1) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
360 printf("Unable to parse tc subcommand\r\n");
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
361 return;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
362 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
363
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
364 if (!strcasecmp(argv[0], "help")) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
365 printf("tc help This help\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
366 "tc save Save settings to EEPROM\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
367 "tc load Load or default settings from EEPROM\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
368 "tc dflt Load defaults from flash\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
369 "tc list List current settings\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
370 "tc mode [achin] Change control mode, must be one of\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
371 " a Auto\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
372 " c Always cool\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
373 " h Always heat\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
374 " i Always idle\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
375 " n Like idle but don't log anything\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
376 "tc X Y Set X to Y where X is one of\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
377 " targ Target temperature\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
378 " hys Hysteresis range\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
379 " mhov Minimum heat overshoot\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
380 " mcov Minimum cool overshoot\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
381 " mcon Minimum cool on time\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
382 " mcoff Minimum cool off time\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
383 " mhin Minimum heat on time\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
384 " mhoff Minimum heat off time\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
385 "tc A B Set temperature sensor ID\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
386 " Where A is ferm, frg or amb\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
387 " and B is of the form xx:xx:xx:xx:xx:xx:xx:xx\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
388 "\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
389 " Times are in seconds\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
390 " Temperatures are in hundredths of degrees Celcius\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
391 );
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
392 return;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
393 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
394
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
395 if (!strcasecmp(argv[0], "save")) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
396 tempctrl_write_settings();
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
397 return;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
398 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
399 if (!strcasecmp(argv[0], "load")) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
400 tempctrl_load_or_init_settings();
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
401 return;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
402 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
403 if (!strcasecmp(argv[0], "dflt")) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
404 tempctrl_default_settings();
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
405 return;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
406 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
407 if (!strcasecmp(argv[0], "list")) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
408 printf("Fermenter ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
409 "Fridge ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
410 "Ambient ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
411 "Mode - %c, Target - %d, Hystersis - %d\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
412 "Min heat overshoot - %d, Min cool overshoot - %d\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
413 "Min cool on time - %d, Min cool off time - %d\r\n"
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
414 "Min heat on time - %d, Min heat off time - %d\r\n",
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
415 settings.fermenter_ROM[0], settings.fermenter_ROM[1], settings.fermenter_ROM[2], settings.fermenter_ROM[3],
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
416 settings.fermenter_ROM[4], settings.fermenter_ROM[5], settings.fermenter_ROM[6], settings.fermenter_ROM[7],
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
417 settings.fridge_ROM[0], settings.fridge_ROM[1], settings.fridge_ROM[2], settings.fridge_ROM[3],
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
418 settings.fridge_ROM[4], settings.fridge_ROM[5], settings.fridge_ROM[6], settings.fridge_ROM[7],
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
419 settings.ambient_ROM[0], settings.ambient_ROM[1], settings.ambient_ROM[2], settings.ambient_ROM[3],
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
420 settings.ambient_ROM[4], settings.ambient_ROM[5], settings.ambient_ROM[6], settings.ambient_ROM[7],
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
421 settings.mode, settings.target_temp, settings.hysteresis,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
422 settings.minheatovershoot, settings.mincoolovershoot,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
423 settings.mincoolontime, settings.minheatontime,
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
424 settings.minheatontime, settings.minheatofftime
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
425 );
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
426 return;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
427 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
428 if (!strcasecmp(argv[0], "mode")) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
429 if (argc < 2) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
430 fputs("Incorrect number of arguments\r\n", stdout);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
431 return;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
432 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
433
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
434 switch (argv[1][0]) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
435 case TC_MODE_AUTO:
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
436 case TC_MODE_HEAT:
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
437 case TC_MODE_COOL:
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
438 case TC_MODE_IDLE:
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
439 case TC_MODE_NOTHING:
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
440 settings.mode = argv[1][0];
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
441 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
442
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
443 default:
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
444 printf("Unknown mode character '%c'\r\n", argv[1][0]);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
445 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
446 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
447 return;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
448 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
449 if (!strcasecmp(argv[0], "ferm") ||
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
450 !strcasecmp(argv[0], "frg") ||
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
451 !strcasecmp(argv[0], "amb")) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
452 if (argc < 2) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
453 fputs("Incorrect number of arguments\r\n", stdout);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
454 return;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
455 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
456
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
457 if (sscanf(argv[1], "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
458 &ROM[0], &ROM[1], &ROM[2], &ROM[3],
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
459 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
460 printf("Unable to parse ROM ID\r\n");
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
461 } else {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
462 if (!strcasecmp(argv[0], "ferm"))
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
463 memcpy(&settings.fermenter_ROM, ROM, sizeof(ROM));
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
464 if (!strcasecmp(argv[0], "frg"))
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
465 memcpy(&settings.fridge_ROM, ROM, sizeof(ROM));
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
466 if (!strcasecmp(argv[0], "amb"))
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
467 memcpy(&settings.ambient_ROM, ROM, sizeof(ROM));
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
468 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
469 return;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
470 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
471
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
472 /* Handle setting the multitude of variables
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
473 * It's last to simplify things */
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
474 if (argc < 3) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
475 fputs("Incorrect number of arguments for variable/value\r\n", stdout);
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
476 return;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
477 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
478
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
479 if (sscanf(argv[2], "%hd", &data) != 1) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
480 printf("Unable to parse value for variable\r\n");
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
481 return;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
482 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
483
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
484 if (!strcasecmp(argv[1], "targ")) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
485 settings.target_temp = data;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
486 } else if (!strcasecmp(argv[1], "hys")) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
487 settings.hysteresis = data;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
488 } else if (!strcasecmp(argv[1], "mhov")) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
489 settings.minheatovershoot = data;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
490 } else if (!strcasecmp(argv[1], "mcov")) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
491 settings.mincoolovershoot = data;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
492 } else if (!strcasecmp(argv[1], "mcon")) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
493 settings.mincoolontime = data;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
494 } else if (!strcasecmp(argv[1], "mcoff")) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
495 settings.mincoolofftime = data;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
496 } else if (!strcasecmp(argv[1], "mhon")) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
497 settings.minheatontime = data;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
498 } else if (!strcasecmp(argv[1], "mhoff")) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
499 settings.minheatofftime = data;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
500 } else {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
501 printf("Unknown setting\r\n");
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
502 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
503 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
504
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
505 static const char*
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
506 state2long(char s) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
507 switch (s) {
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
508 case 'i':
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
509 return "idle";
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
510 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
511
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
512 case 'c':
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
513 return "cool";
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
514 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
515
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
516 case 'h':
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
517 return "heat";
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
518 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
519
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
520 case '-':
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
521 return "-";
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
522 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
523
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
524 default:
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
525 return "unknown";
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
526 break;
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
527 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
528 }