diff --git a/developpment/Makefile b/developpment/Makefile index 71993ff..fd5b6a7 100644 --- a/developpment/Makefile +++ b/developpment/Makefile @@ -3,6 +3,7 @@ cpp_src += $(wildcard ./pimpl/*.cpp) cpp_src += $(wildcard ./communication/i2c/*.cpp) cpp_src += $(wildcard ./management/*.cpp) cpp_src += $(wildcard ./drivers/bh1750/*.cpp) +cpp_src += $(wildcard ./drivers/pca9685/*.cpp) cpp_src += $(wildcard ./systems/*.cpp) c_src += $(wildcard ./algorithms/*.c) diff --git a/developpment/drivers/pca9685/pca9685.cpp b/developpment/drivers/pca9685/pca9685.cpp index 1570d9c..94a065f 100644 --- a/developpment/drivers/pca9685/pca9685.cpp +++ b/developpment/drivers/pca9685/pca9685.cpp @@ -11,12 +11,13 @@ #include "pca9685.h" -Pca9685::Pca9685(i2c_ch1_pImpL* i2c, ErrorHandler* err) +Pca9685::Pca9685(I2C* i2c, ErrorHandler* err) { i2c_pca9685 = i2c; errorHandling = err; m_isExternalClock = 0; m_oscillatorFreq = PCA9685_FREQUENCY_OSCILLATOR; + turnAllOff(); setPwmFreq(1000); m_currentLED = PCA9685_LED_PWM_REG_START; @@ -68,7 +69,14 @@ void Pca9685::setPwmFreq(float frequency) } - +void Pca9685::turnAllOff() +{ + i2c_pca9685->writeWord(PCA9685_I2C_ADDRESS,PCA9685_ALL_OFF_H, 16 ); +} +void Pca9685::turnAllOn() +{ + i2c_pca9685->writeWord(PCA9685_I2C_ADDRESS,PCA9685_ALL_ON_H, 16 ); +} //The impresition leves of thise device is out from this world this is a crude way from me trying to mitigate de awfullness. //Tested with other module all to react the same //maybe an external Clock could help with that but MCU level precision will never be reached !! Too sad diff --git a/developpment/drivers/pca9685/pca9685.h b/developpment/drivers/pca9685/pca9685.h index 06bd92e..8fcd237 100644 --- a/developpment/drivers/pca9685/pca9685.h +++ b/developpment/drivers/pca9685/pca9685.h @@ -5,7 +5,7 @@ #include #include #include -#include "../../periferals/i2c/i2c_ch1_pImpL.hpp" +#include "../../communication/i2c/i2c.hpp" #include "../../management/errorHandling.h" // https://www.nxp.com/docs/en/data-sheet/PCA9685.pdf @@ -61,9 +61,11 @@ class Pca9685 { public: - Pca9685(i2c_ch1_pImpL* i2c,ErrorHandler* err); + Pca9685(I2C* i2c,ErrorHandler* err); void setPwmFreq(float frequency); void setPwmRaw(uint8_t preScale); + void turnAllOff(); + void turnAllOn(); uint8_t compensatePrescale(uint8_t preScale); float getPwmFreq(); void setOnDutyPercent(uint8_t ledNo, uint8_t percent); @@ -82,7 +84,7 @@ class Pca9685 uint8_t m_isExternalClock; float m_oscillatorFreq; ErrorHandler* errorHandling; - i2c_ch1_pImpL* i2c_pca9685; + I2C* i2c_pca9685; }; diff --git a/developpment/interfacer.cpp b/developpment/interfacer.cpp index 544dea1..457c58f 100644 --- a/developpment/interfacer.cpp +++ b/developpment/interfacer.cpp @@ -15,6 +15,7 @@ #include "./management/commandManager.h" #include "./drivers/bh1750/bh1750.h" #include "./drivers/pf8574/pf8574lcd.h" +#include "./drivers/pca9685/pca9685.h" #include "./algorithms/bitgestion.h" #include "./pimpl/interface.hpp" #include "./communication/i2c/i2c.hpp" @@ -27,10 +28,26 @@ I2C i2c; char char_array[TOTAL_CHAR_CAP]; -//i2c_ch1_pImpL i2c(1, &errorHandle); - /* -int freq = 0; + +void dummy() +{ + uint16_t conf = 0; + float conv = 0; + Ads1015 adc(&i2c,&errorHandle); + conf = adc.getConfig(); + adc.setOperationMode(ADS1015_MODE_SINGLE); + adc.setMultiplexer(ADS1015_MUX_AIN0_GND); + adc.setGain(ADS1015_GAIN_6144); + adc.writeConfig(); + adc.pointToConvReg(); + conv = adc.getConversion(); + conv = (5.0 * conv)/2047.0; + std::cout << "Convertion " << conv << std::endl; + exit(1); +} + +*/ int initPlatform() { @@ -38,7 +55,6 @@ int initPlatform() return 0; } - void pca9685_test() { Pca9685 pwmGenarator(&i2c, &errorHandle); @@ -54,62 +70,40 @@ void pca9685_test() strcpy(char_array, "Hz"); lcd_display_string(1,18, char_array, 7); usleep(200000); - freq = getchar(); - } -} - -void bh1750_test() -{ - Bh1750 lightSens(&i2c); - while(1) - { -// std::cout << "value "<< lightSens.continious(BH1750_CONTINUOUS_HIGH_RES_MODE_1,1) << " Lux" <= 0; i--) + { + pwmGenarator.setOnDutyPercent(0,i); + pwmGenarator.setOnDutyPercent(2,i); + usleep(20000); + } } + void dummy() { pimplTest.printNumber(3); @@ -135,6 +129,8 @@ int main(int argc, char *argv[]) std::cout << "Main Begin" << std::endl; commander.addNewCommand("dummy", "The test command for testing the test", dummy); commander.addNewCommand("bh1750", "The test command for testing the bh1750", bh1750_test); + commander.addNewCommand("pca9685", "The test command for testing the pca8695", pca9685_test); + commander.addNewCommand("motor", "The test command for testing the pca8695", pca9685_motor); commander(argv[1]); std::cout << "Main End" << std::endl;