Skip to content

Commit

Permalink
Merge pull request #13 from ElectronicCats/dev
Browse files Browse the repository at this point in the history
feat: Add changes for badge compatibilities
  • Loading branch information
JahazielLem authored Oct 11, 2024
2 parents 0c12965 + 6796513 commit a21a623
Show file tree
Hide file tree
Showing 53 changed files with 1,032 additions and 535 deletions.
9 changes: 9 additions & 0 deletions firmware/components/buzzer/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
menu "Buzzer Configuration"

config BUZZER_COMPONENT_ENABLED
bool "Enable buzzer component"
default true
help
Enable the buzzer component.

endmenu
37 changes: 37 additions & 0 deletions firmware/components/buzzer/buzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,32 @@ typedef struct {
static buzzer_t buzzer;

void buzzer_enable() {
#ifndef CONFIG_BUZZER_COMPONENT_ENABLED
return;
#endif

buzzer.enabled = true;
}

void buzzer_disable() {
buzzer.enabled = false;
}

void buzzer_begin(uint8_t pin) {
#ifndef CONFIG_BUZZER_COMPONENT_ENABLED
return;
#endif

buzzer.pin = pin;
buzzer.freq = BUZZER_DEFAULT_FREQUENCY_HZ;
buzzer.duty = BUZZER_DEFAULT_DUTTY;
}

void buzzer_configure() {
#ifndef CONFIG_BUZZER_COMPONENT_ENABLED
return;
#endif

// Prepare and then apply the LEDC PWM timer configuration
ledc_timer_config_t ledc_timer = {.speed_mode = LEDC_MODE,
.duty_resolution = LEDC_DUTY_RES,
Expand All @@ -57,14 +70,26 @@ void buzzer_configure() {
}

void buzzer_set_freq(uint32_t freq) {
#ifndef CONFIG_BUZZER_COMPONENT_ENABLED
return;
#endif

buzzer.freq = freq;
}

void buzzer_set_duty(uint32_t duty) {
#ifndef CONFIG_BUZZER_COMPONENT_ENABLED
return;
#endif

buzzer.duty = duty;
}

void buzzer_play() {
#ifndef CONFIG_BUZZER_COMPONENT_ENABLED
return;
#endif

if (!buzzer.enabled) {
return;
}
Expand All @@ -75,6 +100,10 @@ void buzzer_play() {
}

void buzzer_play_for_task(void* duration) {
#ifndef CONFIG_BUZZER_COMPONENT_ENABLED
return;
#endif

uint32_t dur = *(uint32_t*) duration;
buzzer_play();
vTaskDelay(*(uint32_t*) duration / portTICK_PERIOD_MS);
Expand All @@ -83,6 +112,10 @@ void buzzer_play_for_task(void* duration) {
}

void buzzer_play_for(uint32_t duration) {
#ifndef CONFIG_BUZZER_COMPONENT_ENABLED
return;
#endif

if (!buzzer.enabled) {
return;
}
Expand All @@ -93,6 +126,10 @@ void buzzer_play_for(uint32_t duration) {
}

void buzzer_stop() {
#ifndef CONFIG_BUZZER_COMPONENT_ENABLED
return;
#endif

ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 0));
ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));

Expand Down
26 changes: 23 additions & 3 deletions firmware/components/cmd_wifi/cmd_wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,27 @@ static void cmd_wifi_delete_crendentials(int argc, char** argv) {
preferences_remove(wifi_ssid);
ESP_LOGI(__func__, "Deleted AP %s", wifi_ssid);

// Restore the AP indexes
int counter = 0;
for (int i = 0; i < count - 1; i++) {
char wifi_ap[100];
char wifi_ssid[100];
sprintf(wifi_ap, "wifi%d", i);
esp_err_t err = preferences_get_string(wifi_ap, wifi_ssid, 100);
if (err != ESP_OK) {
continue;
}
char wifi_pass[100];
err = preferences_get_string(wifi_ssid, wifi_pass, 100);
if (err != ESP_OK) {
continue;
}
char wifi_ap_new[100];
sprintf(wifi_ap_new, "wifi%d", counter);
preferences_put_string(wifi_ap_new, wifi_ssid);
counter++;
}

preferences_put_int("count_ap", count - 1);
}

Expand Down Expand Up @@ -164,8 +185,7 @@ static int cmd_wifi_show_aps(int argc, char** argv) {
sprintf(wifi_ap, "wifi%d", i);
esp_err_t err = preferences_get_string(wifi_ap, wifi_ssid, 100);
if (err != ESP_OK) {
ESP_LOGW(__func__, "Error getting AP");
return 1;
continue;
}
printf("[%i][%s] SSID: %s\n", i, wifi_ap, wifi_ssid);
}
Expand Down Expand Up @@ -199,8 +219,8 @@ static void event_handler(void* arg,
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
printf("Connected to AP");
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
preferences_put_bool("wifi_connected", true);
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
}
}

Expand Down
9 changes: 9 additions & 0 deletions firmware/components/leds/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
menu "LEDs Configuration"

config LEDS_COMPONENT_ENABLED
bool "Enable LEDs component"
default true
help
Enable the LEDs component.

endmenu
48 changes: 48 additions & 0 deletions firmware/components/leds/leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
static led_t *left_led, *right_led;

void leds_begin() {
#ifndef CONFIG_LEDS_COMPONENT_ENABLED
return;
#endif

left_led = (led_t*) malloc(sizeof(led_t));
right_led = (led_t*) malloc(sizeof(led_t));
*left_led = led_controller_led_new(LEFT_LED_IO, LEFT_LED_CHANNEL);
Expand All @@ -23,6 +27,10 @@ void leds_begin() {
}

void leds_deinit() {
#ifndef CONFIG_LEDS_COMPONENT_ENABLED
return;
#endif

if (!left_led || !right_led) {
return;
}
Expand All @@ -35,32 +43,60 @@ void leds_deinit() {
}

void leds_on() {
#ifndef CONFIG_LEDS_COMPONENT_ENABLED
return;
#endif

led_controller_led_on(left_led);
led_controller_led_on(right_led);
}

void leds_off() {
#ifndef CONFIG_LEDS_COMPONENT_ENABLED
return;
#endif

led_controller_led_off(left_led);
led_controller_led_off(right_led);
}

void leds_set_brightness(uint8_t led, uint8_t brightness) {
#ifndef CONFIG_LEDS_COMPONENT_ENABLED
return;
#endif

led_controller_set_duty(led == LED_LEFT ? left_led : right_led, brightness);
}

void led_left_on() {
#ifndef CONFIG_LEDS_COMPONENT_ENABLED
return;
#endif

led_controller_led_on(left_led);
}

void led_left_off() {
#ifndef CONFIG_LEDS_COMPONENT_ENABLED
return;
#endif

led_controller_led_off(left_led);
}

void led_right_on() {
#ifndef CONFIG_LEDS_COMPONENT_ENABLED
return;
#endif

led_controller_led_on(right_led);
}

void led_right_off() {
#ifndef CONFIG_LEDS_COMPONENT_ENABLED
return;
#endif

led_controller_led_off(right_led);
}

Expand All @@ -70,14 +106,26 @@ void led_start_blink(uint8_t led,
uint32_t time_on,
uint32_t time_off,
uint32_t time_out) {
#ifndef CONFIG_LEDS_COMPONENT_ENABLED
return;
#endif

led_controller_start_blink_effect(led == LED_LEFT ? left_led : right_led,
duty, pulse_count, time_on, time_off,
time_out);
}
void led_start_breath(uint8_t led, uint16_t period_ms) {
#ifndef CONFIG_LEDS_COMPONENT_ENABLED
return;
#endif

led_controller_start_breath_effect(led == LED_LEFT ? left_led : right_led,
period_ms);
}
void led_stop(uint8_t led) {
#ifndef CONFIG_LEDS_COMPONENT_ENABLED
return;
#endif

led_controller_stop_any_effect(led == LED_LEFT ? left_led : right_led);
}
8 changes: 8 additions & 0 deletions firmware/components/minino_config/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -716,4 +716,12 @@ config FILE_MANAGER_WEB
Enable or disable the Web File Manager Feature.
endif # FILE_MANAGER_ENABLE

########################### SD_CARD #############################

config SD_CARD
bool "Enable SD Card Menus"
default true
help
Enable or disable SD Card Menus.

endmenu
35 changes: 24 additions & 11 deletions firmware/components/sd_card/include/sd_card.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <stdint.h>
#include "esp_err.h"

#define ESP_ERR_ALREADY_MOUNTED ESP_ERR_NOT_ALLOWED
#define ESP_ERR_NOT_MOUNTED ESP_ERR_NOT_FOUND
#define ESP_ERR_FILE_EXISTS ESP_ERR_NOT_ALLOWED
#define ESP_ERR_FILE_OPEN_FAILED ESP_FAIL
#define ESP_ERR_FILE_WRITE_FAILED ESP_FAIL
Expand All @@ -29,10 +27,9 @@ void sd_card_begin();
*
* @return esp_err_t
*
* @note return ESP_ERR_NOT_FOUND if the SD card is not found.
* @note return ESP_ERR_NO_MEM if failed to initialize the spi bus.
* @note return ESP_ERR_NOT_SUPPORTED if the SD card is not formatted with FAT.
* @note return ESP_ERR_INVALID_ARG if the arguments are invalid.
* @note return ESP_ERR_NOT_FOUND if the SD card is not found.
* @note return ESP_FAIL if the operation failed.
* @note return ESP_OK if the operation was successful or the card is already
* mounted.
Expand All @@ -44,20 +41,29 @@ esp_err_t sd_card_mount();
*
* @return esp_err_t
*
* @note return ESP_ERR_NOT_MOUNTED if the SD card is not mounted.
* @note return ESP_ERR_NOT_FOUND if the SD card is not mounted.
* @note return ESP_FAIL if the operation failed.
* @note return ESP_OK if the operation was successful.
*/
esp_err_t sd_card_unmount();

/**
* Format the SD card if mount failed.
* Mount the SD card.
*
* @return esp_err_t
*
* @note return ESP_ERR_NOT_MOUNTED if the SD card is not mounted.
* @note return ESP_ERR_NO_MEM if failed to initialize the spi bus.
* @note return ESP_ERR_NOT_SUPPORTED if the SD card is not formatted with FAT.
* @note return ESP_ERR_INVALID_ARG if the arguments are invalid.
* @note return ESP_FAIL if the operation failed.
* @note return ESP_OK if the operation was successful.
* @note return ESP_OK if the operation was successful or the card is already
* mounted.
*/
esp_err_t sd_card_check_format();

/**
* Format the SD card.
*
* @return esp_err_t
*/
esp_err_t sd_card_format();

Expand All @@ -68,14 +74,21 @@ esp_err_t sd_card_format();
*/
bool sd_card_is_mounted();

/**
* Check if the SD card is not mounted.
*
* return bool
*/
bool sd_card_is_not_mounted();

/**
* @brief Create a directory in the SD card.
*
* @param dir_name The name of the directory to create.
*
* @return esp_err_t
*
* @note return ESP_ERR_NOT_MOUNTED if the SD card is not mounted.
* @note return ESP_ERR_NOT_FOUND if the SD card is not mounted.
* @note return ESP_OK if the operation was successful or the directory already
* exists.
* @note return ESP_FAIL if the operation failed.
Expand All @@ -89,7 +102,7 @@ esp_err_t sd_card_create_dir(const char* dir_name);
*
* @return esp_err_t
*
* @note return ESP_ERR_NOT_MOUNTED if the SD card is not mounted.
* @note return ESP_ERR_NOT_FOUND if the SD card is not mounted.
* @note return ESP_ERR_FILE_EXISTS if the file already exists.
* @note return ESP_FAIL if the operation failed.
* @note return ESP_OK if the operation was successful.
Expand Down
Loading

0 comments on commit a21a623

Please sign in to comment.