From 066aac8f6d3ab52c31b189ba74865f9c9cf2b21c Mon Sep 17 00:00:00 2001 From: atomega Date: Sun, 28 Mar 2021 17:05:29 +0100 Subject: [PATCH] First working pimpl example --- developpment/$ | 126 ++++++++++++++++++ developpment/Makefile | 9 +- developpment/config.h | 15 +++ developpment/drivers/ads1015/ads1050.cpp | 9 +- developpment/drivers/ads1015/ads1050.h | 3 +- developpment/interfacer.cpp | 54 +++++--- developpment/periferals/i2c/i2c.hpp | 21 +-- developpment/periferals/i2c/i2c_ch0_pImpL.cpp | 15 +-- .../{i2c_ch0_pImpL.h => i2c_ch0_pImpL.hpp} | 17 ++- developpment/periferals/i2c/i2c_ch1_pImpL.cpp | 14 -- developpment/periferals/i2c/i2c_ch1_pImpL.hpp | 15 ++- developpment/periferals/i2c/i2c_driver.o | Bin 0 -> 5280 bytes developpment/pimpl/implementations.hpp | 20 +++ developpment/pimpl/implementations2.hpp | 20 +++ developpment/pimpl/interface.cpp | 24 ++++ developpment/pimpl/interface.hpp | 22 +++ 16 files changed, 321 insertions(+), 63 deletions(-) create mode 100644 developpment/$ create mode 100644 developpment/config.h rename developpment/periferals/i2c/{i2c_ch0_pImpL.h => i2c_ch0_pImpL.hpp} (77%) create mode 100644 developpment/periferals/i2c/i2c_driver.o create mode 100644 developpment/pimpl/implementations.hpp create mode 100644 developpment/pimpl/implementations2.hpp create mode 100644 developpment/pimpl/interface.cpp create mode 100644 developpment/pimpl/interface.hpp diff --git a/developpment/$ b/developpment/$ new file mode 100644 index 0000000..18046a5 --- /dev/null +++ b/developpment/$ @@ -0,0 +1,126 @@ +/* + * Authors : Kerem Yollu & Edwin Koch + * Date : 07.03.2021 + * + * Description : + * TODO : Write description or doxygene + * + */ + +#include +#include +#include +#include +#include "./management/errorHandling.h" +#include "./management/commandManager.h" +//#include "./drivers/bh1750/bh1750.h" +//#include "./drivers/pf8574/pf8574lcd.h" +#include "./algorithms/bitgestion.h" +//#include "./periferals/i2c/i2c.hpp" +#include "./pimpl/implementation.hpp" + + +ErrorHandler errorHandle; +CommandManager commander; + +Device pimplTest; + +//i2c_ch1_pImpL i2c(1, &errorHandle); + +/* +char char_array[TOTAL_CHAR_CAP]; +int freq = 0; + +int initPlatform() +{ + lcd_init(&i2c); + return 0; +} + + +void pca9685_test() +{ + Pca9685 pwmGenarator(&i2c, &errorHandle); + pwmGenarator.setOnDutyPercent(0,50); + for(int i = 3 ; i <= 255; i++) + { + pwmGenarator.setPwmRaw(i); + strcpy(char_array, "Pwm Freq: "); + lcd_display_string(1,0,char_array,0); + std::string Msg = std::to_string(pwmGenarator.getPwmFreq()); + strcpy(char_array, Msg.c_str()); + lcd_display_string(1,10, char_array, 7); + 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" < namespace serial { @@ -33,24 +34,24 @@ namespace serial class I2C { public: - I2C(const uint8_t& mode):pImpL(mode) + I2C(const uint8_t& mode) { } uint8_t readByte(const uint8_t& address, const uint8_t& reg) { - return pImpL -> readByte(address, reg); + return pImpL.readByte(address, reg); } uint16_t readWord(const uint8_t& address, const uint8_t& reg) { - return pImpL -> readWord(address,reg); + return pImpL.readWord(address,reg); } uint8_t writeByte(const uint8_t& address, const uint8_t& data) { - return pImpL -> writeByte(address, data); + return pImpL.writeByte(address, data); } uint8_t writeWord(const uint8_t& address, const uint8_t& reg, const uint16_t& data) { - return pImpL -> writeWord(address, reg, data); + return pImpL.writeWord(address, reg, data); } private: @@ -65,24 +66,24 @@ namespace serial class I2C { public: - I2C(const uint8_t& mode):pImpL(mode) + I2C(const uint8_t& mode) { } uint8_t readByte(const uint8_t& address, const uint8_t& reg) { - return pImpL -> readByte(address, reg); + return pImpL.readByte(address, reg); } uint16_t readWord(const uint8_t& address, const uint8_t& reg) { - return pImpL -> readWord(address,reg); + return pImpL.readWord(address,reg); } uint8_t writeByte(const uint8_t& address, const uint8_t& data) { - return pImpL -> writeByte(address, data); + return pImpL.writeByte(address, data); } uint8_t writeWord(const uint8_t& address, const uint8_t& reg, const uint16_t& data) { - return pImpL -> writeWord(address, reg, data); + return pImpL.writeWord(address, reg, data); } private: diff --git a/developpment/periferals/i2c/i2c_ch0_pImpL.cpp b/developpment/periferals/i2c/i2c_ch0_pImpL.cpp index 6201bc8..0e2aeab 100644 --- a/developpment/periferals/i2c/i2c_ch0_pImpL.cpp +++ b/developpment/periferals/i2c/i2c_ch0_pImpL.cpp @@ -1,18 +1,5 @@ -#include "i2c_ch0_pImpL.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#define PORT_I2C "/dev/i2c-1" +#include "i2c_ch0_pImpL.hpp" // some curious things https://www.john.geek.nz/2012/12/update-reading-data-from-a-bosch-bmp085-with-a-raspberry-pi/ diff --git a/developpment/periferals/i2c/i2c_ch0_pImpL.h b/developpment/periferals/i2c/i2c_ch0_pImpL.hpp similarity index 77% rename from developpment/periferals/i2c/i2c_ch0_pImpL.h rename to developpment/periferals/i2c/i2c_ch0_pImpL.hpp index 51fa22a..a560b1d 100644 --- a/developpment/periferals/i2c/i2c_ch0_pImpL.h +++ b/developpment/periferals/i2c/i2c_ch0_pImpL.hpp @@ -2,10 +2,23 @@ #define _I2C_CH0_PIMPL_H_ #include +#include +#include +#include #include -#include -#include "../../management/errorHandling.h" + +#include +#include +#include +#include +#include + + +#define PORT_I2C "/dev/i2c-1" #include "../../systems/systemCall.h" +#include "../../management/errorHandling.h" + +#include "i2c.hpp" class i2c_ch0_pImpL { diff --git a/developpment/periferals/i2c/i2c_ch1_pImpL.cpp b/developpment/periferals/i2c/i2c_ch1_pImpL.cpp index 350f87f..897472d 100644 --- a/developpment/periferals/i2c/i2c_ch1_pImpL.cpp +++ b/developpment/periferals/i2c/i2c_ch1_pImpL.cpp @@ -1,18 +1,4 @@ #include "i2c_ch1_pImpL.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#define PORT_I2C "/dev/i2c-1" - // some curious things https://www.john.geek.nz/2012/12/update-reading-data-from-a-bosch-bmp085-with-a-raspberry-pi/ diff --git a/developpment/periferals/i2c/i2c_ch1_pImpL.hpp b/developpment/periferals/i2c/i2c_ch1_pImpL.hpp index eabd91e..8ba2952 100644 --- a/developpment/periferals/i2c/i2c_ch1_pImpL.hpp +++ b/developpment/periferals/i2c/i2c_ch1_pImpL.hpp @@ -2,11 +2,24 @@ #define _I2C_CH1_PIMPL_H_ #include +#include +#include +#include #include -#include + +#include +#include +#include +#include +#include + + +#define PORT_I2C "/dev/i2c-1" #include "../../systems/systemCall.h" #include "../../management/errorHandling.h" +#include "i2c.hpp" + class i2c_ch1_pImpL { public: diff --git a/developpment/periferals/i2c/i2c_driver.o b/developpment/periferals/i2c/i2c_driver.o new file mode 100644 index 0000000000000000000000000000000000000000..57c9c2645196bfebd321609347176c8c4b1db8a1 GIT binary patch literal 5280 zcmcgwU2Ggz8U1E=oj5gG2-R-aDo`m#>O&tQ%sDf6 zCfB1lN_pT~v*(`sefRsjKeOJS4~;%;7>2~nkZ!rpL_XUUN?Q6t=$2iQ7dh4QkKFuk zR=Ss-Sutftvn#)&*=+)?j;2_*n(Z>Oa@D-n+>@XC@IUM8|7y2JRx;>kWp0^Vthwce z`Il7_`t#;{%fvP7*0RX>hr31IKAXSRJS*3lp{_ZX$g}ym<&0)y0D8L30~$9Z@=e>+ z$t{hn$g6+;7|~0oO4d>s=aWZ1t;lC5^2sBgRuvcL??j)uWf9K@@Du0pyQh$gb$3<8 zzWpX-H?`Q4d8ydn(qd&j-q3g)d!9bcTVWhI^Sur6Ft(ia(u!fCuCN`)W1xnHHMa*g zvvFLlBHNF`z7@v>e|oJ%)e3XMHHvGM-74~As#a&o)%rhby*`5PIKFhf79m@V<3epW ztJfd2`mkPe8c*tFc3|x~nyu0i`qS5s{jSeZuM@D}7smyE)&u-SHnAtP{q>-l)gDr_ zHf!^J_9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E>3=FN5$ z_PU~O_(>U`^9sX3d|YQxTB8oz&+s6&T1fCgJsgFk#d^fJ#uR=8y(LV<_LpzrVSFe- f7;Bs>s9fJ6@;7Z_Y>z)H>Uw1i{F)O~i}n5sdO*s% literal 0 HcmV?d00001 diff --git a/developpment/pimpl/implementations.hpp b/developpment/pimpl/implementations.hpp new file mode 100644 index 0000000..f47214d --- /dev/null +++ b/developpment/pimpl/implementations.hpp @@ -0,0 +1,20 @@ +#ifndef _IMPLEMENTATION_H_ +#define _IMPLEMENTATION_H_ + +#include "interface.hpp" +#include +#include + +struct Device::deviceImpl +{ + deviceImpl() + { + std::cout << "Device implementation Constarctor For Liunx "<< std::endl; + } + void printNumber(const uint8_t& no) + { + std::cout << "selected no: "<< unsigned(no*2) << std::endl; + } +}; + +#endif // _IMPLEMENTATION_H_ diff --git a/developpment/pimpl/implementations2.hpp b/developpment/pimpl/implementations2.hpp new file mode 100644 index 0000000..777d5af --- /dev/null +++ b/developpment/pimpl/implementations2.hpp @@ -0,0 +1,20 @@ +#ifndef _IMPLEMENTATION2_H_ +#define _IMPLEMENTATION2_H_ + +#include "interface.hpp" +#include +#include + +struct Device::deviceImpl +{ + deviceImpl() + { + std::cout << "Device implementation Constarctor For STM "<< std::endl; + } + void printNumber(const uint8_t& no) + { + std::cout << "selected no: "<< unsigned(no) << std::endl; + } +}; + +#endif // _IMPLEMENTATION2_H_ diff --git a/developpment/pimpl/interface.cpp b/developpment/pimpl/interface.cpp new file mode 100644 index 0000000..effcc05 --- /dev/null +++ b/developpment/pimpl/interface.cpp @@ -0,0 +1,24 @@ +#include "interface.hpp" + +#if PLATFORM == STM +#include "implementations2.hpp" +#endif + +#if PLATFORM == LINUX +#include "implementations.hpp" +#endif + +Device::Device() + :pImpl(new deviceImpl()) +{ +} + +void Device::printNumber(const uint8_t& no) +{ + pImpl->printNumber(no); +} + +Device::~Device() +{ + +} diff --git a/developpment/pimpl/interface.hpp b/developpment/pimpl/interface.hpp new file mode 100644 index 0000000..4dbc73b --- /dev/null +++ b/developpment/pimpl/interface.hpp @@ -0,0 +1,22 @@ +#ifndef _INTERFACE_H_ +#define _INTERFACE_H_ + +#include "../config.h" +#include +#include + +class Device +{ + public: + Device(); + ~Device(); + void printNumber(const uint8_t& no); + + private: + struct deviceImpl; + std::unique_ptr pImpl; +}; + + + +#endif // _INTERFACE_H_