MeterLogger
led.c
Go to the documentation of this file.
1 #include <esp8266.h>
2 #include "debug.h"
3 #include "led.h"
4 
7 
10 
11 static volatile bool led_blinker_timer_running = false;
12 static volatile bool led_double_blinker_timer_running = false;
13 
14 static uint8_t led_sub_pattern_state = 0;
15 
16 ICACHE_FLASH_ATTR void static led_blinker_timer_func(void *arg) {
17  if (led_blinker_timer_running == false) {
18  // stop blinking if asked to stop via state variable led_blinker_timer_running
20  return;
21  }
22 
23  // do blinky stuff
25  led_on();
26  }
27  else {
28  led_off();
29  }
30 }
31 
33  led_off();
34 }
35 
37  // blink fast two times
38  if (led_double_blinker_timer_running == false) {
39  // stop blinking if asked to stop via state variable led_double_blinker_timer_running
41  return;
42  }
43 
44  led_off();
45 
46  switch (led_sub_pattern_state) {
47  case 0:
48  led_on();
49 
54  break;
55  case 1:
56  led_off();
57 
60  os_timer_setfn(&led_sub_pattern_timer, (os_timer_func_t *)led_double_blink_timer_func, NULL);
62  break;
63  case 2:
64  led_on();
65 
68  os_timer_setfn(&led_sub_pattern_timer, (os_timer_func_t *)led_double_blink_timer_func, NULL);
70  break;
71  case 3:
72  led_off();
73 
76  break;
77  }
78 }
79 
81  //Set GPIO2 to output mode
83 
84  // Set GPIO2 to HIGH (turn blue led off)
85  gpio_output_set(BIT2, 0, BIT2, 0);
86 }
87 
89  //Set GPIO2 to LOW
90  gpio_output_set(0, BIT2, BIT2, 0);
91 }
92 
94 
95  // Set GPIO2 to HIGH
96  gpio_output_set(BIT2, 0, BIT2, 0);
97 }
98 
100  led_on();
104 }
105 
109  led_blinker_timer_running = true; // state variable to control stopping after pattern is done
110  os_timer_arm(&led_blinker_timer, 1000, 1);
111 }
112 
116  led_blinker_timer_running = true; // state variable to control stopping after pattern is done
118 }
119 
121  // blink fast two times every 5th second
124  led_double_blinker_timer_running = true; // state variable to control stopping after pattern is done
126 }
127 
131  led_off();
132 }
133 
ICACHE_FLASH_ATTR void led_pattern_b(void)
Definition: led.c:113
static os_timer_t led_sub_pattern_timer
Definition: led.c:9
#define PIN_FUNC_SELECT(PIN_NAME, FUNC)
Definition: eagle_soc.h:270
#define os_timer_t
Definition: os_type.h:34
#define os_timer_disarm
Definition: osapi.h:51
static os_timer_t led_single_blink_off_timer
Definition: led.c:6
ICACHE_FLASH_ATTR static void led_blinker_timer_func(void *arg)
Definition: led.c:16
#define NULL
Definition: def.h:47
#define PERIPHS_IO_MUX_GPIO2_U
Definition: eagle_soc.h:258
#define ICACHE_FLASH_ATTR
Definition: c_types.h:99
#define os_timer_func_t
Definition: os_type.h:35
static uint8_t led_sub_pattern_state
Definition: led.c:14
#define os_timer_setfn
Definition: osapi.h:52
#define GPIO_REG_READ(reg)
Definition: eagle_soc.h:97
ICACHE_FLASH_ATTR static void led_single_blink_off_timer_func(void *arg)
Definition: led.c:32
ICACHE_FLASH_ATTR void led_off(void)
Definition: led.c:93
#define BIT2
Definition: eagle_soc.h:58
static os_timer_t led_double_blink_timer
Definition: led.c:8
static volatile bool led_blinker_timer_running
Definition: led.c:11
ICACHE_FLASH_ATTR void led_blink(void)
Definition: led.c:99
static os_timer_t led_blinker_timer
Definition: led.c:5
ICACHE_FLASH_ATTR void led_init(void)
Definition: led.c:80
ICACHE_FLASH_ATTR void led_on(void)
Definition: led.c:88
#define os_timer_arm(a, b, c)
Definition: osapi.h:50
ICACHE_FLASH_ATTR static void led_double_blink_timer_func(void *arg)
Definition: led.c:36
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 volatile bool led_double_blinker_timer_running
Definition: led.c:12
#define GPIO_OUT_ADDRESS
Definition: eagle_soc.h:99
#define FUNC_GPIO2
Definition: eagle_soc.h:259
ICACHE_FLASH_ATTR void led_stop_pattern(void)
Definition: led.c:128
ICACHE_FLASH_ATTR void led_pattern_c(void)
Definition: led.c:120