View previous topic :: View next topic |
Author |
Message |
AndresRam
Joined: 27 May 2017 Posts: 16 Location: Colombia
|
from arduino to ccs |
Posted: Mon May 29, 2017 9:03 pm |
|
|
Hi, I am trying to pass from an arduino code (* .h and * .cpp) to the ccs (c) language.
I am not clear when using "classes" as doing the respective migration.
The idea is to make a driver for the TMD37821 sensor, if I succeed, I will publish it!
This is my arduino file * .h code and I would like a help:
Code: | class TMD37821
{
protected:
// Instance-specific properties
uint8_t tmd_conversionDelay;
tmdCommand_t tmd_command;
tmdProximityInterrupt_t tmd_proximityinterrupt;
tmdColorInterrupt_t tmd_colorinterrupt;
tmdWaitEnable_t tmd_waitenable;
tmdProximityEnable_t tmd_proximityenable;
tmdColorEnable_t tmd_colorenable;
tmdPowerEnable_t tmd_powerenable;
tmdATime_t tmd_atime;
tmdWTime_t tmd_wtime;
tmdWaitLong_t tmd_waitlong;
tmdProximityDrive_t tmd_proximitydrive;
tmdProximityOutput_t tmd_proximityoutput;
tmdColorGain_t tmd_colorgain;
public:
uint8_t tmd_i2cAddress;
tmdSensorData_t tmd_colorproxData;
void getAddr_TMD37821(uint8_t i2cAddress);
bool begin(void);
void Measure_Sensor(void);
void setUpColorProximity(void);
void Measure_Color(void);
void Measure_Proximity(void);
void setCommand(tmdCommand_t command);
tmdCommand_t getCommand(void);
void setProximityInterrupt(tmdProximityInterrupt_t proximityinterrupt);
tmdProximityInterrupt_t getProximityInterrupt(void);
void setColorInterrupt(tmdColorInterrupt_t colorinterrupt);
tmdColorInterrupt_t getColorInterrupt(void);
void setWaitEnable(tmdWaitEnable_t waitenable);
tmdWaitEnable_t getWaitEnable(void);
void setProximityEnable(tmdProximityEnable_t proximityenable);
tmdProximityEnable_t getProximityEnable(void);
void setColorEnable(tmdColorEnable_t colorenable);
tmdColorEnable_t getColorEnable(void);
void setPowerEnable(tmdPowerEnable_t powerenable);
tmdPowerEnable_t getPowerEnable(void);
void setATime(tmdATime_t atime);
tmdATime_t getATime(void);
void setWTime(tmdWTime_t wtime);
tmdWTime_t getWTime(void);
void setWaitLong(tmdWaitLong_t waitlong);
tmdWaitLong_t getWaitLong(void);
void setProximityDrive(tmdProximityDrive_t proximitydrive);
tmdProximityDrive_t getProximityDrive(void);
void setProximityOutput(tmdProximityOutput_t proximityoutput);
tmdProximityOutput_t getProximityOutput(void);
void setColorGain(tmdColorGain_t colorgain);
tmdColorGain_t getColorGain(void);
private:
}; |
after in the file *cpp:
Code: | void TMD37821::setProximityInterrupt(tmdProximityInterrupt_t proximityinterrupt)
{
tmd_proximityinterrupt = proximityinterrupt;
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue May 30, 2017 6:31 am |
|
|
Its probably faster to write your own driver and just use the arduino code as reference. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19386
|
|
Posted: Tue May 30, 2017 8:10 am |
|
|
The 'class' is a C++ feature (not C).
It allows you to group things so that they are kept together, and to also declare that some things are not public.
You don't need to use it at all. If you want to declare the 'local' stuff with extended names like
uint8_t local_tmd_conversionDelay;
so that there is no possibility of confusion with other stuff, it will avoid any possibility that the variable/function names are declared twice with different meanings.
I have to agree with Gabriel. You would produce far better code for the PIC, by just drawing out the flow chart from the Arduino code, and then creating this in CCS, rather than trying to translate. |
|
![](templates/subSilver/images/spacer.gif) |
|