kopia lustrzana https://github.com/maxnet/pico-webserver
56 wiersze
1.1 KiB
C
56 wiersze
1.1 KiB
C
#include "pico/stdlib.h"
|
|
#include "pico/bootrom.h"
|
|
#include "hardware/watchdog.h"
|
|
#include "hardware/structs/watchdog.h"
|
|
|
|
#include "tusb_lwip_glue.h"
|
|
|
|
#define LED_PIN 25
|
|
|
|
// let our webserver do some dynamic handling
|
|
static const char *cgi_toggle_led(int iIndex, int iNumParams, char *pcParam[], char *pcValue[])
|
|
{
|
|
gpio_put(LED_PIN, !gpio_get(LED_PIN));
|
|
return "/index.html";
|
|
}
|
|
|
|
static const char *cgi_reset_usb_boot(int iIndex, int iNumParams, char *pcParam[], char *pcValue[])
|
|
{
|
|
reset_usb_boot(0, 0);
|
|
return "/index.html";
|
|
}
|
|
|
|
static const tCGI cgi_handlers[] = {
|
|
{
|
|
"/toggle_led",
|
|
cgi_toggle_led
|
|
},
|
|
{
|
|
"/reset_usb_boot",
|
|
cgi_reset_usb_boot
|
|
}
|
|
};
|
|
|
|
|
|
int main()
|
|
{
|
|
// Initialize tinyusb, lwip, dhcpd and httpd
|
|
init_lwip();
|
|
wait_for_netif_is_up();
|
|
dhcpd_init();
|
|
httpd_init();
|
|
http_set_cgi_handlers(cgi_handlers, LWIP_ARRAYSIZE(cgi_handlers));
|
|
|
|
// For toggle_led
|
|
gpio_init(LED_PIN);
|
|
gpio_set_dir(LED_PIN, GPIO_OUT);
|
|
|
|
while (true)
|
|
{
|
|
tud_task();
|
|
service_traffic();
|
|
}
|
|
|
|
return 0;
|
|
}
|