Commit 5dad8923 authored by Alexander Detsch's avatar Alexander Detsch
Browse files

Temperatur-Kanäle eingeführt, um alle Sensoren an einem Pin zusammendfassen zu können.

parent 0d3caa8c
......@@ -107,7 +107,7 @@
</ListValues>
</avrgcccpp.linker.libraries.Libraries>
<avrgcccpp.linker.miscellaneous.LinkerFlags>-Wl,-u,vfprintf -lprintf_flt -lm</avrgcccpp.linker.miscellaneous.LinkerFlags>
</AvrGccCpp>
</AvrGccCpp>
</ToolchainSettings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
......@@ -165,7 +165,7 @@
</avrgcccpp.linker.libraries.Libraries>
<avrgcccpp.linker.miscellaneous.LinkerFlags>-Wl,-u,vfprintf -lprintf_flt -lm</avrgcccpp.linker.miscellaneous.LinkerFlags>
<avrgcccpp.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcccpp.assembler.debugging.DebugLevel>
</AvrGccCpp>
</AvrGccCpp>
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
......@@ -175,6 +175,18 @@
<Compile Include="lib\DS1820.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="lib\TempChannel.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="lib\TempChannel.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="lib\Time.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="lib\Time.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="lib\UART.cpp">
<SubType>compile</SubType>
</Compile>
......
......@@ -8,6 +8,7 @@
#include "DS1820.h"
DS1820::DS1820() {} // empty constructor which do nothing
// default constructor
DS1820::DS1820(uint8_t volatile *ddr, uint8_t volatile *pin, uint8_t volatile *port, uint8_t bitpos)
{
......
......@@ -88,6 +88,7 @@ private:
public:
// Datenrichtungsregister, Pin-register fr Eingang, Port-Register fr Ausgang, Pinposition.
// Beispiel: DS1820 ds1820(&DDRD, &PIND, &PORTD, PD0); --> Sensoren hngen an Pin PD0
DS1820(); // just provide an empty constructor whcih do nothing
DS1820(uint8_t volatile *ddr, uint8_t volatile *pin, uint8_t volatile *port, uint8_t bitpos);
~DS1820();
bool readRom(uint8_t* rom);
......
/** \file TempChannel.cpp
* Description
*
* \author alex
* \date 03.01.2017 16:09:21
* \version 1.0
*/
#include "TempChannel.h"
// default constructor
TempChannel::TempChannel(uint8_t volatile *ddr, uint8_t volatile *pin, uint8_t volatile *port, uint8_t bitpos) {
ds1820 = DS1820(ddr, pin, port, bitpos);
} //TempChannel
void TempChannel::schedule() {
switch (state) {
case TCS_RETRIEVAL_START:
break;
case TCS_IDLE:
case default:
return;
}
}
int32_t TempChannel::getMinTemp() {
return 0;
}
// default destructor
TempChannel::~TempChannel() {
} //~TempChannel
/** \file TempChannel.h
* Concentrate the queries of related sensors in one interface.
* Providing functions for requesting the min/max/avg temperature of this channel
* calculates several values out of all sensors on this channel (pin)
*
* \author Alexander Detsch
* \date 03.01.2017 16:09:21
* \version 1.0
*/
#ifndef __TEMPCHANNEL_H__
#define __TEMPCHANNEL_H__
#include "DS1820.h"
#include <inttypes.h>
#define MAX_NUMBER_PER_CHANNEL 10
#define TCS_IDLE 0 // TempChannelState
#define TCS_RETRIEVAL_START 1
#define TCS_RETRIEVAL_FINISHED 2
class TempChannel {
//variables
public:
protected:
private:
uint8_t state = 0;
// state-variables for the state-machine
uint32_t retrievingStarted = 0; // time when the retrieving of the current sensor has started
uint8_t currentlyRetrievedSensorIndex = -1;
DS1820 ds1820;
uint8_t sensorRom[MAX_NUMBER_PER_CHANNEL][8]; // storage for the recognized sensor-IDs. We only check them once at startup
// stores the indices of the calculated values in thousandths of one degree celsius
uint8_t minTempIndex = 0;
uint8_t maxTempIndex = 0;
uint8_t avgTempIndex = 0;
//functions
public:
TempChannel(uint8_t volatile *ddr, uint8_t volatile *pin, uint8_t volatile *port, uint8_t bitpos);
~TempChannel();
int32_t getMinTemp();
int32_t getMaxTemp();
int32_t getAvgTemp();
void startRetrieval(); // starts the retrieval of the sensors. Works asynchronous
void schedule();
protected:
private:
TempChannel( const TempChannel &c );
TempChannel& operator=( const TempChannel &c );
getSensorID(uint8_t sensorIndex);
}; //TempChannel
#endif //__TEMPCHANNEL_H__
/** \file Time.cpp
* Provides a millisecond accurately absolute system-time
* Uses the 8-bit Timer0 for counting
*
* \author Alexander Detsch
* \date 03.06.2016 10:27:16
* \version 1.0
*/
#include "Time.h"
volatile uint32_t Time::absMillis = 0;
// default constructor
Time::Time() {
start(); // Start timer
} //Time
// default destructor
Time::~Time() {
cli();
stop(); // stop the timer
absMillis = 0; // reset the time
sei();
} //~Time
/**
@brief Initialization of Time
Initialize the timer and variables
*/
void Time::start() {
cli();
absMillis = 0; // Set the time to a defined 0
TCNT0 = 0; // aktuellen Zählerstand auf 0 setzen
TIMSK0 |= (1<<OCIE0A); // Compare Interrupt erlauben
TCCR0A |= (1<<WGM01); // CTC Modus
TCCR0B |= (1<<CS00) | (1<<CS01) | (1<<ICES1); // Vorteiler 64, rising edge
OCR0A = 249-1; // Nach 249 Schritten überlaufen (Index 0) --> Genau jede 1ms
sei();
}
/**
@brief Stops the Time
Stops the timer e.g. to reduce system load
*/
void Time::stop() {
cli();
TCCR0B &= ~(1<<CS00) | ~(1<<CS01) | ~(1<<CS02); // Timer deaktivieren
sei();
}
/**
@brief Retrieve the current absolute system time.
@return the current system time in milliseconds
*/
uint32_t Time::millis() {
unsigned long timeTemp = 0;
cli(); // to prevent an interrupt while reading the time
timeTemp = absMillis;
sei();
return timeTemp;
}
/**
@brief Increments the millisecond counter
static function for the timer to increment the milliseconds
*/
void Time::timeInc() {
absMillis++;
}
ISR(TIMER0_COMPA_vect) {
Time::timeInc();
}
\ No newline at end of file
/** \file Time.h
* Provides a millisecond accurately absolute system-time
* Uses the 8-bit Timer0 for counting
*
* \author Alexander Detsch
* \date 03.06.2016 10:27:16
* \version 1.0
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stddef.h>
#include <inttypes.h>
#ifndef __TIME_H__
#define __TIME_H__
class Time
{
//variables
public:
static volatile uint32_t absMillis; // storage for the absolute system time
protected:
private:
//functions
public:
Time();
~Time();
static void start(); // Start the timer. You don´t have to do this.
static void stop(); // Stop the timer. For whatever reason you will need this.
static uint32_t millis(); // get the current time
static void timeInc(); // Only for the ISR. Not for you!
protected:
private:
Time( const Time &c );
Time& operator=( const Time &c );
}; //Time
#endif //__TIME_H__
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment