Pico Led Controller 1.0.3
A project to control LEDs using Raspberry Pi Pico W
Loading...
Searching...
No Matches
ssi.c
Go to the documentation of this file.
1#include "ssi.h"
2
3#include <stdio.h>
4
5#include "lwip/apps/httpd.h"
6#include "pico/cyw43_arch.h"
7#include "hardware/adc.h"
8
9#include "ntp.h"
10#include "light_state.h"
11#include "blink.h"
12
13static const char* ssi_tags[] =
14{
15 "volt",
16 "temp",
17 "gpio",
18 "led",
19 "mode",
20 "color",
21 "bright",
22 "tm",
23 NULL
24};
25
26u16_t ssi_handler(int iIndex, char *pcInsert, int iInsertLen)
27{
28 size_t print_value;
29 switch (iIndex)
30 {
31 case 0: // volt
32 print_value = snprintf(pcInsert, iInsertLen, "%f", (adc_read() * 3.3f / (1 << 12)));
33 break;
34 case 1: // temp
35 print_value = snprintf(pcInsert, iInsertLen, "%f", (27.0f - ((adc_read() * 3.3f / (1 << 12)) - 0.706f) / 0.001721f));
36 break;
37 case 2: // gpio led
38 if (cyw43_arch_gpio_get(CYW43_WL_GPIO_LED_PIN))
39 print_value = snprintf(pcInsert, iInsertLen, "ON");
40 else
41 print_value = snprintf(pcInsert, iInsertLen, "OFF");
42 break;
43 case 3: // light state
45 print_value = snprintf(pcInsert, iInsertLen, "ON");
46 else
47 print_value = snprintf(pcInsert, iInsertLen, "OFF");
48 break;
49 case 4: // light mode
50 switch (light_state.light_mode)
51 {
53 print_value = snprintf(pcInsert, iInsertLen, "rainbow-wheel");
54 break;
56 print_value = snprintf(pcInsert, iInsertLen, "rainbow-cycle");
57 break;
58 case MODE_STATIC:
59 print_value = snprintf(pcInsert, iInsertLen, "static");
60 break;
61 case MODE_BREATHING:
62 print_value = snprintf(pcInsert, iInsertLen, "breathing");
63 break;
64 case MODE_FLASHING:
65 print_value = snprintf(pcInsert, iInsertLen, "flashing");
66 break;
67 case MODE_LOADING:
68 print_value = snprintf(pcInsert, iInsertLen, "loading");
69 break;
70 case MODE_WAVE:
71 print_value = snprintf(pcInsert, iInsertLen, "wave");
72 break;
73 case MODE_FADE:
74 print_value = snprintf(pcInsert, iInsertLen, "fade");
75 break;
76 default:
77 print_value = 0;
78 break;
79 }
80 break;
81 case 5: // light color
82 switch (light_state.color)
83 {
84 case COLOR_RED:
85 print_value = snprintf(pcInsert, iInsertLen, "red");
86 break;
87 case COLOR_GREEN:
88 print_value = snprintf(pcInsert, iInsertLen, "green");
89 break;
90 case COLOR_BLUE:
91 print_value = snprintf(pcInsert, iInsertLen, "blue");
92 break;
93 case COLOR_WHITE:
94 print_value = snprintf(pcInsert, iInsertLen, "white");
95 break;
96 case COLOR_PURPLE:
97 print_value = snprintf(pcInsert, iInsertLen, "purple");
98 break;
99 case COLOR_YELLOW:
100 print_value = snprintf(pcInsert, iInsertLen, "yellow");
101 break;
102 case COLOR_CYAN:
103 print_value = snprintf(pcInsert, iInsertLen, "cyan");
104 break;
105 case COLOR_ORANGE:
106 print_value = snprintf(pcInsert, iInsertLen, "orange");
107 break;
108 case COLOR_PINK:
109 print_value = snprintf(pcInsert, iInsertLen, "pink");
110 break;
111 case COLOR_TURQUOISE:
112 print_value = snprintf(pcInsert, iInsertLen, "turquoise");
113 break;
114 case COLOR_MAGENTA:
115 print_value = snprintf(pcInsert, iInsertLen, "magenta");
116 break;
117 default:
118 print_value = 0;
119 break;
120 }
121 break;
122 case 6: // brightness
123 print_value = snprintf(pcInsert, iInsertLen, "%d", (int)(light_state.brightness / 255.0 * 100.0));
124 break;
125 case 7: // time tm
126 if (utc)
127 print_value = snprintf(pcInsert, iInsertLen, "%04d-%02d-%02dT%02d:%02d:%02dZ", utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday, utc->tm_hour, utc->tm_min, utc->tm_sec);
128 else
129 print_value = snprintf(pcInsert, iInsertLen, "NULL");
130 break;
131 default:
132 print_value = 0;
133 break;
134 }
135 return (u16_t)print_value;
136}
137
139{
140 adc_init();
141 adc_set_temp_sensor_enabled(true);
142 adc_select_input(4);
143 http_set_ssi_handler(ssi_handler, ssi_tags, LWIP_ARRAYSIZE(ssi_tags));
144}
@ MODE_RAINBOW_CYCLE
Definition light_state.h:20
@ MODE_FLASHING
Definition light_state.h:23
@ MODE_LOADING
Definition light_state.h:24
@ MODE_WAVE
Definition light_state.h:25
@ MODE_BREATHING
Definition light_state.h:22
@ MODE_STATIC
Definition light_state.h:21
@ MODE_RAINBOW_WHEEL
Definition light_state.h:19
@ MODE_FADE
Definition light_state.h:26
@ COLOR_ORANGE
Definition light_state.h:41
@ COLOR_BLUE
Definition light_state.h:36
@ COLOR_PINK
Definition light_state.h:43
@ COLOR_PURPLE
Definition light_state.h:40
@ COLOR_TURQUOISE
Definition light_state.h:42
@ COLOR_MAGENTA
Definition light_state.h:39
@ COLOR_RED
Definition light_state.h:34
@ COLOR_CYAN
Definition light_state.h:37
@ COLOR_YELLOW
Definition light_state.h:38
@ COLOR_GREEN
Definition light_state.h:35
@ COLOR_WHITE
Definition light_state.h:44
volatile struct light_state_t light_state
Light state.
Definition light_state.c:8
volatile struct tm * utc
UTC time struct.
Definition ntp.c:13
static const char * ssi_tags[]
Definition ssi.c:13
void ssi_init()
SSI init.
Definition ssi.c:138
u16_t ssi_handler(int iIndex, char *pcInsert, int iInsertLen)
SSI handler.
Definition ssi.c:26
uint8_t brightness
Definition light_state.h:59
enum light_modes light_mode
Definition light_state.h:61
enum light_colors color
Definition light_state.h:62