Skip to content
Snippets Groups Projects

Car leds

Merged Jan Schmitz requested to merge car_leds into master
All threads resolved!
Files
3
+ 56
30
@@ -12,8 +12,8 @@
@@ -12,8 +12,8 @@
#include "freertos/semphr.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
#include "freertos/task.h"
/*#include "ina233.h"*/
/*#include "ina233.h"*/
#include "leds.h"
#include "hal/dac_types.h"
#include "hal/dac_types.h"
 
#include "leds.h"
#include "legos_common.h"
#include "legos_common.h"
#include "legos_fs.h"
#include "legos_fs.h"
#include "legos_http.h"
#include "legos_http.h"
@@ -98,7 +98,7 @@ static hospital_status entity = { .id = 0,
@@ -98,7 +98,7 @@ static hospital_status entity = { .id = 0,
.power_source = GRID,
.power_source = GRID,
.led_intensity = 0.5,
.led_intensity = 0.5,
.status = EMERGENCY_NONE,
.status = EMERGENCY_NONE,
.power_in = { 0.0, 0.0, 0.0 }};
.power_in = { 0.0, 0.0, 0.0 } };
typedef struct hospial_overrides {
typedef struct hospial_overrides {
emergency_t remote;
emergency_t remote;
@@ -113,6 +113,7 @@ typedef struct hospital_control {
@@ -113,6 +113,7 @@ typedef struct hospital_control {
id_bus id_bus;
id_bus id_bus;
pca9956_t pca;
pca9956_t pca;
ups_leds_t ups_led;
ups_leds_t ups_led;
 
car_leds_t car_led;
virtual_load_t virtual_load;
virtual_load_t virtual_load;
// TODO: GPIO
// TODO: GPIO
} hospital_control;
} hospital_control;
@@ -240,26 +241,32 @@ void entity_main_tasks(void* arg)
@@ -240,26 +241,32 @@ void entity_main_tasks(void* arg)
entity.status = (!gpio_get_level(PIN_SENS_CAR))
entity.status = (!gpio_get_level(PIN_SENS_CAR))
| ((!gpio_get_level(PIN_SENS_HELI)) << 0x01) | overrides.remote;
| ((!gpio_get_level(PIN_SENS_HELI)) << 0x01) | overrides.remote;
switch (entity.status) {
// switch LEDs acccording to status
case EMERGENCY_NONE:
if (entity.ups.charge_level > 0.01) {
pwm_switch(LED_ROOM_0, LED_INTENSITY_0);
switch (entity.status) {
pwm_switch(LED_ROOM_1, LED_INTENSITY_0);
case EMERGENCY_NONE:
break;
car_leds_enable(&control->car_led, false);
pwm_switch(LED_ROOM_1, LED_INTENSITY_0);
case EMERGENCY_CAR:
break;
pwm_switch(LED_ROOM_0, led_intensity);
 
case EMERGENCY_CAR:
 
car_leds_enable(&control->car_led, true);
 
pwm_switch(LED_ROOM_1, LED_INTENSITY_0);
 
break;
 
 
case EMERGENCY_HELI:
 
car_leds_enable(&control->car_led, false);
 
pwm_switch(LED_ROOM_1, led_intensity);
 
break;
 
 
case EMERGENCY_BOTH:
 
car_leds_enable(&control->car_led, true);
 
pwm_switch(LED_ROOM_1, led_intensity);
 
break;
 
}
 
} else {
 
car_leds_enable(&control->car_led, false);
pwm_switch(LED_ROOM_1, LED_INTENSITY_0);
pwm_switch(LED_ROOM_1, LED_INTENSITY_0);
break;
case EMERGENCY_HELI:
pwm_switch(LED_ROOM_0, LED_INTENSITY_0);
pwm_switch(LED_ROOM_1, led_intensity);
break;
case EMERGENCY_BOTH:
pwm_switch(LED_ROOM_0, led_intensity);
pwm_switch(LED_ROOM_1, led_intensity);
break;
}
}
// check bus voltage.
// check bus voltage.
@@ -273,13 +280,32 @@ void entity_main_tasks(void* arg)
@@ -273,13 +280,32 @@ void entity_main_tasks(void* arg)
}
}
// virtual load
// virtual load
if(entity.ups.charge_level < 99){ //more load while charging
float load_percent = 0.1;
virtual_load_set_percent(&control->virtual_load, 0.5);
float ups_charge_rate = 0.1;
 
if (entity.ups.charge_level < 99) { // more load while charging
 
load_percent += 0.4;
 
}
 
if (entity.status == EMERGENCY_CAR) {
 
load_percent += 0.13;
 
ups_charge_rate += 0.13;
 
}
 
if (entity.status == EMERGENCY_HELI) {
 
load_percent += 0.27;
 
ups_charge_rate += 0.27;
 
}
 
if (entity.status == EMERGENCY_BOTH) {
 
load_percent += 0.4;
 
ups_charge_rate += 0.4;
}
}
else{
if (entity.ups.charge_level > 0.1) {
virtual_load_set_percent(&control->virtual_load, 0.1);
virtual_load_set_percent(&control->virtual_load, load_percent);
}
}
ESP_LOGI(TAG,"Voltage in mA: %f", entity.ups.charge_level);
 
