Sun, 16 Apr 2023 12:27:12 +0200
Preparations for BLE GATT. Added extra time after INA219 is powered on before measurement. Reduced LEDC frequency to 60 Hz, that makes the LED lights less nervous. Hardware mod on output 4, now needs external pulldown resistor.
9
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /** |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * @file task_out.c |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * @brief The FreeRTOS task to drive the outputs. |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | */ |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | #include "config.h" |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | static const char *TAG = "task_out"; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | #define OutputPin1 CONFIG_OUT1_PIN |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | #define OutputPin2 CONFIG_OUT2_PIN |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | #define OutputPin3 CONFIG_OUT3_PIN |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | #define OutputPin4 CONFIG_OUT4_PIN |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | SemaphoreHandle_t xSemaphoreOUT = NULL; ///< Semaphore OUT task |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | OUT_State *out_state; ///< Public state for other tasks |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | extern uint32_t Alarm; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | extern uint8_t Relay1; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | extern uint8_t Relay2; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | extern uint8_t Dimmer3; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | extern uint8_t Dimmer4; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | /* |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | * Task to drive the outputs. |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | */ |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | void task_out(void *pvParameter) |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | { |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | int val; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | ESP_LOGI(TAG, "Starting task OUT %d %d %d %d", Relay1, Relay2, Dimmer3, Dimmer4); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | xSemaphoreOUT = xSemaphoreCreateMutex(); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | out_state = malloc(sizeof(OUT_State)); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | out_state->error = OUT_ERR_NONE; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | out_state->out1 = 0; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | out_state->out2 = 0; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | out_state->out3 = 0; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | out_state->out4 = 0; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
45 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | gpio_reset_pin(OutputPin1); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | gpio_reset_pin(OutputPin2); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | gpio_reset_pin(OutputPin3); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | gpio_reset_pin(OutputPin4); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
51 | gpio_set_direction(OutputPin1, GPIO_MODE_OUTPUT); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
52 | gpio_set_direction(OutputPin2, GPIO_MODE_OUTPUT); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
53 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | /* |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
55 | * Prepare the LEDC PWM channels |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | */ |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
57 | ledc_timer_config_t ledc_timer = { |
30
7448b8dd4288
Preparations for BLE GATT. Added extra time after INA219 is powered on before measurement. Reduced LEDC frequency to 60 Hz, that makes the LED lights less nervous. Hardware mod on output 4, now needs external pulldown resistor.
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
58 | .speed_mode = LEDC_LOW_SPEED_MODE, ///< Use high speed timer |
9
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
59 | .timer_num = LEDC_TIMER_0, ///< Timer 0 |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
60 | .duty_resolution = LEDC_TIMER_10_BIT, ///< 10 bits resolution |
30
7448b8dd4288
Preparations for BLE GATT. Added extra time after INA219 is powered on before measurement. Reduced LEDC frequency to 60 Hz, that makes the LED lights less nervous. Hardware mod on output 4, now needs external pulldown resistor.
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
61 | .freq_hz = 60, ///< 60 Hz |
9
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
62 | .clk_cfg = LEDC_AUTO_CLK ///< Auto select PWM clock |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
63 | }; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
64 | ledc_timer_config(&ledc_timer); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | ledc_channel_config_t dimmer_channel3 = { |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | .channel = LEDC_CHANNEL_0, |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
68 | .duty = 0, ///< Default 0% |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
69 | .gpio_num = OutputPin3, ///< Dimmer3 pin |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
70 | .speed_mode = LEDC_LOW_SPEED_MODE, |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
71 | .hpoint = 0, |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
72 | .intr_type = LEDC_INTR_DISABLE, |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
73 | .timer_sel = LEDC_TIMER_0 ///< Timer 0 |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
74 | }; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
75 | ledc_channel_config(&dimmer_channel3); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
76 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
77 | ledc_channel_config_t dimmer_channel4 = { |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
78 | .channel = LEDC_CHANNEL_1, |
30
7448b8dd4288
Preparations for BLE GATT. Added extra time after INA219 is powered on before measurement. Reduced LEDC frequency to 60 Hz, that makes the LED lights less nervous. Hardware mod on output 4, now needs external pulldown resistor.
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
79 | .duty = 0, ///< Default 0% |
9
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
80 | .gpio_num = OutputPin4, ///< Dimmer4 pin |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
81 | .speed_mode = LEDC_LOW_SPEED_MODE, |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
82 | .hpoint = 0, |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
83 | .intr_type = LEDC_INTR_DISABLE, |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
84 | .timer_sel = LEDC_TIMER_0 ///< Timer 0 |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
85 | }; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
86 | ledc_channel_config(&dimmer_channel4); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
87 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
88 | ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
89 | ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
90 | ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
91 | ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
92 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
93 | /* |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
94 | * Task loop forever. |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
95 | */ |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
96 | ESP_LOGI(TAG, "Starting loop OUT task"); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
97 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
98 | while (1) { |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
99 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
100 | if (xSemaphoreTake(xSemaphoreOUT, 25) == pdTRUE) { |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
101 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
102 | if (out_state->out1 != Relay1) { |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
103 | out_state->out1 = Relay1; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
104 | if (Alarm) |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
105 | gpio_set_level(OutputPin1, 0); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
106 | else |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
107 | gpio_set_level(OutputPin1, Relay1); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
108 | // ESP_LOGI(TAG, "Relay1 %d %d", OutputPin1, Relay1); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
109 | } |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
110 | if (out_state->out2 != Relay2) { |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
111 | out_state->out2 = Relay2; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
112 | if (Alarm) |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
113 | gpio_set_level(OutputPin2, 0); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
114 | else |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
115 | gpio_set_level(OutputPin2, Relay2); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
116 | // ESP_LOGI(TAG, "Relay2 %d %d", OutputPin2, Relay2); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
117 | } |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
118 | |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
119 | if (out_state->out3 != Dimmer3) { |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
120 | if (out_state->out3 < Dimmer3) { |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
121 | out_state->out3++; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
122 | } else if (out_state->out3 > Dimmer3) { |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
123 | out_state->out3--; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
124 | } |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
125 | if (Alarm) |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
126 | val = 0; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
127 | else |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
128 | val = (out_state->out3 * 1024) / 100; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
129 | //ESP_LOGI(TAG, "Dimmer 3 %d val %d", out_state->out3, val); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
130 | ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, val); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
131 | ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
132 | } |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
133 | if (out_state->out4 != Dimmer4) { |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
134 | if (out_state->out4 < Dimmer4) { |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
135 | out_state->out4++; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
136 | } else if (out_state->out4 > Dimmer4) { |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
137 | out_state->out4--; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
138 | } |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
139 | if (Alarm) |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
140 | val = 0; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
141 | else |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
142 | val = (out_state->out4 * 1024) / 100; |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
143 | //ESP_LOGI(TAG, "Dimmer 4 %d val %d", out_state->out4, val); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
144 | ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, val); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
145 | ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
146 | } |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
147 | xSemaphoreGive(xSemaphoreOUT); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
148 | } |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
149 | vTaskDelay(20 / portTICK_PERIOD_MS); |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
150 | } |
1659bd3c7a2b
Added task_out to drive the relays and led lights. Added NVS namespace to store the state of the outputs. Respond to subscribed MQTT topics to set new output values.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
151 | } |