MeterLogger
Enumerations | Functions | Variables
ac_out.c File Reference
#include <esp8266.h>
#include "led.h"
#include "ac_out.h"
#include "config.h"
Include dependency graph for ac_out.c:

Go to the source code of this file.

Enumerations

enum  ac_pwm_state_t { ON, OFF }
 

Functions

ICACHE_FLASH_ATTR void ac_out_init ()
 
ICACHE_FLASH_ATTR static void ac_test_timer_func (void *arg)
 
ICACHE_FLASH_ATTR static void ac_out_off_timer_func (void *arg)
 
ICACHE_FLASH_ATTR static void ac_pwm_timer_func (void *arg)
 
ICACHE_FLASH_ATTR void ac_test ()
 
ICACHE_FLASH_ATTR void ac_motor_valve_open ()
 
ICACHE_FLASH_ATTR void ac_motor_valve_close ()
 
ICACHE_FLASH_ATTR void ac_thermo_open ()
 
ICACHE_FLASH_ATTR void ac_thermo_close ()
 
ICACHE_FLASH_ATTR void ac_thermo_pwm (unsigned int duty_cycle)
 
ICACHE_FLASH_ATTR void ac_off ()
 

Variables

static os_timer_t ac_test_timer
 
static os_timer_t ac_out_off_timer
 
static os_timer_t ac_pwm_timer
 
unsigned int ac_pwm_duty_cycle
 
ac_pwm_state_t ac_pwm_state = OFF
 

Enumeration Type Documentation

◆ ac_pwm_state_t

Enumerator
ON 
OFF 

Definition at line 12 of file ac_out.c.

ac_pwm_state_t
Definition: ac_out.c:12
Definition: ac_out.c:12
Definition: ac_out.c:12

Function Documentation

◆ ac_motor_valve_close()

ICACHE_FLASH_ATTR void ac_motor_valve_close ( )

Definition at line 154 of file ac_out.c.

References ac_off(), ac_out_off_timer, ac_out_off_timer_func(), ICACHE_FLASH_ATTR, led_pattern_b(), NULL, os_printf, os_timer_arm, os_timer_disarm, os_timer_func_t, and os_timer_setfn.

154  {
155 #ifdef DEBUG
156  os_printf("\n\rac 2 on\n\r");
157 #endif
158  ac_off();
159 #ifdef LED_ON_AC
160  led_pattern_b();
161 #endif
162 
163  //Set GPI15 to HIGH
164 // gpio_output_set(BIT15, 0, BIT15, 0);
165 
166  // wait 60 seconds and turn ac output off
169  os_timer_arm(&ac_out_off_timer, 60000, 0);
170 }
ICACHE_FLASH_ATTR void led_pattern_b(void)
Definition: led.c:113
#define os_timer_disarm
Definition: osapi.h:51
static os_timer_t ac_out_off_timer
Definition: ac_out.c:8
#define NULL
Definition: def.h:47
#define os_timer_func_t
Definition: os_type.h:35
ICACHE_FLASH_ATTR void ac_off()
Definition: ac_out.c:247
#define os_printf
Definition: osapi.h:62
#define os_timer_setfn
Definition: osapi.h:52
ICACHE_FLASH_ATTR static void ac_out_off_timer_func(void *arg)
Definition: ac_out.c:53
#define os_timer_arm(a, b, c)
Definition: osapi.h:50
Here is the call graph for this function:

◆ ac_motor_valve_open()

ICACHE_FLASH_ATTR void ac_motor_valve_open ( )

Definition at line 135 of file ac_out.c.

References ac_off(), ac_out_off_timer, ac_out_off_timer_func(), BIT14, gpio_output_set(), ICACHE_FLASH_ATTR, led_pattern_a(), NULL, os_printf, os_timer_arm, os_timer_disarm, os_timer_func_t, and os_timer_setfn.

