annotate tempctrl.c @ 48:2f336d212c74

Ignore more emacs crap.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 03 Apr 2013 23:33:47 +1030
parents b4440f9f6d47
children adc9b1555f9d
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>
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
30 #include <ctype.h>
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
31 #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
32 #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
33 #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
34 #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
35 #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
36 #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
37 #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
38
03592ca4d37e Port tempctrl.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 "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
40 #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
41 #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
42
03592ca4d37e Port tempctrl.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 /* 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
44 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
45 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
46 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
47 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
48 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
49 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
50 /* 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
51 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
52 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
53
03592ca4d37e Port tempctrl.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 /* 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
55 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
56 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
57
03592ca4d37e Port tempctrl.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 /* 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
59 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
60 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
61
03592ca4d37e Port tempctrl.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_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
63 #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
64 #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
65 #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
66 #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
67 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
68
03592ca4d37e Port tempctrl.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 port the heater & cooler are on */
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
70 char coolport;
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
71 uint16_t coolpin;
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
72 uint8_t coolinv;
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
73
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
74 char heatport;
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
75 uint16_t heatpin;
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
76 uint8_t heatinv;
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
77
03592ca4d37e Port tempctrl.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 /* 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
79 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
80 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
81
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
82 uint8_t pad[1]; /* Pad to multiple of 4 bytes */
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
83 } 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
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 /* 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
86 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
87
03592ca4d37e Port tempctrl.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 /* 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
89 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
90 .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
91 .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
92 .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
93 .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
94 .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
95 .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
96 .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
97 .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
98 .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
99 .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
100 .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
101 .mode = TC_MODE_AUTO,
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
102 .coolport = 'E',
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
103 .coolpin = 4,
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
104 .coolinv = 1,
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
105 .heatport = 'E',
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
106 .heatpin = 5,
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
107 .heatinv = 1,
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
108 .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
109 .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
110 };
03592ca4d37e Port tempctrl.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
03592ca4d37e Port tempctrl.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 /* 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
113
03592ca4d37e Port tempctrl.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 /* 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
115 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
116 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
117 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
118 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
119 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
120 static void printtemp(const char *name, int tmp, const char *trailer);
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
121 static GPIO_TypeDef *char2port(char port);
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
122
03592ca4d37e Port tempctrl.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 /*
03592ca4d37e Port tempctrl.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 * 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
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 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
128 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
129 tempctrl_load_or_init_settings();
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
130 setstate('i');
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
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 /*
03592ca4d37e Port tempctrl.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
03592ca4d37e Port tempctrl.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 *
03592ca4d37e Port tempctrl.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 * 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
137 * (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
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 */
03592ca4d37e Port tempctrl.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 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
141 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
142 /* 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
143 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
144 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
145
03592ca4d37e Port tempctrl.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 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 /* 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
155 * 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
156
03592ca4d37e Port tempctrl.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 /* 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
158 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
159 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
160 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
161 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
162 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
163 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
164 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
165 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
166
03592ca4d37e Port tempctrl.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 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
168
03592ca4d37e Port tempctrl.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 /* 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
170 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
171 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
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 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
174
03592ca4d37e Port tempctrl.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 /* 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
176 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
177 nextstate = 'i';
43
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
178 goto skip;
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
179 }
03592ca4d37e Port tempctrl.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 /* 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
182 * 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
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 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
185 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
186 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
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 /* 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
189 * 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
190 */
03592ca4d37e Port tempctrl.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 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
192 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
193 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
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
03592ca4d37e Port tempctrl.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 /* 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
197 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
198 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
199 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
200 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
201
03592ca4d37e Port tempctrl.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 /* 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
203 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
204
03592ca4d37e Port tempctrl.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 /* 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
206 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
207
03592ca4d37e Port tempctrl.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 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
209 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
210 /* If we're idle then only heat or cool if the temperate difference is out of the
43
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
211 * hysteresis band and the heater/cooler have been off long enough
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
212 */
03592ca4d37e Port tempctrl.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 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
214 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
215 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
216 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
217 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
218 }
03592ca4d37e Port tempctrl.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 '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
222 /* 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
223 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
224 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
225 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
226 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
227
03592ca4d37e Port tempctrl.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 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
229 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
230 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
231 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
232 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
233
03592ca4d37e Port tempctrl.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 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
235 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
236 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
237 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
238 }
03592ca4d37e Port tempctrl.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
03592ca4d37e Port tempctrl.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 /* 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
241 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
242 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
243
03592ca4d37e Port tempctrl.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 /* 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
245 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
246 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
247 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
248 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
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 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
251 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
252 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
253 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
254 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
255 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
256
43
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
257 /* Keep track of when we last turned things on or off */
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
258 skip:
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
259 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
260 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
261 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
262 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
263 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
264 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
265
03592ca4d37e Port tempctrl.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 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
267 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
268 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
269 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
270 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
271
03592ca4d37e Port tempctrl.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 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
273 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
274 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
275 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
276 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
277 }
03592ca4d37e Port tempctrl.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
03592ca4d37e Port tempctrl.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 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
280 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
281
03592ca4d37e Port tempctrl.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
43
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
283 if (settings.mode != TC_MODE_NOTHING) {
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
284 localtime_r(&t, &tm);
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
285 assert(strftime(buf, sizeof(buf) - 1, "%Y/%m/%d %H:%M:%S: ", &tm) != 0);
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
286 fputs(buf, stdout);
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
287 printtemp("Tr", settings.target_temp, ", ");
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
288 printtemp("Fm", tempt, ", "); // Use actual value from sensor
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
289 printtemp("Fr", fridge_temp, ", ");
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
290 printtemp("Am", ambient_temp, ", ");
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
291 printf("St: %s, Fl: %s%s\r\n", state2long(currstate),
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
292 forced ? "F" : "",
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
293 stale ? "S" : "");
b4440f9f6d47 Fix 'none' mode.
Daniel O'Connor <darius@dons.net.au>
parents: 42
diff changeset
294 }
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
295
03592ca4d37e Port tempctrl.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 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
297 }
03592ca4d37e Port tempctrl.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
03592ca4d37e Port tempctrl.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 * 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
301 */
03592ca4d37e Port tempctrl.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 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
303 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
304 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
305 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
306 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
307 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
308 }
03592ca4d37e Port tempctrl.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
03592ca4d37e Port tempctrl.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 /* 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
311 * 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
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 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
314 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
315 /* 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
316 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
317 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
318 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
319 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
320 }
03592ca4d37e Port tempctrl.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 }
03592ca4d37e Port tempctrl.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
03592ca4d37e Port tempctrl.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 /* 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
324 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
325 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
326 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
327 }
03592ca4d37e Port tempctrl.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
03592ca4d37e Port tempctrl.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 /* 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
330 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
331 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
332 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
333 }
03592ca4d37e Port tempctrl.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 /* 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
336 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
337 setstate(char state) {
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
338 uint8_t cool, heat;
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
339
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
340 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
341 case 'c':
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
342 cool = 1;
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
343 heat = 0;
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
344 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
345
03592ca4d37e Port tempctrl.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 case 'h':
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
347 cool = 0;
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
348 heat = 1;
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
349 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
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 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
352 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
353 /* 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
354
03592ca4d37e Port tempctrl.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 case 'i':
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
356 cool = 0;
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
357 heat = 0;
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
358 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
359 }
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
360
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
361 if (cool ^ settings.coolinv)
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
362 GPIO_SetBits(char2port(settings.coolport), 1 << settings.coolpin);
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
363 else
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
364 GPIO_ResetBits(char2port(settings.coolport), 1 << settings.coolpin);
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
365
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
366 if (heat ^ settings.heatinv)
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
367 GPIO_SetBits(char2port(settings.heatport), 1 << settings.heatpin);
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
368 else
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
369 GPIO_ResetBits(char2port(settings.heatport), 1 << settings.heatpin);
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
370 }
03592ca4d37e Port tempctrl.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
03592ca4d37e Port tempctrl.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 /* 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
373 *
03592ca4d37e Port tempctrl.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 */
03592ca4d37e Port tempctrl.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 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
376 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
377 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
378 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
379
03592ca4d37e Port tempctrl.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 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
381 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
382 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
383 }
03592ca4d37e Port tempctrl.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
03592ca4d37e Port tempctrl.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 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
386 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
387 "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
388 "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
389 "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
390 "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
391 "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
392 " 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
393 " 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
394 " 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
395 " 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
396 " 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
397 "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
398 " 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
399 " 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
400 " 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
401 " 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
402 " 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
403 " 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
404 " 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
405 " 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
406 "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
407 " 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
408 " 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
409 "\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 " 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
411 " 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
412 );
03592ca4d37e Port tempctrl.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 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
414 }
03592ca4d37e Port tempctrl.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
03592ca4d37e Port tempctrl.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 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
417 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
418 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
419 }
03592ca4d37e Port tempctrl.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 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
421 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
422 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
423 }
03592ca4d37e Port tempctrl.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 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
425 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
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], "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
429 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
430 "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
431 "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
432 "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
433 "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
434 "Min cool on time - %d, Min cool off time - %d\r\n"
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
435 "Min heat on time - %d, Min heat off time - %d\r\n"
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
436 "Cool: Port %c Pin %d Inv %d, Heat: Port %c Pin %d Inv %d\r\n",
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
437 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
438 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
439 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
440 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
441 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
442 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
443 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
444 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
445 settings.mincoolontime, settings.minheatontime,
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
446 settings.minheatontime, settings.minheatofftime,
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
447 settings.coolport, settings.coolpin, settings.coolinv,
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
448 settings.heatport, settings.heatpin, settings.heatinv
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
449 );
03592ca4d37e Port tempctrl.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 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
451 }
03592ca4d37e Port tempctrl.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 (!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
453 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
454 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
455 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
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
03592ca4d37e Port tempctrl.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 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
459 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
460 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
461 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
462 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
463 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
464 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
465 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
466
03592ca4d37e Port tempctrl.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 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
468 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
469 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
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 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
472 }
03592ca4d37e Port tempctrl.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 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
474 !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
475 !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
476 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
477 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
478 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
479 }
03592ca4d37e Port tempctrl.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
03592ca4d37e Port tempctrl.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 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
482 &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
483 &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
484 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
485 } 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
486 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
487 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
488 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
489 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
490 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
491 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
492 }
03592ca4d37e Port tempctrl.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 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
494 }
03592ca4d37e Port tempctrl.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
03592ca4d37e Port tempctrl.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 /* 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
497 * 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
498 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
499 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
500 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
501 }
03592ca4d37e Port tempctrl.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 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
504 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
505 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
506 }
03592ca4d37e Port tempctrl.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
03592ca4d37e Port tempctrl.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 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
509 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
510 } 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
511 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
512 } 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
513 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
514 } 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
515 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
516 } 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
517 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
518 } 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
519 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
520 } 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
521 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
522 } 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
523 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
524 } 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
525 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
526 }
03592ca4d37e Port tempctrl.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
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
529 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
530 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
531 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
532 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
533 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
534 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
535
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
536 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
537 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
538 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
539
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
540 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
541 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
542 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
543
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
544 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
545 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
546 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
547
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
548 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
549 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
550 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
551 }
03592ca4d37e Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
552 }
42
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
553
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
554 /* Convert a port name into a number */
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
555 static GPIO_TypeDef *
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
556 char2port(char port) {
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
557 char p;
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
558
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
559 p = toupper(port);
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
560 assert(p >= 'A' && p <= 'E');
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
561
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
562 switch (p) {
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
563 case 'A':
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
564 return GPIOA;
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
565 case 'B':
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
566 return GPIOB;
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
567 case 'C':
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
568 return GPIOC;
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
569 case 'D':
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
570 return GPIOD;
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
571 case 'E':
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
572 return GPIOE;
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
573 }
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
574 }
56b32b0c9a40 Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
575