This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from OpenStratos/feature/temperature
Fixed #30. Tests in Raspberry Pi pass.
- Loading branch information
Showing
21 changed files
with
219 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
bin_PROGRAMS = openstratos | ||
openstratos_SOURCES = openstratos.cpp camera/Camera.cpp gps/GPS.cpp serial/Serial.cpp battery/Battery.cpp | ||
openstratos_SOURCES = openstratos.cpp camera/Camera.cpp gps/GPS.cpp serial/Serial.cpp battery/Battery.cpp temperature/Temperature.cpp | ||
openstratos_LDADD = -lwiringPi | ||
openstratos_CPPFLAGS = -std=c++11 -Wno-unused-result | ||
|
||
EXTRA_PROGRAMS = openstratosRoot utesting | ||
openstratosRoot_SOURCES = openstratos-root.cpp camera/Camera.cpp gps/GPS.cpp serial/Serial.cpp battery/Battery.cpp | ||
openstratosRoot_SOURCES = openstratos-root.cpp camera/Camera.cpp gps/GPS.cpp serial/Serial.cpp battery/Battery.cpp temperature/Temperature.cpp | ||
openstratosRoot_CPPFLAGS = -std=c++11 -Wno-unused-result | ||
|
||
utesting_SOURCES = testing/testing.cpp camera/Camera.cpp gps/GPS.cpp serial/Serial.cpp battery/Battery.cpp | ||
utesting_SOURCES = testing/testing.cpp camera/Camera.cpp gps/GPS.cpp serial/Serial.cpp battery/Battery.cpp temperature/Temperature.cpp | ||
utesting_CPPFLAGS = -std=c++11 -Itesting/bandit -Wno-unused-result -DOS_TESTING |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
printf "Installing WiringPi\n" | ||
git clone https://github.com/OpenStratos/WiringPi.git > /dev/null | ||
cd WiringPi | ||
./build > /dev/null | ||
cd .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "Temperature.hpp" | ||
#include "../constants.hpp" | ||
#include <wiringPiI2C.h> | ||
#include <string> | ||
#include <thread> | ||
#include <chrono> | ||
|
||
using namespace std; | ||
using namespace os; | ||
|
||
Temperature::~Temperature() | ||
{ | ||
if (this->reading) | ||
this->stop_reading(); | ||
} | ||
|
||
Temperature::Temperature(const int address) | ||
{ | ||
this->reading = false; | ||
this->stopped = true; | ||
#ifndef OS_TESTING | ||
int fh = wiringPiI2CSetup(address); | ||
if (fh != -1) | ||
{ | ||
this->address = address; | ||
this->filehandle = fh; | ||
} | ||
else | ||
{ | ||
// TODO Log error | ||
//printf("An error ocurred initializing I2C Temperature module\n"); | ||
} | ||
#endif | ||
} | ||
|
||
void Temperature::start_reading() | ||
{ | ||
if ( ! this->reading) | ||
{ | ||
this->reading = true; | ||
this->stopped = false; | ||
thread t(&Temperature::read_temperature, this); | ||
t.detach(); | ||
} | ||
} | ||
|
||
void Temperature::stop_reading() | ||
{ | ||
this->reading = false; | ||
while( ! this->stopped); | ||
} | ||
|
||
void Temperature::read_temperature() | ||
{ | ||
while (this->reading) | ||
{ | ||
#ifndef OS_TESTING | ||
int value = wiringPiI2CRead(this->filehandle); | ||
#else | ||
int value = 16000; | ||
#endif | ||
|
||
float voltage = value * 5 / 32768; // 2^15 | ||
this->temperature = r_to_c(TEMP_R * (TEMP_VIN / voltage - 1)); | ||
|
||
this_thread::sleep_for(chrono::milliseconds(50)); | ||
} | ||
this->stopped = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef TEMPERATURE_H | ||
#define TEMPERATURE_H | ||
|
||
#include <atomic> | ||
using namespace std; | ||
|
||
namespace os { | ||
class Temperature | ||
{ | ||
private: | ||
int address; | ||
int filehandle; | ||
float temperature; | ||
atomic_bool reading; | ||
atomic_bool stopped; | ||
|
||
void read_temperature(); | ||
public: | ||
Temperature(const int address); | ||
~Temperature(); | ||
Temperature(Temperature& copy) = delete; | ||
|
||
int get_temperature() {return this->temperature;} | ||
void start_reading(); | ||
void stop_reading(); | ||
bool is_reading() {return this->reading;} | ||
}; | ||
} | ||
|
||
inline float r_to_c(float r) | ||
{ | ||
float value = r - 1000; | ||
return (value / 3.91 + value * value / 100000); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.