135  {
136 #ifdef DEBUG
137  os_printf("\n\rac 1 on\n\r");
138 #endif
139  ac_off();
140 #ifdef LED_ON_AC
141  led_pattern_a();
142 #endif
143 
144  //Set GPI14 to HIGH
145  gpio_output_set(BIT14, 0, BIT14, 0);
146 
147  // wait 60 seconds and turn ac output off
150  os_timer_arm(&ac_out_off_timer, 60000, 0);
151 }
#define os_timer_disarm
Definition: osapi.h:51
static os_timer_t ac_out_off_timer
Definition: ac_out.c:8
#define NULL
Definition: def.h:47
#define os_timer_func_t
Definition: os_type.h:35
ICACHE_FLASH_ATTR void ac_off()
Definition: ac_out.c:247
#define os_printf
Definition: osapi.h:62
#define os_timer_setfn
Definition: osapi.h:52
#define BIT14
Definition: eagle_soc.h:46
ICACHE_FLASH_ATTR static void ac_out_off_timer_func(void *arg)
Definition: ac_out.c:53
#define os_timer_arm(a, b, c)
Definition: osapi.h:50
void gpio_output_set(uint32 set_mask, uint32 clear_mask, uint32 enable_mask, uint32 disable_mask)
ICACHE_FLASH_ATTR void led_pattern_a(void)
Definition: led.c:106
Here is the call graph for this function:

◆ ac_off()

ICACHE_FLASH_ATTR void ac_off ( )

Definition at line 247 of file ac_out.c.

References ac_out_off_timer, ac_out_off_timer_func(), ac_test_timer, NULL, os_timer_arm, os_timer_disarm, os_timer_func_t, and os_timer_setfn.

Referenced by ac_motor_valve_close(), ac_motor_valve_open(), and minute_timer_func().

247  {
248  // turn ac output off
253 }
#define os_timer_disarm
Definition: osapi.h:51
static os_timer_t ac_out_off_timer
Definition: ac_out.c:8
#define NULL
Definition: def.h:47
#define os_timer_func_t
Definition: os_type.h:35
#define os_timer_setfn
Definition: osapi.h:52
ICACHE_FLASH_ATTR static void ac_out_off_timer_func(void *arg)
Definition: ac_out.c:53
#define os_timer_arm(a, b, c)
Definition: osapi.h:50
static os_timer_t ac_test_timer
Definition: ac_out.c:7
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ac_out_init()

ICACHE_FLASH_ATTR void ac_out_init ( )

Definition at line 17 of file ac_out.c.

References FUNC_GPIO14, FUNC_GPIO15, ICACHE_FLASH_ATTR, PERIPHS_IO_MUX_MTDO_U, PERIPHS_IO_MUX_MTMS_U, and PIN_FUNC_SELECT.

17  {
18  //Set GPIO14 and GPIO15 to output mode
20 #ifdef THERMO_ON_AC_2
22 #endif
23 }
#define PIN_FUNC_SELECT(PIN_NAME, FUNC)
Definition: eagle_soc.h:270
#define FUNC_GPIO15
Definition: eagle_soc.h:226
#define FUNC_GPIO14
Definition: eagle_soc.h:224
#define PERIPHS_IO_MUX_MTDO_U
Definition: eagle_soc.h:225
#define PERIPHS_IO_MUX_MTMS_U
Definition: eagle_soc.h:223

◆ ac_out_off_timer_func()

ICACHE_FLASH_ATTR static void ac_out_off_timer_func ( void *  arg)
static

Definition at line 53 of file ac_out.c.

References BIT14, BIT15, gpio_output_set(), led_off(), led_stop_pattern(), and os_printf.

Referenced by ac_motor_valve_close(), ac_motor_valve_open(), and ac_off().

53  {
54 #ifdef DEBUG
55  os_printf("\n\rac 1 and 2 off\n\r");
56 #endif
57 
58  //Set GPI14 to LOW
59  gpio_output_set(0, BIT14, BIT14, 0);
60 
61 #ifdef THERMO_ON_AC_2
62  //Set GPI15 to LOW
63  gpio_output_set(0, BIT15, BIT15, 0);
64 #endif
65 
67 #ifdef LED_ON_AC
68  led_off();
69 #endif
70 }
#define BIT15
Definition: eagle_soc.h:45
#define os_printf
Definition: osapi.h:62
ICACHE_FLASH_ATTR void led_off(void)
Definition: led.c:93
#define BIT14
Definition: eagle_soc.h:46
void gpio_output_set(uint32 set_mask, uint32 clear_mask, uint32 enable_mask, uint32 disable_mask)
ICACHE_FLASH_ATTR void led_stop_pattern(void)
Definition: led.c:128
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ac_pwm_timer_func()