// set charge/discharge rate of ups according to load
 
entity.ups.charge_rate = 10 * (1 - 2 * ups_charge_rate);
 
entity.ups.discharge_rate = 10 * 2 * ups_charge_rate;
 
 
ESP_LOGI(TAG, "Voltage in mA: %f", entity.ups.charge_level);
// ups led
// ups led
ups_leds_set_perc(&control->ups_led, entity.ups.charge_level, false);
ups_leds_set_perc(&control->ups_led, entity.ups.charge_level, false);
@@ -325,8 +351,7 @@ esp_err_t init_pwm()
@@ -325,8 +351,7 @@ esp_err_t init_pwm()
&pwm_timer)); // Set configuration of timer1 for high speed channels
&pwm_timer)); // Set configuration of timer1 for high speed channels
// Set LED Controller with previously prepared configuration
// Set LED Controller with previously prepared configuration
for (int ch = 0; ch < LED_MAX; ch++){
for (int ch = 0; ch < LED_MAX; ch++) {
ESP_LOGD(TAG, "config channel %d", ch);
ESP_LOGD(TAG, "config channel %d", ch);
ESP_ERROR_CHECK(ledc_channel_config(&pwm_channel[ch]));
ESP_ERROR_CHECK(ledc_channel_config(&pwm_channel[ch]));
}
}
@@ -386,14 +411,15 @@ void init_entity(hospital_control* control)
@@ -386,14 +411,15 @@ void init_entity(hospital_control* control)
ESP_ERROR_CHECK(set_calibration(&control->power_mon,
ESP_ERROR_CHECK(set_calibration(&control->power_mon,
atof(CONFIG_PWR_MON_R_SHUNT), atof(CONFIG_PWR_MON_I_MAX)));
atof(CONFIG_PWR_MON_R_SHUNT), atof(CONFIG_PWR_MON_I_MAX)));
//init virtual ups
// init virtual ups
entity.ups.charge_level = 50.0;
entity.ups.charge_level = 50.0;
entity.ups.charge_rate = 10.0;
entity.ups.charge_rate = 10.0;
entity.ups.discharge_rate = 5.0;
entity.ups.discharge_rate = 10.0;
// init leds
// init leds
control->pca = pca9956_init(CONFIG_PWR_MON_I2C_BUS, 0x19, 2000, 19);
control->pca = pca9956_init(CONFIG_PWR_MON_I2C_BUS, 0x19, 2000, 19);
control->ups_led = init_ups_leds(&control->pca);
control->ups_led = init_ups_leds(&control->pca);
 
control->car_led = init_car_leds(&control->pca);
ups_leds_startup_animation(&control->ups_led);
ups_leds_startup_animation(&control->ups_led);
ESP_LOGD(TAG, "Charge Level %f", entity.ups.charge_level);
ESP_LOGD(TAG, "Charge Level %f", entity.ups.charge_level);
Loading