Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup of DS18B20 Temperature Sensor Handling #59

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 21 additions & 10 deletions Globals/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,27 @@ byte MoonPhase()

void ConvertNumToString(char* string, int num, byte decimal)
{
char temptxt[3];
int Temp = num;
if (Temp==0xFFFF) Temp=0;
itoa(Temp/decimal,string,10);
if (decimal>1)
{
itoa(Temp%decimal,temptxt,10);
strcat(string , ".");
if (Temp%decimal<10 && decimal==100) strcat(string , "0");
strcat(string , temptxt);
if((num < 0) && (num + decimal > 0))
{
// handle fractional negatives
*string++ = '-';
}

itoa(num/decimal,string,10);
if(decimal > 1) {
// decimal portion.
string += strlen(string);
*string++ = '.';
num = abs(num%decimal);
if(num < (decimal/10)) {
*string++ = '0';
}

if(num > 0) {
itoa(num,string,10);
} else {
*string = '\0';
}
}
}

Expand Down
18 changes: 7 additions & 11 deletions Globals/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#endif // COLORS_PDE
#include <Arduino.h>
#include <Time.h>
#include <OneWire.h>

#include <avr/pgmspace.h>

Expand Down Expand Up @@ -165,7 +164,7 @@ const prog_char NoIMCheck1[] PROGMEM = "Found";
#define HPin 1
#define PHPin 6
// issue #2 - Piezo Not needed anymore
//#define Piezo 16
//#define Piezo 16

//Digital I/O
#ifdef REEFANGEL_MINI
Expand Down Expand Up @@ -208,9 +207,9 @@ const prog_char NoIMCheck1[] PROGMEM = "Found";
#define STORE_PARAMS_TIMER 5

// Temp Sensor References
#define T1_PROBE 1
#define T2_PROBE 2
#define T3_PROBE 3
#define T1_PROBE 0
#define T2_PROBE 1
#define T3_PROBE 2

/*
EEPROM locations
Expand Down Expand Up @@ -683,19 +682,17 @@ Used by the AI Functions
#define RoyalBlue 2
const byte RawChannel[]={67,65,66};

#define MAX_TEMP_SENSORS 3

// Parameters structure, moved from RA_NokiaLCD.h to a more central location
typedef struct {
int Temp[4];
int Temp[MAX_TEMP_SENSORS];
int PH;
int Salinity;
int ORP;
int PHExp;
} ParamsStruct;

// Temperature units
#define Celsius 1
#define Fahrenheit 0

//ReefTouch Block

typedef struct Calibration
Expand Down Expand Up @@ -882,7 +879,6 @@ typedef struct {

// external globally defined variables
extern byte ButtonPress; // Defined in ReefAngel.cpp, used for joystick button presses
extern OneWire ds; // Defined in TempSensor.cpp, used for TempSensorClass
// delayed on variables, Defined in Relay.cpp
extern uint32_t LastStart;
extern byte DelayedOnPorts;
Expand Down
53 changes: 37 additions & 16 deletions RA_NokiaLCD/RA_NokiaLCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

#include <Globals.h>
#include <limits.h>
#include <Time.h>
#include "RA_NokiaLCD.h"
#include <Wire.h>
Expand Down Expand Up @@ -1177,13 +1178,13 @@ void RA_NokiaLCD::DrawCircleOutletBoxHorizontal(byte x, byte y, byte RelayData)
// designed for a layout where the plugs are aligned like:
// 8 6 4 2
// 7 5 3 1

//Variables:
byte offset = 5; //distance between given x,y location and the center of first circle
byte a = 0; //our counter of relay port
byte b = 3; //horizontal column counter
byte c = 1; //vertical row counter

//Main Loop - Starting at port 1 work our way up and left
for (a=0;a<8;a++)
{
Expand Down Expand Up @@ -1260,43 +1261,64 @@ void RA_NokiaLCD::DrawDateTimeISO8601(byte x, byte y)
char temp2[]=" ";
char temp4[]=" ";
strcpy(text,"");

// Date
itoa(year(),temp4,10);
strcat(text,temp4);
strcat(text,"-");

itoa(month(),temp2,10);
if (temp2[1]==0) strcat(text,"0");
strcat(text,temp2);
strcat(text,"-");

itoa(day(),temp2,10);
if (temp2[1]==0) strcat(text,"0");
strcat(text,temp2);
strcat(text," ");

// Time
itoa(hour(),temp2,10);
if (temp2[1]==0) strcat(text,"0");
strcat(text,temp2);
strcat(text,":");

itoa(minute(),temp2,10);
if (temp2[1]==0) strcat(text,"0");
strcat(text,temp2);
strcat(text,":");

itoa(second(),temp2,10);
if (temp2[1]==0) strcat(text,"0");
strcat(text,temp2);

DrawText(DateTextColor, DefaultBGColor, x, y, text);
}
#endif // DATETIME24

/**
* Draw a relay outlet box at the x-y coordinates using the provided relay data. Ports
* are labelled "1" through "8".
*
* @param x X coordinate for the relay outlet box.
* @param y Y coordinate for the relay outlet box.
* @param RelayData state data for the outlet box, one bit per port.
*/
void RA_NokiaLCD::DrawOutletBox(byte x, byte y,byte RelayData)
{
DrawLabelledOutletBox(x, y, RelayData, "12345678");
}

/**
* Draw a labelled relay outlet box at the x-y coordinates using the provided relay data.
*
* @param x X coordinate for the relay outlet box.
* @param y Y coordinate for the relay outlet box.
* @param RelayData state data for the outlet box, one bit per port.
* @param labels labels for each relay port.
*/
void RA_NokiaLCD::DrawLabelledOutletBox(byte x, byte y, byte RelayData, const char * labels)
{
Clear(OutletBorderColor,x,y,x+104,y); //94
Clear(OutletBorderColor,x,y+12,x+104,y+12);
for (byte a=0;a<8;a++)
Expand All @@ -1310,22 +1332,21 @@ void RA_NokiaLCD::DrawOutletBox(byte x, byte y,byte RelayData)
fcolor = OutletOnFGColor;
}
Clear(bcolor,x+(a*13),y+1,x+13+(a*13),y+11);
itoa(a+1,temp,10);
temp[0] = labels[a];
DrawText(fcolor,bcolor,x+4+(a*13),y+3,temp);
}
}