ICACHE_FLASH_ATTR static void ac_pwm_timer_func ( void *  arg)
static

Definition at line 72 of file ac_out.c.

References ac_pwm_duty_cycle, ac_pwm_state, ac_pwm_timer, BIT14, gpio_output_set(), ICACHE_FLASH_ATTR, led_off(), led_on(), NULL, OFF, ON, os_timer_arm, os_timer_disarm, os_timer_func_t, and os_timer_setfn.

Referenced by ac_thermo_pwm().

72  {
73  // do ac 1 pwm
74  if (ac_pwm_state == OFF) {
75  ac_pwm_state = ON;
76  if (ac_pwm_duty_cycle > 0) {
77 #ifdef LED_ON_AC
78  led_on();
79 #endif
80 #ifdef THERMO_NO
81  //Set GPI14 to LOW
82  gpio_output_set(0, BIT14, BIT14, 0);
83 #else // THERMO_NC
84  //Set GPI14 to HIGH
85  gpio_output_set(BIT14, 0, BIT14, 0);
86 #endif
87  }
88  // reload timer
91  os_timer_arm(&ac_pwm_timer, ac_pwm_duty_cycle * 10, 1); // pwm frequency 10 second
92  }
93  else if (ac_pwm_state == ON) {
94  ac_pwm_state = OFF;
95  if (ac_pwm_duty_cycle < 1000) {
96 #ifdef LED_ON_AC
97  led_off();
98 #endif
99 #ifdef THERMO_NO
100  //Set GPI14 to HIGHT
101  gpio_output_set(BIT14, 0, BIT14, 0);
102 #else // THERMO_NC
103  //Set GPI14 to LOW
104  gpio_output_set(0, BIT14, BIT14, 0);
105 #endif
106  }
107  // reload timer
110  os_timer_arm(&ac_pwm_timer, (1000 - ac_pwm_duty_cycle) * 10, 1); // pwm frequency 10 second
111  }
112 }
#define os_timer_disarm
Definition: osapi.h:51
#define NULL
Definition: def.h:47
static os_timer_t ac_pwm_timer
Definition: ac_out.c:9
#define os_timer_func_t
Definition: os_type.h:35
#define os_timer_setfn
Definition: osapi.h:52
ICACHE_FLASH_ATTR void led_off(void)
Definition: led.c:93
ICACHE_FLASH_ATTR static void ac_pwm_timer_func(void *arg)
Definition: ac_out.c:72
Definition: ac_out.c:12
#define BIT14
Definition: eagle_soc.h:46
ICACHE_FLASH_ATTR void led_on(void)
Definition: led.c:88
ac_pwm_state_t ac_pwm_state
Definition: ac_out.c:13
#define os_timer_arm(a, b, c)
Definition: osapi.h:50
void gpio_output_set(uint32 set_mask, uint32 clear_mask, uint32 enable_mask, uint32 disable_mask)
unsigned int ac_pwm_duty_cycle
Definition: ac_out.c:11
Definition: ac_out.c:12
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ac_test()

ICACHE_FLASH_ATTR void ac_test ( )

Definition at line 115 of file ac_out.c.

References ac_test_timer, ac_test_timer_func(), BIT14, BIT15, gpio_output_set(), ICACHE_FLASH_ATTR, led_pattern_a(), NULL, os_printf, os_timer_arm, os_timer_disarm, os_timer_func_t, and os_timer_setfn.

Referenced by minute_timer_func().

115  {
116 #ifdef DEBUG
117  os_printf("\n\rac test on\n\r");
118 #endif
119 #ifdef LED_ON_AC
120  led_pattern_a();
121 #endif
122 
123  // set GPIO14 high and GPIO15 low
124  gpio_output_set(BIT14, 0, BIT14, 0);
125 #ifdef THERMO_ON_AC_2
126  gpio_output_set(0, BIT15, BIT15, 0);
127 #endif
128 
131  os_timer_arm(&ac_test_timer, 120000, 1);
132 }
#define os_timer_disarm
Definition: osapi.h:51
#define NULL
Definition: def.h:47
#define os_timer_func_t
Definition: os_type.h:35
#define BIT15
Definition: eagle_soc.h:45
#define os_printf
Definition: osapi.h:62
#define os_timer_setfn
Definition: osapi.h:52
#define BIT14
Definition: eagle_soc.h:46
#define os_timer_arm(a, b, c)
Definition: osapi.h:50
void gpio_output_set(uint32 set_mask, uint32 clear_mask, uint32 enable_mask, uint32 disable_mask)
ICACHE_FLASH_ATTR void led_pattern_a(void)
Definition: led.c:106
static os_timer_t ac_test_timer
Definition: ac_out.c:7
ICACHE_FLASH_ATTR static void ac_test_timer_func(void *arg)
Definition: ac_out.c:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ac_test_timer_func()

