mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-05-19 02:51:47 +02:00
Integrate color sensor, infrared LEDs and phototransistors into Power Management
This commit is contained in:
parent
e5ff1e7610
commit
5407543658
@ -1,6 +1,7 @@
|
||||
#include "ColorDetection.h"
|
||||
|
||||
void ColorDetection::begin(void){
|
||||
Power::waitForCurrentAllowance(PowerParameters::PowerConsumers::RGBW_SENSOR, PowerParameters::CurrentConsumptions::CURRENT_SENSOR_RGBW, COLOR_DETECTION_MAX_EXECUTION_DELAY_MS, NULL);
|
||||
ColorDetection::configure(VEML_CONFIG{.mode = AUTO,.enabled = true,.exposureTime=MS40});
|
||||
};
|
||||
void ColorDetection::configure(VEML_CONFIG config){
|
||||
|
@ -11,9 +11,10 @@
|
||||
|
||||
#ifndef ColorDetection_h
|
||||
#define ColorDetection_h
|
||||
#include <stdint.h>
|
||||
#include <Wire.h>
|
||||
#include "../power/Power.h"
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <stdint.h>
|
||||
//Definitions for I2c
|
||||
#define I2C_MASTER_SCL_IO 2 /*!< GPIO number used for I2C master clock */
|
||||
#define I2C_MASTER_SDA_IO 1 /*!< GPIO number used for I2C master data */
|
||||
@ -28,6 +29,8 @@
|
||||
#define REG_BLUE 0x0A
|
||||
#define REG_WHITE 0x0B
|
||||
|
||||
#define COLOR_DETECTION_MAX_EXECUTION_DELAY_MS 1
|
||||
|
||||
|
||||
enum duration{
|
||||
MS40,
|
||||
|
@ -1,6 +1,9 @@
|
||||
#include "InfraredLight.h"
|
||||
|
||||
#define pwmSpeedMode LEDC_LOW_SPEED_MODE
|
||||
#define IR_FRONT_PIN 14
|
||||
#define IR_BOTTOM_PIN 13
|
||||
#define DUTY_RESOLUTION LEDC_TIMER_10_BIT
|
||||
|
||||
InfraredLED::InfraredLED(uint8_t pin,ledc_timer_t timer, ledc_channel_t channel){
|
||||
this->ledPin = pin;
|
||||
@ -12,7 +15,7 @@ void InfraredLED::begin(void){
|
||||
//we want to change frequency instead of
|
||||
pwmTimer = ledc_timer_config_t{
|
||||
.speed_mode = pwmSpeedMode,
|
||||
.duty_resolution = LEDC_TIMER_10_BIT,
|
||||
.duty_resolution = DUTY_RESOLUTION,
|
||||
.timer_num = this->timer,
|
||||
.freq_hz = 800,
|
||||
.clk_cfg = LEDC_AUTO_CLK
|
||||
@ -42,8 +45,24 @@ void InfraredLED::turnOff(void){
|
||||
void InfraredLED::setState(bool state){
|
||||
ledc_set_freq(pwmSpeedMode,timer,1);
|
||||
if (state) {
|
||||
if (this->ledPin == IR_BOTTOM_PIN) {
|
||||
Power::waitForCurrentAllowance(
|
||||
PowerParameters::PowerConsumers::LED_IR_BOTTOM,
|
||||
PowerParameters::CurrentConsumptions::CURRENT_LED_IR_BOTTOM,
|
||||
IR_LED_MAX_EXECUTION_DELAY_MS, NULL);
|
||||
} else if (this->ledPin == IR_FRONT_PIN) {
|
||||
Power::waitForCurrentAllowance(
|
||||
PowerParameters::PowerConsumers::LED_IR_FRONT,
|
||||
PowerParameters::CurrentConsumptions::CURRENT_LED_IR_FRONT,
|
||||
IR_LED_MAX_EXECUTION_DELAY_MS, NULL);
|
||||
}
|
||||
ledc_set_duty(pwmSpeedMode,channel,1023);
|
||||
} else {
|
||||
if (this->ledPin == IR_BOTTOM_PIN) {
|
||||
Power::releaseCurrent(PowerParameters::PowerConsumers::LED_IR_BOTTOM);
|
||||
} else {
|
||||
Power::releaseCurrent(PowerParameters::PowerConsumers::LED_IR_FRONT);
|
||||
}
|
||||
ledc_set_duty(pwmSpeedMode,channel,0);
|
||||
}
|
||||
ledc_update_duty(pwmSpeedMode,channel);
|
||||
@ -51,7 +70,27 @@ void InfraredLED::setState(bool state){
|
||||
};
|
||||
|
||||
void InfraredLED::sendFrequency(uint16_t frequency){
|
||||
constexpr uint32_t duty = 512;
|
||||
// Float to force float division without casting
|
||||
constexpr float resolution = 1 << DUTY_RESOLUTION;
|
||||
if (this->ledPin == IR_BOTTOM_PIN) {
|
||||
float currentConsumption =
|
||||
(duty / resolution) *
|
||||
PowerParameters::CurrentConsumptions::CURRENT_LED_IR_BOTTOM;
|
||||
Power::waitForCurrentAllowance(
|
||||
PowerParameters::PowerConsumers::LED_IR_BOTTOM,
|
||||
currentConsumption,
|
||||
IR_LED_MAX_EXECUTION_DELAY_MS, NULL);
|
||||
} else if (this->ledPin == IR_FRONT_PIN) {
|
||||
float currentConsumption =
|
||||
(duty / resolution) *
|
||||
PowerParameters::CurrentConsumptions::CURRENT_LED_IR_FRONT;
|
||||
Power::waitForCurrentAllowance(
|
||||
PowerParameters::PowerConsumers::LED_IR_FRONT,
|
||||
currentConsumption,
|
||||
IR_LED_MAX_EXECUTION_DELAY_MS, NULL);
|
||||
}
|
||||
ledc_set_freq(pwmSpeedMode,timer,frequency);
|
||||
ledc_set_duty(pwmSpeedMode,channel,512);
|
||||
ledc_set_duty(pwmSpeedMode,channel,duty);
|
||||
ledc_update_duty(pwmSpeedMode,channel);
|
||||
};
|
@ -10,9 +10,12 @@
|
||||
*/
|
||||
#ifndef InfraredLight_h
|
||||
#define InfraredLight_h
|
||||
#include <stdint.h>
|
||||
#include <Arduino.h>
|
||||
#include "../power/Power.h"
|
||||
#include "driver/ledc.h"
|
||||
#include <Arduino.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define IR_LED_MAX_EXECUTION_DELAY_MS 1
|
||||
|
||||
|
||||
class InfraredLED{
|
||||
|
@ -64,6 +64,10 @@ uint32_t LightDetection::getAverageValue(photoTransistors sensor, uint32_t measu
|
||||
};
|
||||
|
||||
void LightDetection::beginInfrared(void){
|
||||
Power::waitForCurrentAllowance(
|
||||
PowerParameters::PowerConsumers::PT_IR,
|
||||
PowerParameters::CurrentConsumptions::CURRENT_PT * 4,
|
||||
LIGHT_DETECTION_MAX_EXECUTION_DELAY_MS, NULL);
|
||||
digitalWrite(IR_PT_ENABLE,true);
|
||||
pinMode(IR_PT_ENABLE, OUTPUT);
|
||||
pinMode(IR_PT_FRONT_ADC, INPUT);
|
||||
@ -73,6 +77,10 @@ void LightDetection::beginInfrared(void){
|
||||
};
|
||||
|
||||
void LightDetection::beginDaylight(void){
|
||||
Power::waitForCurrentAllowance(
|
||||
PowerParameters::PowerConsumers::PT_DL,
|
||||
PowerParameters::CurrentConsumptions::CURRENT_PT * 2,
|
||||
LIGHT_DETECTION_MAX_EXECUTION_DELAY_MS, NULL);
|
||||
digitalWrite(DL_PT_ENABLE,true);
|
||||
pinMode(DL_PT_ENABLE, OUTPUT);
|
||||
pinMode(DL_PT_BOTTOM_ADC, INPUT);
|
||||
@ -99,6 +107,7 @@ uint16_t LightDetection::readIRPT(photoTransistors sensor){
|
||||
default:
|
||||
break;
|
||||
}
|
||||
//Power::releaseCurrent(PowerParameters::PowerConsumers::PT_IR);
|
||||
//digitalWrite(IR_PT_ENABLE,LOW);
|
||||
return result;
|
||||
};
|
||||
@ -117,6 +126,7 @@ uint16_t LightDetection::readDLPT(photoTransistors sensor){
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Power::releaseCurrent(PowerParameters::PowerConsumers::PT_DL);
|
||||
digitalWrite(DL_PT_ENABLE,LOW);
|
||||
return result;
|
||||
};
|
@ -11,10 +11,11 @@
|
||||
|
||||
#ifndef LightDetection_h
|
||||
#define LightDetection_h
|
||||
#include <stdint.h>
|
||||
#include "../power/Power.h"
|
||||
#include <Arduino.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define LIGHT_DETECTION_MAX_EXECUTION_DELAY_MS 1
|
||||
|
||||
enum photoTransistors{
|
||||
IR_LEFT,
|
||||
|
Loading…
x
Reference in New Issue
Block a user