Skip to content

Commit

Permalink
#4 project format def, code formats, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Davis committed Feb 28, 2020
1 parent 300f6ae commit 42453d0
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 169 deletions.
3 changes: 3 additions & 0 deletions teensy_fan_controller/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions teensy_fan_controller/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions teensy_fan_controller/.idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions teensy_fan_controller/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void FanData::doRPM()
void FanData::writePWM(const uint8_t pout) const
{
if (cfg.pinPWM) {
analogWrite(cfg.pinPWM, (int)(pout * cfg.ratio));
analogWrite(cfg.pinPWM, (int) (pout * cfg.ratio));
}
}

Expand Down Expand Up @@ -104,7 +104,7 @@ float SensorData::getAverage() const
{
// average all the samples out
float average = 0;
size_t i;
uint16_t i;
for (i = 0; i < NUMSAMPLES; i++) {
average += samples[i];
}
Expand All @@ -122,7 +122,7 @@ float SensorData::getAverage() const
@param beta Beta coefficient of the thermistor (usually 3000-4000)
@param seriesR Value of the 'other' resistor
*/
/*static */float SensorData::convert_reading(float reading, uint16_t nominalR, uint8_t nominalTemp, uint16_t beta, uint16_t seriesR)
/*static */float SensorData::convert_reading(float reading, const uint16_t nominalR, const uint8_t nominalTemp, const uint16_t beta, const uint16_t seriesR)
{
// convert value1 to resistance
reading = (ADC_RANGE / reading) - 1;
Expand All @@ -139,7 +139,7 @@ float SensorData::getAverage() const
}


int read_config(byte bytes[], size_t len)
int read_config(byte bytes[], const uint16_t len)
{
memset(bytes, '\0', len);
uint16_t i;
Expand All @@ -149,7 +149,7 @@ int read_config(byte bytes[], size_t len)
return 0;
}

int write_config(const byte bytes[], size_t len)
int write_config(const byte bytes[], const uint16_t len)
{
uint16_t i;
for (i = 0; i < len; i++) {
Expand Down
11 changes: 7 additions & 4 deletions teensy_fan_controller/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
//#define DISABLE_EEPROM // disable EEPROM
#define USB_RAWHID_EN // enable RawHID

//
//#define TEENSY_LC
#define TEENSY_35
//#define TEENSY_4 // RawHID not yet available in Arduino Studio?
#define FAN_CNT 6
#define PERIOD_UPDATE 100 // how often to read ADC / update PID
#define PERIOD_RPM 500

// ADC coefficients:
#define PERIOD 100 // how often to read ADC / update PID
#define ADC_RESOLUTION 12
#define ADC_RANGE 4096
#define NUMSAMPLES 10 // num of samples to averages
Expand Down Expand Up @@ -79,19 +82,19 @@ struct SensorData {
void doSample();
float getAverage() const;

static float convert_reading(float reading, uint16_t nominalR, uint8_t nominalTemp, uint16_t beta, uint16_t seriesR);
static float convert_reading(float reading, const uint16_t nominalR, const uint8_t nominalTemp, const uint16_t beta, const uint16_t seriesR);
};


/**
Read EEPROM into bytes[].
*/
int read_config(byte bytes[], size_t len);
int read_config(byte bytes[], const uint16_t len);

/**
Write bytes[] into EEPROM.
*/
int write_config(const byte bytes[], size_t len);
int write_config(const byte bytes[], const uint16_t len);


#endif //TFC_CORE_H
3 changes: 2 additions & 1 deletion teensy_fan_controller/hid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ uint8_t HID::send()
// config requested, transmit (all) config packets

// copy entire configuration into config_bytes
if (ctrl.config.to_bytes(config_bytes, CONFIG_BYTES) != 0) {
if (ctrl.config.toBytes(config_bytes, CONFIG_BYTES) != 0) {
setState(HID_DATA);
return -1; // TODO errno
}

Expand Down
4 changes: 2 additions & 2 deletions teensy_fan_controller/moving_average.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
Source: https://stackoverflow.com/a/10990893/1345237
*/
template<typename T, typename Total, size_t N>
template<typename T, typename Total, uint16_t N>
class Moving_Average {
public:
void operator()(T sample) {
Expand All @@ -32,7 +32,7 @@ class Moving_Average {

private:
T samples_[N];
size_t num_samples_{0};
uint16_t num_samples_{0};
Total total_{0};
};

Expand Down
Loading

0 comments on commit 42453d0

Please sign in to comment.