Skip to content

Commit

Permalink
#42 fan control
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jun 18, 2021
1 parent b543a45 commit 7109fe2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/eez/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,10 @@ bool Module::isAmperAllowed(int subchannelIndex) {
return false;
}

float Module::getMaxTemperature() {
return 25.0f;
}

////////////////////////////////////////////////////////////////////////////////

struct NoneModule : public Module {
Expand Down
2 changes: 2 additions & 0 deletions src/eez/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ struct Module {

virtual bool isMicroAmperAllowed(int subchannelIndex);
virtual bool isAmperAllowed(int subchannelIndex);

virtual float getMaxTemperature();
};

static const int NUM_SLOTS = 3;
Expand Down
16 changes: 16 additions & 0 deletions src/eez/modules/dib-mio168/dib-mio168.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <float.h>

#if defined(EEZ_PLATFORM_STM32)
#include <spi.h>
Expand Down Expand Up @@ -4744,6 +4745,21 @@ struct Mio168Module : public Module {
}
return Module::isMicroAmperAllowed(subchannelIndex);
}

float getMaxTemperature() {
if (afeVersion != 4) {
float maxCurrent = FLT_MIN;
for (int i = 0; i < 4; i++) {
if (ainChannels[i].getMode() == MEASURE_MODE_CURRENT) {
maxCurrent = MAX(maxCurrent, ainChannels[i].getValue());
}
}

return clamp(remap(maxCurrent, 5.0f, FAN_MIN_TEMP, 8.0f, FAN_MAX_TEMP), 25.0f, FAN_MAX_TEMP);
}

return Module::getMaxTemperature();
}
};

////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 4 additions & 0 deletions src/eez/modules/psu/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ void tick() {
}
}

for (int i = 0; i < NUM_SLOTS; ++i) {
maxChannelTemperature = MAX(maxChannelTemperature, g_slots[i]->getMaxTemperature());
}

// check if max_channel_temperature is too high
if (isPowerUp() && maxChannelTemperature > FAN_MAX_TEMP) {
if (g_lastMaxChannelTemperature <= FAN_MAX_TEMP) {
Expand Down

0 comments on commit 7109fe2

Please sign in to comment.