implement bmc gpio,
clkeanup some code
This commit is contained in:
parent
6aebefc748
commit
930ae5498a
4
cgi.h
4
cgi.h
@ -5,10 +5,6 @@
|
|||||||
#include "pico/cyw43_arch.h"
|
#include "pico/cyw43_arch.h"
|
||||||
#include "handlers.h"
|
#include "handlers.h"
|
||||||
|
|
||||||
char parseRequestedState (char * requested_state) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const char * cgi_power_handler (int iIndex, int iNumParams, char * pcParam [], char * pcValue []) {
|
const char * cgi_power_handler (int iIndex, int iNumParams, char * pcParam [], char * pcValue []) {
|
||||||
// Check if an request for power has been made (/power?requested_state=x)
|
// Check if an request for power has been made (/power?requested_state=x)
|
||||||
if (strcmp(pcParam[0] , "requested_state") == 0){
|
if (strcmp(pcParam[0] , "requested_state") == 0){
|
||||||
|
36
handlers.h
36
handlers.h
@ -3,36 +3,54 @@
|
|||||||
|
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
|
|
||||||
#define PW_SW_DELAY_MS 100
|
#define PW_SWITCH_PIN 0
|
||||||
#define STATE_UPDATE_REPEAT_DELAY_MS 100
|
#define PW_SWITCH_DELAY_MS 100
|
||||||
|
#define PW_STATE_PIN 1
|
||||||
|
#define PW_STATE_UPDATE_REPEAT_DELAY_MS 100
|
||||||
|
|
||||||
bool current_state = false;
|
bool current_state = false;
|
||||||
struct repeating_timer * state_update_timer = NULL;
|
struct repeating_timer * state_update_timer = NULL;
|
||||||
|
|
||||||
|
// handler fn to set the power switch pin to an active state
|
||||||
int64_t pw_sw_on_async (alarm_id_t id, void * user_data) {
|
int64_t pw_sw_on_async (alarm_id_t id, void * user_data) {
|
||||||
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
|
|
||||||
return 0; // do not reschedule alarm
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t pw_sw_off_async (alarm_id_t id, void * user_data) {
|
|
||||||
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);
|
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);
|
||||||
|
gpio_put(PW_SWITCH_PIN, 1);
|
||||||
return 0; // do not reschedule alarm
|
return 0; // do not reschedule alarm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handler fn to set the power switch pin to an inactive state
|
||||||
|
int64_t pw_sw_off_async (alarm_id_t id, void * user_data) {
|
||||||
|
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
|
||||||
|
gpio_put(PW_SWITCH_PIN, 0);
|
||||||
|
return 0; // do not reschedule alarm
|
||||||
|
}
|
||||||
|
|
||||||
|
// hander fn to read from the power state
|
||||||
bool update_current_state_async (repeating_timer_t * rt) {
|
bool update_current_state_async (repeating_timer_t * rt) {
|
||||||
|
current_state = gpio_get(PW_STATE_PIN);
|
||||||
return true; // continue repeating alarm
|
return true; // continue repeating alarm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handler fn called to attempt to set the power state to the requested state
|
||||||
bool bmc_power_handler (bool requested_state) {
|
bool bmc_power_handler (bool requested_state) {
|
||||||
if (requested_state != current_state) {
|
if (requested_state != current_state) {
|
||||||
add_alarm_in_ms(0, pw_sw_on_async, NULL, true);
|
add_alarm_in_ms(0, pw_sw_on_async, NULL, true);
|
||||||
add_alarm_in_ms(PW_SW_DELAY_MS, pw_sw_off_async, NULL, true);
|
add_alarm_in_ms(PW_SWITCH_DELAY_MS, pw_sw_off_async, NULL, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bmc_handler_init () {
|
void bmc_handler_init () {
|
||||||
|
// init power switch pin as output
|
||||||
|
gpio_init(PW_SWITCH_PIN);
|
||||||
|
gpio_set_dir(PW_SWITCH_DELAY_MS, GPIO_OUT);
|
||||||
|
|
||||||
|
// init power state pin as input
|
||||||
|
gpio_init(PW_STATE_PIN);
|
||||||
|
gpio_set_dir(PW_STATE_PIN, GPIO_IN);
|
||||||
|
|
||||||
|
// set repeating timer for power state update
|
||||||
state_update_timer = malloc(sizeof(struct repeating_timer));
|
state_update_timer = malloc(sizeof(struct repeating_timer));
|
||||||
add_repeating_timer_ms(STATE_UPDATE_REPEAT_DELAY_MS, update_current_state_async, NULL, state_update_timer);
|
add_repeating_timer_ms(PW_STATE_UPDATE_REPEAT_DELAY_MS, update_current_state_async, NULL, state_update_timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bmc_handler_deinit () {
|
void bmc_handler_deinit () {
|
||||||
|
7
main.c
7
main.c
@ -23,17 +23,24 @@ int main() {
|
|||||||
}
|
}
|
||||||
printf("Wi-Fi connected\n");
|
printf("Wi-Fi connected\n");
|
||||||
|
|
||||||
|
// init httpd
|
||||||
httpd_init();
|
httpd_init();
|
||||||
printf("HTTP Server initialized at %s on port %d\n", ip4addr_ntoa(netif_ip4_addr(netif_list)), HTTPD_SERVER_PORT);
|
printf("HTTP Server initialized at %s on port %d\n", ip4addr_ntoa(netif_ip4_addr(netif_list)), HTTPD_SERVER_PORT);
|
||||||
|
|
||||||
|
// enable ssi
|
||||||
ssi_init();
|
ssi_init();
|
||||||
printf("SSI Handler initialized\n");
|
printf("SSI Handler initialized\n");
|
||||||
|
|
||||||
|
// enable cgi
|
||||||
cgi_init();
|
cgi_init();
|
||||||
printf("CGI Handler initialised\n");
|
printf("CGI Handler initialised\n");
|
||||||
|
|
||||||
|
// init bmc handler
|
||||||
bmc_handler_init();
|
bmc_handler_init();
|
||||||
printf("BMC handler initialized\n");
|
printf("BMC handler initialized\n");
|
||||||
|
|
||||||
|
// set LED to on to indicate it has connected and initialized
|
||||||
|
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
|
||||||
|
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user