move pico libs to pico_lib.h,
add INV option to PW_SWITCH and PW_STATE
This commit is contained in:
parent
9da9e35393
commit
7aadd6d4e0
1
cgi.h
1
cgi.h
@ -2,7 +2,6 @@
|
|||||||
#define CGI_H
|
#define CGI_H
|
||||||
|
|
||||||
#include "lwip/apps/httpd.h"
|
#include "lwip/apps/httpd.h"
|
||||||
#include "pico/cyw43_arch.h"
|
|
||||||
#include "handlers.h"
|
#include "handlers.h"
|
||||||
|
|
||||||
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 []) {
|
||||||
|
12
handlers.h
12
handlers.h
@ -1,12 +1,12 @@
|
|||||||
#ifndef HANDLERS_H
|
#ifndef HANDLERS_H
|
||||||
#define HANDLERS_H
|
#define HANDLERS_H
|
||||||
|
|
||||||
#include "pico/stdlib.h"
|
|
||||||
|
|
||||||
#define PW_SWITCH_PIN 0
|
#define PW_SWITCH_PIN 0
|
||||||
#define PW_SWITCH_DELAY_MS 100
|
#define PW_SWITCH_DELAY_MS 100
|
||||||
|
#define PW_SWITCH_INV 0
|
||||||
#define PW_STATE_PIN 1
|
#define PW_STATE_PIN 1
|
||||||
#define PW_STATE_UPDATE_REPEAT_DELAY_MS 100
|
#define PW_STATE_UPDATE_REPEAT_DELAY_MS 100
|
||||||
|
#define PW_STATE_INV 1
|
||||||
|
|
||||||
bool current_state = false;
|
bool current_state = false;
|
||||||
struct repeating_timer * state_update_timer = NULL;
|
struct repeating_timer * state_update_timer = NULL;
|
||||||
@ -14,25 +14,25 @@ struct repeating_timer * state_update_timer = NULL;
|
|||||||
// handler fn to set the power switch pin to an active state
|
// 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, 0);
|
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);
|
||||||
gpio_put(PW_SWITCH_PIN, 1);
|
gpio_put(PW_SWITCH_PIN, 1 ^ PW_SWITCH_INV);
|
||||||
return 0; // do not reschedule alarm
|
return 0; // do not reschedule alarm
|
||||||
}
|
}
|
||||||
|
|
||||||
// handler fn to set the power switch pin to an inactive state
|
// 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) {
|
int64_t pw_sw_off_async (alarm_id_t id, void * user_data) {
|
||||||
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
|
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
|
||||||
gpio_put(PW_SWITCH_PIN, 0);
|
gpio_put(PW_SWITCH_PIN, 0 ^ PW_SWITCH_INV);
|
||||||
return 0; // do not reschedule alarm
|
return 0; // do not reschedule alarm
|
||||||
}
|
}
|
||||||
|
|
||||||
// hander fn to read from the power state
|
// 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);
|
current_state = gpio_get(PW_STATE_PIN) ^ PW_STATE_INV;
|
||||||
return true; // continue repeating alarm
|
return true; // continue repeating alarm
|
||||||
}
|
}
|
||||||
|
|
||||||
// handler fn called to attempt to set the power state to the requested state
|
// handler fn called to attempt to set the power state to the requested state
|
||||||
bool bmc_power_handler (bool requested_state) {
|
void 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_SWITCH_DELAY_MS, pw_sw_off_async, NULL, true);
|
add_alarm_in_ms(PW_SWITCH_DELAY_MS, pw_sw_off_async, NULL, true);
|
||||||
|
3
main.c
3
main.c
@ -1,6 +1,5 @@
|
|||||||
#include "lwip/apps/httpd.h"
|
#include "lwip/apps/httpd.h"
|
||||||
#include "pico/stdlib.h"
|
#include "pico_lib.h"
|
||||||
#include "pico/cyw43_arch.h"
|
|
||||||
#include "lwipopts.h"
|
#include "lwipopts.h"
|
||||||
#include "ssi.h"
|
#include "ssi.h"
|
||||||
#include "cgi.h"
|
#include "cgi.h"
|
||||||
|
8
pico_lib.h
Normal file
8
pico_lib.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef PICO_LIB_H
|
||||||
|
#define PICO_LIB_H
|
||||||
|
|
||||||
|
#include "pico/cyw43_arch.h"
|
||||||
|
#include "pico/stdlib.h"
|
||||||
|
#include "hardware/adc.h"
|
||||||
|
|
||||||
|
#endif
|
2
ssi.h
2
ssi.h
@ -2,8 +2,6 @@
|
|||||||
#define SSI_H
|
#define SSI_H
|
||||||
|
|
||||||
#include "lwip/apps/httpd.h"
|
#include "lwip/apps/httpd.h"
|
||||||
#include "pico/cyw43_arch.h"
|
|
||||||
#include "hardware/adc.h"
|
|
||||||
#include "handlers.h"
|
#include "handlers.h"
|
||||||
|
|
||||||
const char * ssi_tags[] = {"volt", "temp", "power"};
|
const char * ssi_tags[] = {"volt", "temp", "power"};
|
||||||
|
Loading…
Reference in New Issue
Block a user