CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

from arduino to ccs

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
AndresRam



Joined: 27 May 2017
Posts: 16
Location: Colombia

View user's profile Send private message

from arduino to ccs
PostPosted: Mon May 29, 2017 9:03 pm     Reply with quote

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;
}
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue May 30, 2017 6:31 am     Reply with quote

Its probably faster to write your own driver and just use the arduino code as reference.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Tue May 30, 2017 8:10 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group