ICACHE_FLASH_ATTR static void ac_test_timer_func ( void *  arg)
static

Definition at line 26 of file ac_out.c.

References BIT14, GPIO_OUT_ADDRESS, gpio_output_set(), GPIO_REG_READ, led_pattern_a(), and led_pattern_b().

Referenced by ac_test().

26  {
27  // do blinky stuff
29  //Set GPI14 to LOW
30  gpio_output_set(0, BIT14, BIT14, 0);
31 #ifdef LED_ON_AC
32  led_pattern_b();
33 #endif
34  }
35  else {
36  //Set GPI14 to HIGH
37  gpio_output_set(BIT14, 0, BIT14, 0);
38 #ifdef LED_ON_AC
39  led_pattern_a();
40 #endif
41  }
42 
43 // if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT15) {
44 // //Set GPI15 to LOW
45 // gpio_output_set(0, BIT15, BIT15, 0);
46 // }
47 // else {
48 // //Set GPI15 to HIGH
49 // gpio_output_set(BIT15, 0, BIT15, 0);
50 // }
51 }
ICACHE_FLASH_ATTR void led_pattern_b(void)
Definition: led.c:113
#define GPIO_REG_READ(reg)
Definition: eagle_soc.h:97
#define BIT14
Definition: eagle_soc.h:46
void gpio_output_set(uint32 set_mask, uint32 clear_mask, uint32 enable_mask, uint32 disable_mask)
ICACHE_FLASH_ATTR void led_pattern_a(void)
Definition: led.c:106
#define GPIO_OUT_ADDRESS
Definition: eagle_soc.h:99
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ac_thermo_close()

ICACHE_FLASH_ATTR void ac_thermo_close ( )

Definition at line 203 of file ac_out.c.

References syscfg_t::ac_thermo_state, BIT14, BIT15, cfg_save_defered(), gpio_output_set(), ICACHE_FLASH_ATTR, led_pattern_a(), os_printf, and sys_cfg.

Referenced by minute_timer_func().

203  {
204 #ifdef DEBUG
205  os_printf("\n\rac 1 close\n\r");
206 #endif
207 #ifdef LED_ON_AC
208  led_pattern_a();
209 #endif
210 
211 #ifdef THERMO_NO
212  //Set GPI14 to HIGHT
213  gpio_output_set(BIT14, 0, BIT14, 0);
214 #ifdef THERMO_ON_AC_2
215  //Set GPI15 to HIGH
216  gpio_output_set(BIT15, 0, BIT15, 0);
217 #endif
218 #else // THERMO_NC
219  //Set GPI14 to LOW
220  gpio_output_set(0, BIT14, BIT14, 0);
221 #ifdef THERMO_ON_AC_2
222  //Set GPI15 to LOW
223  gpio_output_set(0, BIT15, BIT15, 0);
224 #endif
225 #endif
226  if (sys_cfg.ac_thermo_state) { // only save if state changed
229  }
230 }
#define BIT15
Definition: eagle_soc.h:45
#define os_printf
Definition: osapi.h:62
void ICACHE_FLASH_ATTR cfg_save_defered()
Definition: config.c:144
#define BIT14
Definition: eagle_soc.h:46
void gpio_output_set(uint32 set_mask, uint32 clear_mask, uint32 enable_mask, uint32 disable_mask)
ICACHE_FLASH_ATTR void led_pattern_a(void)
Definition: led.c:106
uint8_t ac_thermo_state
Definition: config.h:61
syscfg_t sys_cfg
Definition: config.c:12
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ac_thermo_open()

ICACHE_FLASH_ATTR void ac_thermo_open ( )

Definition at line 173 of file ac_out.c.

References syscfg_t::ac_thermo_state, BIT14, BIT15, cfg_save_defered(), gpio_output_set(), ICACHE_FLASH_ATTR, led_pattern_b(), os_printf, and sys_cfg.

Referenced by minute_timer_func().

173  {
174 #ifdef DEBUG
175  os_printf("\n\rac 1 open\n\r");
176 #endif
177 #ifdef LED_ON_AC
178  led_pattern_b();
179 #endif
180 
181 #ifdef THERMO_NO
182  //Set GPI14 to LOW
183  gpio_output_set(0, BIT14, BIT14, 0);
184 #ifdef THERMO_ON_AC_2
185  //Set GPI15 to LOW
186  gpio_output_set(0, BIT15, BIT15, 0);
187 #endif
188 #else // THERMO_NC
189  //Set GPI14 to HIGH
190  gpio_output_set(BIT14, 0, BIT14, 0);
191 #ifdef THERMO_ON_AC_2
192  //Set GPI15 to HIGH
193  gpio_output_set(BIT15, 0, BIT15, 0);
194 #endif
195 #endif
196  if (!sys_cfg.ac_thermo_state) { // only save if state changed
199  }
200 }
ICACHE_FLASH_ATTR void led_pattern_b(void)
Definition: led.c:113
#define BIT15
Definition: eagle_soc.h:45
#define os_printf
Definition: osapi.h:62
void ICACHE_FLASH_ATTR cfg_save_defered()
Definition: config.c:144
#define BIT14
Definition: eagle_soc.h:46
void gpio_output_set(uint32 set_mask, uint32 clear_mask, uint32 enable_mask, uint32 disable_mask)
uint8_t ac_thermo_state
Definition: config.h:61
syscfg_t sys_cfg
Definition: config.c:12
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ac_thermo_pwm()

ICACHE_FLASH_ATTR void ac_thermo_pwm ( unsigned int  duty_cycle)

Definition at line 233 of file ac_out.c.

References ac_pwm_duty_cycle, ac_pwm_timer, ac_pwm_timer_func(), ICACHE_FLASH_ATTR, led_stop_pattern(), NULL, os_printf, os_timer_arm, os_timer_disarm, os_timer_func_t, and os_timer_setfn.

233  {
234 #ifdef DEBUG
235  os_printf("\n\rac 1 pwm\n\r");
236 #endif
237 #ifdef LED_ON_AC
239 #endif
240  ac_pwm_duty_cycle = duty_cycle;
243  os_timer_arm(&ac_pwm_timer, 0, 0); // fire now once, ac_pwm_timer start itself
244 }
#define os_timer_disarm
Definition: osapi.h:51
#define NULL
Definition: def.h:47
static os_timer_t ac_pwm_timer
Definition: ac_out.c:9
#define os_timer_func_t
Definition: os_type.h:35
#define os_printf
Definition: osapi.h:62
#define os_timer_setfn
Definition: osapi.h:52
ICACHE_FLASH_ATTR static void ac_pwm_timer_func(void *arg)
Definition: ac_out.c:72
#define os_timer_arm(a, b, c)
Definition: osapi.h:50
unsigned int ac_pwm_duty_cycle
Definition: ac_out.c:11
ICACHE_FLASH_ATTR void led_stop_pattern(void)
Definition: led.c:128
Here is the call graph for this function:

Variable Documentation

◆ ac_out_off_timer

os_timer_t ac_out_off_timer
static

Definition at line 8 of file ac_out.c.

Referenced by ac_motor_valve_close(), ac_motor_valve_open(), and ac_off().

◆ ac_pwm_duty_cycle

unsigned int ac_pwm_duty_cycle

Definition at line 11 of file ac_out.c.

Referenced by ac_pwm_timer_func(), and ac_thermo_pwm().

◆ ac_pwm_state

ac_pwm_state_t ac_pwm_state = OFF

Definition at line 13 of file ac_out.c.

Referenced by ac_pwm_timer_func().

◆ ac_pwm_timer

os_timer_t ac_pwm_timer
static

Definition at line 9 of file ac_out.c.

Referenced by ac_pwm_timer_func(), and ac_thermo_pwm().

◆ ac_test_timer

os_timer_t ac_test_timer
static

Definition at line 7 of file ac_out.c.

Referenced by ac_off(), and ac_test().