mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 23:48:11 +01:00
par
This commit is contained in:
parent
e4e4a7aeef
commit
4994c4b39c
2 changed files with 27 additions and 21 deletions
|
@ -241,12 +241,12 @@ void AS7343Component::calculate_and_publish() {
|
|||
float irradiance;
|
||||
float irradiance_photopic;
|
||||
float lux;
|
||||
float ppfd;
|
||||
float ppfd, par;
|
||||
|
||||
float cct, duv, lux2;
|
||||
|
||||
this->calculate_irradiance(irradiance, irradiance_photopic, lux);
|
||||
this->calculate_ppfd(ppfd);
|
||||
this->calculate_ppfd(ppfd, par);
|
||||
this->calculate_color_params(cct, duv, lux2);
|
||||
|
||||
// ESP_LOGD(TAG, "BEFORE GLASS ATTENUATION");
|
||||
|
@ -260,10 +260,12 @@ void AS7343Component::calculate_and_publish() {
|
|||
lux *= this->glass_attenuation_factor_;
|
||||
lux2 *= this->glass_attenuation_factor_;
|
||||
ppfd *= this->glass_attenuation_factor_;
|
||||
par *= this->glass_attenuation_factor_;
|
||||
|
||||
ESP_LOGD(TAG, "AFTER GLASS ATTENUATION");
|
||||
ESP_LOGD(TAG, " ,Irradiance , %f, W/m²", irradiance);
|
||||
ESP_LOGD(TAG, " ,Irradiance(photopic), %f, W/m²", irradiance_photopic);
|
||||
ESP_LOGD(TAG, " ,PAR , %f, W/m²", par);
|
||||
ESP_LOGD(TAG, " ,PPFD , %f, µmol/s⋅m²", ppfd);
|
||||
ESP_LOGD(TAG, " ,Lux(solar coeff) , %f, lx", lux);
|
||||
ESP_LOGD(TAG, " ,Lux(XYZ) , %f, lx", lux2);
|
||||
|
@ -404,7 +406,7 @@ void AS7343Component::calculate_basic_counts() {
|
|||
}
|
||||
}
|
||||
|
||||
void AS7343Component::calculate_ppfd(float &ppfd) {
|
||||
void AS7343Component::calculate_ppfd(float &ppfd, float &par) {
|
||||
/*
|
||||
Given the spectral irradiance Iλ, defined as the radiant flux
|
||||
per unit wavelength and unit area, the photon flux density
|
||||
|
@ -430,6 +432,7 @@ void AS7343Component::calculate_ppfd(float &ppfd) {
|
|||
|
||||
*/
|
||||
ppfd = 0;
|
||||
par = 0;
|
||||
|
||||
// assume we integrate using rectangles - mid point is channel wavelength, width is channel width in nm
|
||||
for (uint8_t i = 0; i < AS7343_NUM_CHANNELS; i++) {
|
||||
|
@ -448,10 +451,12 @@ void AS7343Component::calculate_ppfd(float &ppfd) {
|
|||
// // assume channels cover whole range
|
||||
// ppfd += photon_flux * CHANNEL_NM_WIDTH[i] / 1e9f; // nm to meters
|
||||
|
||||
ppfd += irradiance_in_w_per_m2;
|
||||
// k = λ / h * c * Na
|
||||
// 1 W/m2 = λ / 119.565
|
||||
// https://www.gigahertz-optik.com/en-us/service-and-support/knowledge-base/measurement-of-par/
|
||||
ppfd += irradiance_in_w_per_m2 * CHANNEL_NM[i] / 119.565;
|
||||
par += irradiance_in_w_per_m2;
|
||||
}
|
||||
// https://www.controlledenvironments.org/wp-content/uploads/sites/6/2017/06/Ch01.pdf
|
||||
ppfd *= 4.6; // good approximation 1 W/m2 ≈ 4.6 μmole.m2/s.
|
||||
}
|
||||
|
||||
void AS7343Component::calculate_irradiance(float &irradiance_in_w_per_m2, float &irradiance_in_w_per_m2_photopic,
|
||||
|
@ -471,7 +476,6 @@ void AS7343Component::calculate_irradiance(float &irradiance_in_w_per_m2, float
|
|||
// errata hack???
|
||||
irr_band *= 10;
|
||||
|
||||
|
||||
irradiance_in_w_per_m2 += irr_band;
|
||||
|
||||
// photo_band *= CHANNEL_ENERGY_CONTRIBUTION[i]; ?? ideas
|
||||
|
@ -571,9 +575,11 @@ bool AS7343Component::read_all_channels() {
|
|||
bool AS7343Component::is_data_ready() {
|
||||
AS7343RegStatus2 status2{0};
|
||||
status2.raw = this->reg((uint8_t) AS7343Registers::STATUS2).get();
|
||||
this->reg((uint8_t) AS7343Registers::STATUS2) = status2.raw;
|
||||
if (status2.avalid) {
|
||||
ESP_LOGD(TAG, "Status2 0x%02x, avalid %d, asat_digital %d, asat_analog %d", status2.raw, status2.avalid,
|
||||
status2.asat_digital, status2.asat_analog);
|
||||
this->reg((uint8_t) AS7343Registers::STATUS2) = status2.raw;
|
||||
}
|
||||
|
||||
// return this->read_register_bit((uint8_t) AS7343Registers::STATUS2, 6);
|
||||
return status2.avalid;
|
||||
|
|
|
@ -57,7 +57,7 @@ class AS7343Component : public PollingComponent, public i2c::I2CDevice {
|
|||
bool read_all_channels();
|
||||
|
||||
void calculate_basic_counts();
|
||||
void calculate_ppfd(float &ppfd);
|
||||
void calculate_ppfd(float &ppfd, float &par);
|
||||
void calculate_irradiance(float &irradiance, float &irradiance_photopic, float &lux);
|
||||
void calculate_color_params(float &ct, float &duv, float &lux);
|
||||
|
||||
|
|
Loading…
Reference in a new issue