You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
3.5 KiB

/*
* Authors : Kerem Yollu & Edwin Koch
* Date : 07.03.2021
*
* Description :
* TODO : Write description or doxygene
*
*/
#include <iostream>
#include <stdint.h>
#include <unistd.h>
#include <bitset>
#include "./management/errorHandling.h"
#include "./management/commandManager.h"
// hardwareinterfaces
#include "./communication/i2c/i2c.hpp"
// drivers
#include "./drivers/bh1750/bh1750.h"
#include "./drivers/pf8574/pf8574lcd.h"
#include "./drivers/pca9685/pca9685.h"
#include "./drivers/mcp4725/mcp4725.hpp"
#include "./algorithms/bitgestion.h"
#include "./pimpl/interface.hpp"
ErrorHandler errorHandle;
CommandManager commander;
Device pimplTest;
I2C i2c;
char char_array[TOTAL_CHAR_CAP];
/*
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()
{
//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);
}
}
void pca9685_motor()
{
Pca9685 pwmGenarator(&i2c, &errorHandle);
pwmGenarator.setPwmFreq(1500);
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);
int i = 0;
for(i = 0 ; i <= 100; i++)
{
pwmGenarator.setOnDutyPercent(0,i);
pwmGenarator.setOnDutyPercent(2,i);
usleep(20000);
}
for(i = 100 ; i >= 0; i--)
{
pwmGenarator.setOnDutyPercent(0,i);
pwmGenarator.setOnDutyPercent(2,i);
usleep(20000);
}
}
void mcp4725_test()
{
std::cout << "mcp4725 dac test" << std::endl;
/*
auto cb = std::bind()
MCP4725 dac(MCP4725::normal,
MCP4725::addr_0x6,
)
*/
}
void dummy()
{
pimplTest.printNumber(3);
}
void bh1750_test()
{
Bh1750 lightSens(&i2c);
while(1)
{
// std::cout << "value "<< lightSens.continious(BH1750_CONTINUOUS_HIGH_RES_MODE_1,1) << " Lux" <<std::endl;
std::string Msg = std::to_string(lightSens.continious(BH1750_CONTINUOUS_HIGH_RES_MODE_1,1));
char char_array[TOTAL_CHAR_CAP];
strcpy(char_array, Msg.c_str());
lcd_display_string(2,0, char_array,5);
usleep(150*1000);
}
}
int main(int argc, char *argv[])
{
// Init
initPlatform();
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.addNewCommand("dac", "The test command for testing the mcp4725", mcp4725_test);
commander(argv[1]);
std::cout << "Main End" << std::endl;
return 1;
}