Hello, I am working on a project utilizing the mbed and I am new to C++ and OOP. I think you'll understand what I am trying to do by looking at the code. I think my issue is a lack of understanding regarding the proper initialization of classes and their members.
On a side note I would eventually like to incorporate Threads to handle the timing of certain functions so any advice in that direction would be very helpful.
Any assistance, even in the way of tutorials, etc would be very much appreciated.
Edit: I was able to fix my code below... not too sure what the issue was.
- I moved the constructor up to be first under public.
- I removed the ()'s from the AnalogIn declaration.
- I also changed the define statement of the file to match the actual case of the letters in the file name.
I would still be very interested in ideas regarding Threads or other ways to incorporate timing and a real-time clock (for timestamps) into this system. The rough idea I have is - sample every 5 seconds and store, average again after 5 minutes and log (will be to external SD).
Here is the code:
#ifndef POWERLOGGER_H
#define POWERLOGGER_H
#include "mbed.h"
#define maxInput 3.3
#define totalSamples 50
#define samplesPerMinute 12
class PowerLogger
{
public:
AnalogIn voltageIn(), currentIn();
typedef float pData_t;
struct pData {
pData_t voltage;
pData_t current;
pData_t voltageSamples[totalSamples];
pData_t currentSamples[totalSamples];
};
struct pData pMinute[samplesPerMinute];
PowerLogger(PinName voltagePin, PinName currentPin);
void collectSamples(unsigned char logNumber);
};
#endif
The starred spots below are where I am having trouble.
#include "PowerLogger.h"
#include "mbed.h"
PowerLogger::PowerLogger(PinName voltagePin, PinName currentPin) **: voltageIn(voltagePin), currentIn(currentPin)**
{
}
void PowerLogger::collectSamples(unsigned char logNumber)
{
for (int i = 0; i < totalSamples; i++) {
pMinute[logNumber].voltageSamples[i] = **voltageIn.read();**
wait_ms(1);
pMinute[logNumber].currentSamples[i] = **currentIn.read();**
wait_ms(1);
}
for (int i = 0; i < totalSamples; i++) {
pMinute[logNumber].voltage += pMinute[logNumber].voltageSamples[i];
pMinute[logNumber].current += pMinute[logNumber].currentSamples[i];
}
pMinute[logNumber].voltage /= totalSamples;
pMinute[logNumber].current /= totalSamples;
}
Thank you.
Hello, I am working on a project utilizing the mbed and I am new to C++ and OOP. I think you'll understand what I am trying to do by looking at the code. I think my issue is a lack of understanding regarding the proper initialization of classes and their members.
On a side note I would eventually like to incorporate Threads to handle the timing of certain functions so any advice in that direction would be very helpful.
Any assistance, even in the way of tutorials, etc would be very much appreciated.
Edit: I was able to fix my code below... not too sure what the issue was. - I moved the constructor up to be first under public. - I removed the ()'s from the AnalogIn declaration. - I also changed the define statement of the file to match the actual case of the letters in the file name.
I would still be very interested in ideas regarding Threads or other ways to incorporate timing and a real-time clock (for timestamps) into this system. The rough idea I have is - sample every 5 seconds and store, average again after 5 minutes and log (will be to external SD).
Here is the code:
The starred spots below are where I am having trouble.
Thank you.