1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
84
85
86
87
88
89
90
91
92
93
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
172
173
174
175
176
177
178
179
180
181
182
183
/* ... */
#include "main.h"
#include "lwip/debug.h"
#include "lwip/tcp.h"
#include "lwip/apps/httpd.h"
#include "http_cgi_ssi.h"
#include <string.h>
#include <stdlib.h>
7 includes
tSSIHandler ADC_Page_SSI_Handler;
uint32_t ADC_not_configured=1;
ADC_HandleTypeDef hadc;
char const* TAGCHAR="t";
char const** TAGS=&TAGCHAR;
const char * LEDS_CGI_Handler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]);
const tCGI LEDS_CGI={"/leds.cgi", LEDS_CGI_Handler};
tCGI CGI_TAB[1];
/* ... */
static void ADC_Configuration(void)
{
ADC_ChannelConfTypeDef sConfig;
hadc.Instance = ADC3;
hadc.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;
hadc.Init.Resolution = ADC_RESOLUTION_12B;
hadc.Init.ScanConvMode = DISABLE;
hadc.Init.ContinuousConvMode = ENABLE;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.NbrOfConversion = 1;
HAL_ADC_Init(&hadc);
sConfig.Channel = ADC_CHANNEL_8;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES;
sConfig.Offset = 0;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
HAL_ADC_Start(&hadc);
}{ ... }
/* ... */
u16_t ADC_Handler(int iIndex, char *pcInsert, int iInsertLen)
{
if (iIndex ==0)
{
char Digit1=0, Digit2=0, Digit3=0, Digit4=0;
uint32_t ADCVal = 0;
if (ADC_not_configured ==1)
{
ADC_Configuration();
ADC_not_configured=0;
}if (ADC_not_configured ==1) { ... }
HAL_ADC_PollForConversion(&hadc, 10);
ADCVal = HAL_ADC_GetValue(&hadc);
ADCVal = (uint32_t)(ADCVal * 0.8);
Digit1= ADCVal/1000;
Digit2= (ADCVal-(Digit1*1000))/100;
Digit3= (ADCVal-((Digit1*1000)+(Digit2*100)))/10;
Digit4= ADCVal -((Digit1*1000)+(Digit2*100)+ (Digit3*10));
*pcInsert = (char)(Digit1+0x30);
*(pcInsert + 1) = (char)(Digit2+0x30);
*(pcInsert + 2) = (char)(Digit3+0x30);
*(pcInsert + 3) = (char)(Digit4+0x30);
return 4;
}if (iIndex ==0) { ... }
return 0;
}{ ... }
/* ... */
const char * LEDS_CGI_Handler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[])
{
uint32_t i=0;
if (iIndex==0)
{
BSP_LED_Off(LED1);
BSP_LED_Off(LED2);
BSP_LED_Off(LED3);
BSP_LED_Off(LED4);
for (i=0; i<iNumParams; i++)
{
if (strcmp(pcParam[i] , "led")==0)
{
if(strcmp(pcValue[i], "1") ==0)
BSP_LED_On(LED1);
else if(strcmp(pcValue[i], "2") ==0)
BSP_LED_On(LED2);
else if(strcmp(pcValue[i], "3") ==0)
BSP_LED_On(LED3);
else if(strcmp(pcValue[i], "4") ==0)
BSP_LED_On(LED4);
}if (strcmp(pcParam[i] , "led")==0) { ... }
}for (i=0; i
}if (iIndex==0) { ... }
return "/STM32F4xxLED.html";
}{ ... }
/* ... */
void http_server_init(void)
{
httpd_init();
http_set_ssi_handler(ADC_Handler, (char const **)TAGS, 1);
CGI_TAB[0] = LEDS_CGI;
http_set_cgi_handlers(CGI_TAB, 1);
}{ ... }