Add GPIO initialization, logging
This commit is contained in:
parent
95f2403163
commit
30e9411a2e
@ -26,12 +26,31 @@ static const char * TAG = "chair-adjustment";
|
|||||||
//current motor states
|
//current motor states
|
||||||
static restState_t stateLegRest = REST_OFF;
|
static restState_t stateLegRest = REST_OFF;
|
||||||
static restState_t stateBackRest = REST_OFF;
|
static restState_t stateBackRest = REST_OFF;
|
||||||
|
bool isInitialized = false;
|
||||||
|
|
||||||
|
|
||||||
//TODO Add timestamps or even a task to keep track of current position (estimate)
|
//TODO Add timestamps or even a task to keep track of current position (estimate)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//====================
|
||||||
|
//======= init =======
|
||||||
|
//====================
|
||||||
|
//init gpio pins for relays
|
||||||
|
void chairAdjust_init(){
|
||||||
|
ESP_LOGW(TAG, "initializing gpio pins for relays...");
|
||||||
|
gpio_pad_select_gpio(GPIO_LEGREST_UP);
|
||||||
|
gpio_set_direction(GPIO_LEGREST_UP, GPIO_MODE_OUTPUT);
|
||||||
|
gpio_pad_select_gpio(GPIO_LEGREST_DOWN);
|
||||||
|
gpio_set_direction(GPIO_LEGREST_DOWN, GPIO_MODE_OUTPUT);
|
||||||
|
gpio_pad_select_gpio(GPIO_BACKREST_UP);
|
||||||
|
gpio_set_direction(GPIO_BACKREST_UP, GPIO_MODE_OUTPUT);
|
||||||
|
gpio_pad_select_gpio(GPIO_BACKREST_DOWN);
|
||||||
|
gpio_set_direction(GPIO_BACKREST_DOWN, GPIO_MODE_OUTPUT);
|
||||||
|
isInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=============================
|
//=============================
|
||||||
//======= set direction =======
|
//======= set direction =======
|
||||||
@ -40,42 +59,48 @@ static restState_t stateBackRest = REST_OFF;
|
|||||||
//TODO evaluate if separate functions needed, can be merged with run..Rest(state) function?
|
//TODO evaluate if separate functions needed, can be merged with run..Rest(state) function?
|
||||||
//--- leg-rest ---
|
//--- leg-rest ---
|
||||||
void setLegrestUp(){
|
void setLegrestUp(){
|
||||||
gpio_set_level(GPIO_LEGREST_DOWN, 0);
|
if (!isInitialized) chairAdjust_init();
|
||||||
gpio_set_level(GPIO_LEGREST_UP, 1);
|
gpio_set_level(GPIO_LEGREST_DOWN, 0);
|
||||||
stateLegRest = REST_UP;
|
gpio_set_level(GPIO_LEGREST_UP, 1);
|
||||||
ESP_LOGD(TAG, "switched relays to move leg-rest UP");
|
stateLegRest = REST_UP;
|
||||||
|
ESP_LOGD(TAG, "switched relays to move leg-rest UP");
|
||||||
}
|
}
|
||||||
void setLegrestDown(){
|
void setLegrestDown(){
|
||||||
gpio_set_level(GPIO_LEGREST_DOWN, 1);
|
if (!isInitialized) chairAdjust_init();
|
||||||
gpio_set_level(GPIO_LEGREST_UP, 0);
|
gpio_set_level(GPIO_LEGREST_DOWN, 1);
|
||||||
stateLegRest = REST_DOWN;
|
gpio_set_level(GPIO_LEGREST_UP, 0);
|
||||||
ESP_LOGD(TAG, "switched relays to move leg-rest DOWN");
|
stateLegRest = REST_DOWN;
|
||||||
|
ESP_LOGD(TAG, "switched relays to move leg-rest DOWN");
|
||||||
}
|
}
|
||||||
void setLegrestOff(){
|
void setLegrestOff(){
|
||||||
gpio_set_level(GPIO_LEGREST_DOWN, 0);
|
if (!isInitialized) chairAdjust_init();
|
||||||
gpio_set_level(GPIO_LEGREST_UP, 0);
|
gpio_set_level(GPIO_LEGREST_DOWN, 0);
|
||||||
stateLegRest = REST_OFF;
|
gpio_set_level(GPIO_LEGREST_UP, 0);
|
||||||
ESP_LOGD(TAG, "switched relays for leg-rest OFF");
|
stateLegRest = REST_OFF;
|
||||||
|
ESP_LOGD(TAG, "switched relays for leg-rest OFF");
|
||||||
}
|
}
|
||||||
|
|
||||||
//--- back-rest ---
|
//--- back-rest ---
|
||||||
void setBackrestUp(){
|
void setBackrestUp(){
|
||||||
gpio_set_level(GPIO_BACKREST_DOWN, 0);
|
if (!isInitialized) chairAdjust_init();
|
||||||
gpio_set_level(GPIO_BACKREST_UP, 1);
|
gpio_set_level(GPIO_BACKREST_DOWN, 0);
|
||||||
stateBackRest = REST_UP;
|
gpio_set_level(GPIO_BACKREST_UP, 1);
|
||||||
ESP_LOGD(TAG, "switched relays to move back-rest UP");
|
stateBackRest = REST_UP;
|
||||||
|
ESP_LOGD(TAG, "switched relays to move back-rest UP");
|
||||||
}
|
}
|
||||||
void setBackrestDown(){
|
void setBackrestDown(){
|
||||||
gpio_set_level(GPIO_BACKREST_DOWN, 1);
|
if (!isInitialized) chairAdjust_init();
|
||||||
gpio_set_level(GPIO_BACKREST_UP, 0);
|
gpio_set_level(GPIO_BACKREST_DOWN, 1);
|
||||||
stateBackRest = REST_DOWN;
|
gpio_set_level(GPIO_BACKREST_UP, 0);
|
||||||
ESP_LOGD(TAG, "switched relays to move back-rest DOWN");
|
stateBackRest = REST_DOWN;
|
||||||
|
ESP_LOGD(TAG, "switched relays to move back-rest DOWN");
|
||||||
}
|
}
|
||||||
void setBackrestOff(){
|
void setBackrestOff(){
|
||||||
gpio_set_level(GPIO_BACKREST_DOWN, 0);
|
if (!isInitialized) chairAdjust_init();
|
||||||
gpio_set_level(GPIO_BACKREST_UP, 0);
|
gpio_set_level(GPIO_BACKREST_DOWN, 0);
|
||||||
stateBackRest = REST_OFF;
|
gpio_set_level(GPIO_BACKREST_UP, 0);
|
||||||
ESP_LOGD(TAG, "switched relays for back-rest OFF");
|
stateBackRest = REST_OFF;
|
||||||
|
ESP_LOGD(TAG, "switched relays for back-rest OFF");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user