mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-19 00:13:21 +08:00
修改了Web后台的部分界面,增加了HAmqtt中的总电量传感器,后台新增mqtt上报频率设置
This commit is contained in:
15
mico-os/libraries/drivers/rgb_led/P9813/P9813.mk
Normal file
15
mico-os/libraries/drivers/rgb_led/P9813/P9813.mk
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
# UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
# Copyright (c) 2016 MXCHIP Inc.
|
||||
#
|
||||
# The contents of this file may not be disclosed to third parties, copied or
|
||||
# duplicated in any form, in whole or in part, without the prior written
|
||||
# permission of MXCHIP Corporation.
|
||||
#
|
||||
|
||||
NAME := Lib_RGB_P9813_$(PLATFORM)
|
||||
|
||||
$(NAME)_SOURCES := hsb2rgb_led.c \
|
||||
rgb_led.c
|
||||
|
||||
GLOBAL_INCLUDES := .
|
||||
146
mico-os/libraries/drivers/rgb_led/P9813/hsb2rgb_led.c
Normal file
146
mico-os/libraries/drivers/rgb_led/P9813/hsb2rgb_led.c
Normal file
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file hsb2rgb_led.c
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 17-Mar-2015
|
||||
* @brief converts HSB color values to RGB colors to control RGB LED.
|
||||
******************************************************************************
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "debug.h"
|
||||
#include "hsb2rgb_led.h"
|
||||
#include "rgb_led.h"
|
||||
|
||||
#define hsb2rgb_led_log(M, ...) custom_log("HSB2RGB_LED", M, ##__VA_ARGS__)
|
||||
#define hsb2rgb_led_log_trace() custom_log_trace("HSB2RGB_LED")
|
||||
|
||||
#define H2R_MAX_RGB_val 255.0f
|
||||
|
||||
static float constrain(float value, float min, float max){
|
||||
if(value >= max)
|
||||
return max;
|
||||
if(value <=min )
|
||||
return min;
|
||||
return value;
|
||||
}
|
||||
|
||||
//float Percent(float value){
|
||||
// return value = (((float)value / 255.0) * 100.0);
|
||||
//}
|
||||
|
||||
static void H2R_HSBtoRGB(float hue, float sat, float bright, float *color) {
|
||||
// constrain all input variables to expected range
|
||||
hue = constrain(hue, 0, 360);
|
||||
sat = constrain(sat, 0, 100);
|
||||
bright = constrain(bright, 0, 100);
|
||||
// define maximum value for RGB array elements
|
||||
float max_rgb_val = H2R_MAX_RGB_val;
|
||||
// convert saturation and brightness value to decimals and init r, g, b variables
|
||||
float sat_f = (float)sat / 100.0f;
|
||||
float bright_f = (float)bright / 100.0f;
|
||||
float r=0, g=0, b=0;
|
||||
// If brightness is 0 then color is black (achromatic)
|
||||
// therefore, R, G and B values will all equal to 0
|
||||
if (bright <= 0) {
|
||||
color[0] = 0;
|
||||
color[1] = 0;
|
||||
color[2] = 0;
|
||||
}
|
||||
// If saturation is 0 then color is gray (achromatic)
|
||||
// therefore, R, G and B values will all equal the current brightness
|
||||
if (sat <= 0) {
|
||||
color[0] = bright_f * max_rgb_val;
|
||||
color[1] = bright_f * max_rgb_val;
|
||||
color[2] = bright_f * max_rgb_val;
|
||||
}
|
||||
// if saturation and brightness are greater than 0 then calculate
|
||||
// R, G and B values based on the current hue and brightness
|
||||
else {
|
||||
if (hue >= 0 && hue < 120) {
|
||||
float hue_primary = 1.0f - ((float)hue / 120.0f);
|
||||
float hue_secondary = (float)hue / 120.0f;
|
||||
float sat_primary = (1.0f - hue_primary) * (1.0f - sat_f);
|
||||
float sat_secondary = (1.0f - hue_secondary) * (1.0f - sat_f);
|
||||
float sat_tertiary = 1.0f - sat_f;
|
||||
r = (bright_f * max_rgb_val) * (hue_primary + sat_primary);
|
||||
g = (bright_f * max_rgb_val) * (hue_secondary + sat_secondary);
|
||||
b = (bright_f * max_rgb_val) * sat_tertiary;
|
||||
}
|
||||
else if (hue >= 120 && hue < 240) {
|
||||
float hue_primary = 1.0f - (((float)hue-120.0f) / 120.0f);
|
||||
float hue_secondary = ((float)hue-120.0f) / 120.0f;
|
||||
float sat_primary = (1.0f - hue_primary) * (1.0f - sat_f);
|
||||
float sat_secondary = (1.0f - hue_secondary) * (1.0f - sat_f);
|
||||
float sat_tertiary = 1.0f - sat_f;
|
||||
r = (bright_f * max_rgb_val) * sat_tertiary;
|
||||
g = (bright_f * max_rgb_val) * (hue_primary + sat_primary);
|
||||
b = (bright_f * max_rgb_val) * (hue_secondary + sat_secondary);
|
||||
}
|
||||
else if (hue >= 240 && hue <= 360) {
|
||||
float hue_primary = 1.0f - (((float)hue-240.0f) / 120.0f);
|
||||
float hue_secondary = ((float)hue-240.0f) / 120.0f;
|
||||
float sat_primary = (1.0f - hue_primary) * (1.0f - sat_f);
|
||||
float sat_secondary = (1.0f - hue_secondary) * (1.0f - sat_f);
|
||||
float sat_tertiary = 1.0f - sat_f;
|
||||
r = (bright_f * max_rgb_val) * (hue_secondary + sat_secondary);
|
||||
g = (bright_f * max_rgb_val) * sat_tertiary;
|
||||
b = (bright_f * max_rgb_val) * (hue_primary + sat_primary);
|
||||
}
|
||||
color[0] = r;
|
||||
color[1] = g;
|
||||
color[2] = b;
|
||||
}
|
||||
// color[0] = Percent(color[0]);
|
||||
// color[1] = Percent(color[1]);
|
||||
// color[2] = Percent(color[2]);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------- INTERNAL FUNCTION ---------------------------------------*/
|
||||
|
||||
// call RGB LED driver to control LED
|
||||
static void OpenLED_RGB(float *color)
|
||||
{
|
||||
uint8_t blue = (uint8_t)(color[2]);
|
||||
uint8_t green = (uint8_t)(color[1]);
|
||||
uint8_t red = (uint8_t)(color[0]);
|
||||
|
||||
//hsb2rgb_led_log("OpenLED_RGB: red=%d, green=%d, blue=%d.", red, green, blue);
|
||||
|
||||
rgb_led_init();
|
||||
rgb_led_open(red, green, blue);
|
||||
}
|
||||
|
||||
static void CloseLED_RGB()
|
||||
{
|
||||
rgb_led_init();
|
||||
rgb_led_close();
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------- USER INTERFACES ---------------------------------------*/
|
||||
|
||||
void hsb2rgb_led_init(void)
|
||||
{
|
||||
rgb_led_init();
|
||||
}
|
||||
|
||||
void hsb2rgb_led_open(float hues, float saturation, float brightness)
|
||||
{
|
||||
float color[3] = {0};
|
||||
H2R_HSBtoRGB(hues, saturation, brightness, color);
|
||||
OpenLED_RGB(color);
|
||||
}
|
||||
|
||||
void hsb2rgb_led_close(void)
|
||||
{
|
||||
CloseLED_RGB();
|
||||
}
|
||||
81
mico-os/libraries/drivers/rgb_led/P9813/hsb2rgb_led.h
Normal file
81
mico-os/libraries/drivers/rgb_led/P9813/hsb2rgb_led.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file hsb2rgb_led.h
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 17-Mar-2015
|
||||
* @brief converts HSB color values to RGB colors to control RGB LED.
|
||||
******************************************************************************
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __HSB2RGB_LED_H_
|
||||
#define __HSB2RGB_LED_H_
|
||||
|
||||
|
||||
/** @addtogroup MICO_Drivers_interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup MICO_LED_Driver MiCO LED Driver
|
||||
* @brief Provide driver interface for LED devices
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup MICO_LED_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup MICO_HSB2RGB_Driver MiCO hsb2rgb Driver
|
||||
* @brief Provide driver interface for Hsb2rgb
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize hsb2rgb device.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void hsb2rgb_led_init(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set light parameters for hsb2rgb.
|
||||
*
|
||||
* @param hues: hues data of hsb2rgb
|
||||
* @param saturation: saturation data of hsb2rgb
|
||||
* @param brightness: brightness data of hsb2rgb
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void hsb2rgb_led_open(float hues, float saturation, float brightness);
|
||||
|
||||
/**
|
||||
* @brief Close hsb2rgb
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void hsb2rgb_led_close(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif // __HSB2RGB_LED_H_
|
||||
91
mico-os/libraries/drivers/rgb_led/P9813/rgb_led.c
Normal file
91
mico-os/libraries/drivers/rgb_led/P9813/rgb_led.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rgb_led.c
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 17-Mar-2015
|
||||
* @brief rgb led controller.
|
||||
******************************************************************************
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "rgb_led.h"
|
||||
#include "mico.h"
|
||||
|
||||
#define rgb_led_log(M, ...) custom_log("RGB_LED", M, ##__VA_ARGS__)
|
||||
#define rgb_led_log_trace() custom_log_trace("RGB_LED")
|
||||
|
||||
/* use gpio */
|
||||
static void P9813_PIN_write_frame(uint32_t data)
|
||||
{
|
||||
uint8_t i;
|
||||
uint32_t f_data = data;
|
||||
//rgb_led_log("P9813_PIN_write_frame = %X", f_data);
|
||||
|
||||
for(i=0; i<32; i++){
|
||||
P9813_PIN_CIN_Clr();
|
||||
if(f_data & 0x80000000){
|
||||
P9813_PIN_DIN_Set();
|
||||
}
|
||||
else{
|
||||
P9813_PIN_DIN_Clr();
|
||||
}
|
||||
P9813_PIN_CIN_Set(); // raise edge to set data
|
||||
f_data = f_data << 1;
|
||||
//rgb_led_log("frame_data<<1 =%x", f_data);
|
||||
}
|
||||
|
||||
//P9813_PIN_CIN_Clr();
|
||||
//P9813_PIN_DIN_Clr();
|
||||
}
|
||||
|
||||
static void P9813_PIN_write_start_frame(void)
|
||||
{
|
||||
uint32_t start_frame = 0x00000000;
|
||||
P9813_PIN_write_frame(start_frame);
|
||||
}
|
||||
|
||||
static void P9813_PIN_write_data(uint8_t blue, uint8_t green, uint8_t red)
|
||||
{
|
||||
uint8_t check_byte = 0xC0; // starting flag "11"
|
||||
uint32_t send_data = 0;
|
||||
|
||||
// calc check data
|
||||
check_byte |= (((~blue) >> 2) & 0x30); // B7, B6
|
||||
check_byte |= (((~green) >> 4) & 0x0C); // G7,G6
|
||||
check_byte |= (((~red) >> 6) & 0x03); // R7,R6
|
||||
|
||||
// create send data 32bit
|
||||
send_data |= (check_byte << 24) | (blue << 16) | (green << 8) | (red);
|
||||
|
||||
//send_data = 0xFC0000FF;
|
||||
//rgb_led_log("P9813_PIN_write_data: %X", send_data);
|
||||
P9813_PIN_write_frame(send_data);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------- USER INTERFACES ------------------------------------------------*/
|
||||
|
||||
void rgb_led_init(void)
|
||||
{
|
||||
MicoGpioInitialize( (mico_gpio_t)P9813_PIN_CIN, OUTPUT_PUSH_PULL );
|
||||
MicoGpioInitialize( (mico_gpio_t)P9813_PIN_DIN, OUTPUT_PUSH_PULL );
|
||||
}
|
||||
|
||||
void rgb_led_open(uint8_t red, uint8_t green, uint8_t blue)
|
||||
{
|
||||
P9813_PIN_write_start_frame();
|
||||
P9813_PIN_write_data(blue, green, red);
|
||||
P9813_PIN_write_start_frame(); // fix led bink bug
|
||||
}
|
||||
|
||||
void rgb_led_close(void)
|
||||
{
|
||||
rgb_led_init();
|
||||
rgb_led_open(0, 0, 0);
|
||||
}
|
||||
95
mico-os/libraries/drivers/rgb_led/P9813/rgb_led.h
Normal file
95
mico-os/libraries/drivers/rgb_led/P9813/rgb_led.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rgb_led.h
|
||||
* @author Eshen Wang
|
||||
* @version V1.0.0
|
||||
* @date 17-Mar-2015
|
||||
* @brief rgb led controller.
|
||||
******************************************************************************
|
||||
* UNPUBLISHED PROPRIETARY SOURCE CODE
|
||||
* Copyright (c) 2016 MXCHIP Inc.
|
||||
*
|
||||
* The contents of this file may not be disclosed to third parties, copied or
|
||||
* duplicated in any form, in whole or in part, without the prior written
|
||||
* permission of MXCHIP Corporation.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __RGB_LED_H_
|
||||
#define __RGB_LED_H_
|
||||
|
||||
#include "mico.h"
|
||||
#include "hsb2rgb_led.h"
|
||||
#include "platform.h"
|
||||
|
||||
|
||||
/** @addtogroup MICO_Drivers_interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup MICO_LED_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup MICO_RGBLED_Driver MiCO RGBLED Driver
|
||||
* @brief Provide driver interface for RGBLED
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef P9813_PIN_CIN
|
||||
#define P9813_PIN_CIN (MICO_GPIO_NONE)
|
||||
#endif
|
||||
|
||||
#ifndef P9813_PIN_DIN
|
||||
#define P9813_PIN_DIN (MICO_GPIO_NONE)
|
||||
#endif
|
||||
|
||||
#define P9813_PIN_CIN_Clr() MicoGpioOutputLow(P9813_PIN_CIN)
|
||||
#define P9813_PIN_CIN_Set() MicoGpioOutputHigh(P9813_PIN_CIN)
|
||||
|
||||
#define P9813_PIN_DIN_Clr() MicoGpioOutputLow(P9813_PIN_DIN)
|
||||
#define P9813_PIN_DIN_Set() MicoGpioOutputHigh(P9813_PIN_DIN)
|
||||
|
||||
//-------------------- user interfaces ---------------------------
|
||||
|
||||
/**
|
||||
* @brief Initialize RGB LED device.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void rgb_led_init(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set light parameters for RGB LED
|
||||
*
|
||||
* @param red: Red light parameter
|
||||
* @param green: Green light parameter
|
||||
* @param blue: Blue light parameter
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void rgb_led_open(uint8_t red, uint8_t green, uint8_t blue);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Close RGB LED
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void rgb_led_close(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
#endif // __RGB_LED_H_
|
||||
Reference in New Issue
Block a user