Added LED intensity
This commit is contained in:
parent
bb274d367a
commit
0061723472
@ -25,6 +25,7 @@
|
||||
|
||||
#define RGBLED_PRESCALER 0
|
||||
#define RGBLED_PERIOD 255
|
||||
#define RGBLED_MAX_INTENSITY 100
|
||||
|
||||
/*
|
||||
* Shorthands for colors
|
||||
@ -72,6 +73,8 @@ typedef struct {
|
||||
|
||||
int8_t rgbled_init(rgbled_context_t *context);
|
||||
int8_t rgbled_set_color(uint8_t R, uint8_t G, uint8_t B);
|
||||
int8_t rgbled_set_intensity(uint8_t intensity);
|
||||
int8_t rgbled_get_intensity(uint8_t *intensity);
|
||||
int8_t rgbled_off(void);
|
||||
|
||||
|
||||
|
@ -225,8 +225,8 @@ int main(void)
|
||||
rgbled_context.channel.G = 1;
|
||||
rgbled_context.channel.B = 1;
|
||||
rgbled_init(&rgbled_context);
|
||||
|
||||
rgbled_set_color(RGBLED_WHITE);
|
||||
rgbled_set_intensity(sensor_config.led_brightness);
|
||||
rgbled_set_color(RGBLED_WHITE); /* white color indicates init process */
|
||||
|
||||
LL_mDelay(2000);
|
||||
|
||||
@ -258,7 +258,6 @@ int main(void)
|
||||
LL_mDelay(5000);
|
||||
|
||||
static uint32_t new_baud;
|
||||
|
||||
/* Enter the main loop */
|
||||
while (1)
|
||||
{
|
||||
@ -854,6 +853,7 @@ int8_t modbus_slave_callback(modbus_transaction_t *transaction)
|
||||
break;
|
||||
case REGISTER_NUM_LED_BRIGHTNESS:
|
||||
sensor_config.led_brightness = (uint16_t) transaction->holding_registers[i];
|
||||
rgbled_set_intensity(sensor_config.led_brightness);
|
||||
break;
|
||||
case REGISTER_NUM_LED_SMOOTH:
|
||||
sensor_config.led_smooth = (uint16_t) transaction->holding_registers[i];
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "rgbled.h"
|
||||
|
||||
static rgbled_context_t *rgbled_context;
|
||||
|
||||
static uint8_t rgbled_intensity = RGBLED_MAX_INTENSITY; /* LED intensity from 0 (off) to RGBLED_MAX_INTENSITY (full power) */
|
||||
|
||||
int8_t rgbled_init(rgbled_context_t *context)
|
||||
{
|
||||
@ -25,9 +25,9 @@ int8_t rgbled_set_color(uint8_t R, uint8_t G, uint8_t B)
|
||||
uint8_t colors[3];
|
||||
uint8_t i;
|
||||
|
||||
colors[0] = R;
|
||||
colors[1] = G;
|
||||
colors[2] = B;
|
||||
colors[0] = (uint32_t)R * rgbled_intensity / RGBLED_MAX_INTENSITY;
|
||||
colors[1] = (uint32_t)G * rgbled_intensity / RGBLED_MAX_INTENSITY;
|
||||
colors[2] = (uint32_t)B * rgbled_intensity / RGBLED_MAX_INTENSITY;
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (colors[i] > RGBLED_PERIOD) {
|
||||
return RGBLED_ERROR;
|
||||
@ -51,10 +51,25 @@ int8_t rgbled_set_color(uint8_t R, uint8_t G, uint8_t B)
|
||||
return RGBLED_WRONG_CHANNEL;
|
||||
}
|
||||
}
|
||||
|
||||
return RGBLED_OK;
|
||||
}
|
||||
|
||||
int8_t rgbled_set_intensity(uint8_t intensity)
|
||||
{
|
||||
if (intensity > RGBLED_MAX_INTENSITY) {
|
||||
return RGBLED_ERROR;
|
||||
}
|
||||
rgbled_intensity = intensity;
|
||||
}
|
||||
|
||||
int8_t rgbled_get_intensity(uint8_t *intensity)
|
||||
{
|
||||
if (intensity == NULL) {
|
||||
return RGBLED_ERROR;
|
||||
}
|
||||
*intensity = rgbled_intensity;
|
||||
}
|
||||
|
||||
int8_t rgbled_off(void)
|
||||
{
|
||||
rgbled_set_color(RGBLED_OFF);
|
||||
|
Loading…
Reference in New Issue
Block a user