commit 0b95847b308d66f4ead2d53bc99218df168c7995 Author: Denis Denisov Date: Sun Apr 19 10:21:55 2020 +0300 Initial commit diff --git a/.cproject b/.cproject new file mode 100644 index 0000000..c31fccb --- /dev/null +++ b/.cproject @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f240e72 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Debug/ diff --git a/.project b/.project new file mode 100644 index 0000000..beeeacb --- /dev/null +++ b/.project @@ -0,0 +1,27 @@ + + + defrost + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + org.eclipse.cdt.core.ccnature + + diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml new file mode 100644 index 0000000..c889b83 --- /dev/null +++ b/.settings/language.settings.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.settings/org.eclipse.cdt.managedbuilder.core.prefs b/.settings/org.eclipse.cdt.managedbuilder.core.prefs new file mode 100644 index 0000000..dc91d16 --- /dev/null +++ b/.settings/org.eclipse.cdt.managedbuilder.core.prefs @@ -0,0 +1,13 @@ +eclipse.preferences.version=1 +environment/buildEnvironmentInclude/com.intel.iotdevkit.ide.config.gnu.cross.exe.debug.452830329/CPATH/delimiter=; +environment/buildEnvironmentInclude/com.intel.iotdevkit.ide.config.gnu.cross.exe.debug.452830329/CPATH/operation=remove +environment/buildEnvironmentInclude/com.intel.iotdevkit.ide.config.gnu.cross.exe.debug.452830329/CPLUS_INCLUDE_PATH/delimiter=; +environment/buildEnvironmentInclude/com.intel.iotdevkit.ide.config.gnu.cross.exe.debug.452830329/CPLUS_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/com.intel.iotdevkit.ide.config.gnu.cross.exe.debug.452830329/C_INCLUDE_PATH/delimiter=; +environment/buildEnvironmentInclude/com.intel.iotdevkit.ide.config.gnu.cross.exe.debug.452830329/C_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/com.intel.iotdevkit.ide.config.gnu.cross.exe.debug.452830329/append=true +environment/buildEnvironmentInclude/com.intel.iotdevkit.ide.config.gnu.cross.exe.debug.452830329/appendContributed=true +environment/buildEnvironmentLibrary/com.intel.iotdevkit.ide.config.gnu.cross.exe.debug.452830329/LIBRARY_PATH/delimiter=; +environment/buildEnvironmentLibrary/com.intel.iotdevkit.ide.config.gnu.cross.exe.debug.452830329/LIBRARY_PATH/operation=remove +environment/buildEnvironmentLibrary/com.intel.iotdevkit.ide.config.gnu.cross.exe.debug.452830329/append=true +environment/buildEnvironmentLibrary/com.intel.iotdevkit.ide.config.gnu.cross.exe.debug.452830329/appendContributed=true diff --git a/defrost.launch b/defrost.launch new file mode 100644 index 0000000..664314a --- /dev/null +++ b/defrost.launch @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/defrost.cpp b/src/defrost.cpp new file mode 100644 index 0000000..f1b19f9 --- /dev/null +++ b/src/defrost.cpp @@ -0,0 +1,112 @@ + +#include "grove.h" +#include "jhd1313m1.h" +#include "mraa/common.hpp" +#include "mraa/gpio.hpp" + +#include +#include +#include +#include + +#define GPIO_PIN_1 2 + +void temperature_update(upm::GroveTemp* temperature_sensor, upm::Jhd1313m1 *lcd) +{ + // minimum and maximum temperatures registered, the initial values will be + // replaced after the first read + static int min_temperature = INT_MAX; + static int max_temperature = INT_MIN; + + // the temperature range in degrees Celsius, + // adapt to your room temperature for a nicer effect! + const int TEMPERATURE_RANGE_MIN_VAL = 18; + const int TEMPERATURE_RANGE_MAX_VAL = 31; + + // other helper variables + int temperature; // temperature sensor value in degrees Celsius + float fade; // fade value [0.0 .. 1.0] + uint8_t r, g, b; // resulting LCD backlight color components [0 .. 255] + std::stringstream row_1, row_2; // LCD rows + + // update the min and max temperature values + temperature = temperature_sensor->value(); + + if (temperature < min_temperature) { + min_temperature = temperature; + } + if (temperature > max_temperature) { + max_temperature = temperature; + } + + // display the temperature values on the LCD + row_1 << "Temp " << temperature << " "; + row_2 << "Min " << min_temperature << " Max " << max_temperature << " "; + lcd->setCursor(0,0); + lcd->write(row_1.str()); + lcd->setCursor(1,0); + lcd->write(row_2.str()); + + // set the fade value depending on where we are in the temperature range + if (temperature <= TEMPERATURE_RANGE_MIN_VAL) { + fade = 0.0; + } else if (temperature >= TEMPERATURE_RANGE_MAX_VAL) { + fade = 1.0; + } else { + fade = (float)(temperature - TEMPERATURE_RANGE_MIN_VAL) / + (TEMPERATURE_RANGE_MAX_VAL - TEMPERATURE_RANGE_MIN_VAL); + } + + // fade the color components separately + r = (int)(255 * fade); + g = (int)(64 * fade); + b = (int)(255 * (1 - fade)); + + // apply the calculated result + lcd->setColor(r, g, b); +} + +int main() +{ + // check that we are running on Galileo or Edison + mraa_platform_t platform = mraa_get_platform_type(); + if ((platform != MRAA_INTEL_GALILEO_GEN1) && + (platform != MRAA_INTEL_GALILEO_GEN2) && + (platform != MRAA_INTEL_EDISON_FAB_C)) + { + std::cerr << "Unsupported platform, exiting" << std::endl; + return MRAA_ERROR_INVALID_PLATFORM; + } + + mraa::Gpio gpio(GPIO_PIN_1); + mraa_result_t status = gpio.dir(mraa::DIR_OUT); + if (status != MRAA_SUCCESS) + { + return EXIT_FAILURE; + } + + // temperature sensor connected to A0 (analog in) + upm::GroveTemp* temp_sensor = new upm::GroveTemp(0); + + // LCD connected to the default I2C bus + upm::Jhd1313m1* lcd = new upm::Jhd1313m1(0); + + if ((temp_sensor == NULL) || (lcd == NULL)) + + { + std::cerr << "Can't create all objects, exiting" << std::endl; + return MRAA_ERROR_UNSPECIFIED; + } + + int io_value = 1; + // loop forever updating the temperature values every second + for (;;) { + temperature_update(temp_sensor, lcd); + gpio.write(io_value); + io_value = 1 - io_value; + std::cerr << io_value << "\n"; + sleep(1); + } + + return MRAA_SUCCESS; +}