void RA_NokiaLCD::DrawSingleMonitor(int Temp, byte fcolor, byte x, byte y, byte decimal)
void RA_NokiaLCD::DrawSingleMonitor(int value, byte fcolor, byte x, byte y, byte decimal)
{
char text[7];
if ( Temp == 0xFFFF ) Temp = 0;
if (( Temp == 0 ) && ( decimal > 1 ))
char text[12];
if (value == INT_MIN)
{
strcpy(text, "Error");
strcpy_P(text, PSTR(" n/a"));
}
else
{
ConvertNumToString(text, Temp, decimal);
ConvertNumToString(text, value, decimal);
}
Clear(DefaultBGColor,x,y,x+30,y+8);
DrawText(fcolor,DefaultBGColor,x,y,text);
Expand Down
1 change: 1 addition & 0 deletions RA_NokiaLCD/RA_NokiaLCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class RA_NokiaLCD
void DrawDateTimeISO8601(byte x, byte y);
#endif // defined(DATETIME24)
void DrawOutletBox(byte x, byte y, byte RelayData);
void DrawLabelledOutletBox(byte x, byte y, byte RelayData, const char * labels);
#if defined DisplayLEDPWM && ! defined RemoveAllLights
void DrawMonitor(byte x, byte y, ParamsStruct Params, byte DaylightPWMValue, byte ActinicPWMValue);
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
Expand Down