2024-02-14 05:05:01 +00:00
|
|
|
#ifndef SSI_H
|
|
|
|
#define SSI_H
|
|
|
|
|
2024-02-14 02:01:59 +00:00
|
|
|
#include "lwip/apps/httpd.h"
|
2024-02-14 05:05:01 +00:00
|
|
|
#include "handlers.h"
|
2024-02-14 02:01:59 +00:00
|
|
|
|
2024-02-14 05:05:01 +00:00
|
|
|
const char * ssi_tags[] = {"volt", "temp", "power"};
|
2024-02-14 02:01:59 +00:00
|
|
|
|
|
|
|
u16_t ssi_handler(int iIndex, char *pcInsert, int iInsertLen) {
|
|
|
|
size_t printed;
|
|
|
|
switch (iIndex) {
|
|
|
|
case 0: // volt
|
|
|
|
{
|
2024-02-14 05:05:01 +00:00
|
|
|
const float voltage = adc_read() * 3.3f / (1 << 12);
|
|
|
|
printed = snprintf(pcInsert, iInsertLen, "%f", voltage);
|
2024-02-14 02:01:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1: // temp
|
|
|
|
{
|
2024-02-14 05:05:01 +00:00
|
|
|
const float voltage = adc_read() * 3.3f / (1 << 12);
|
|
|
|
const float tempC = 27.0f - (voltage - 0.706f) / 0.001721f;
|
|
|
|
printed = snprintf(pcInsert, iInsertLen, "%f", tempC);
|
2024-02-14 02:01:59 +00:00
|
|
|
}
|
|
|
|
break;
|
2024-02-14 05:05:01 +00:00
|
|
|
case 2: // power
|
2024-02-14 02:01:59 +00:00
|
|
|
{
|
2024-02-14 05:05:01 +00:00
|
|
|
printed = snprintf(pcInsert, iInsertLen, "%d", current_state);
|
2024-02-14 02:01:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2024-02-14 05:05:01 +00:00
|
|
|
{
|
|
|
|
printed = 0;
|
|
|
|
}
|
2024-02-14 02:01:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-02-14 05:05:01 +00:00
|
|
|
return (u16_t) printed;
|
2024-02-14 02:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ssi_init() {
|
|
|
|
adc_init();
|
|
|
|
adc_set_temp_sensor_enabled(true);
|
|
|
|
adc_select_input(4);
|
|
|
|
http_set_ssi_handler(ssi_handler, ssi_tags, LWIP_ARRAYSIZE(ssi_tags));
|
2024-02-14 05:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|