3rd Repo, trying to figure this out.

Dependencies:   LPS25H hts221

Fork of SOFT253_Template_Weather_OS_54 by Stage-1 Students SoCEM

Committer:
aburch1
Date:
Thu May 11 14:34:53 2017 +0000
Revision:
81:996c0a3319b4
Parent:
80:959151952153
Child:
82:668b51a39148
Changed the logger to use char arrays of a size 256 and fixed some issues that cropped up from this. Moved all printing statements over to use the logger

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Netaphous 64:8ada3e0b2048 1 #include "CircularArray.h"
Netaphous 64:8ada3e0b2048 2 #include <stdio.h>
Netaphous 64:8ada3e0b2048 3 #include <ctype.h>
Netaphous 64:8ada3e0b2048 4 /*
Netaphous 64:8ada3e0b2048 5 Constructor
Netaphous 64:8ada3e0b2048 6 */
aburch1 81:996c0a3319b4 7 CircularArray::CircularArray(int limit, MessageLogger *newLogger)
Netaphous 64:8ada3e0b2048 8 {
Netaphous 64:8ada3e0b2048 9 maxSize = limit;
Netaphous 64:8ada3e0b2048 10 array = new Measure[maxSize];
Netaphous 64:8ada3e0b2048 11 firstValue = 0;
Netaphous 64:8ada3e0b2048 12 currentSize = 0;
aburch1 81:996c0a3319b4 13 logger = newLogger;
aburch1 81:996c0a3319b4 14 }
Netaphous 64:8ada3e0b2048 15 void CircularArray::pushValue(Measure _measure)
Netaphous 64:8ada3e0b2048 16 {
Netaphous 64:8ada3e0b2048 17 if(currentSize >= maxSize)
Netaphous 64:8ada3e0b2048 18 {
Netaphous 64:8ada3e0b2048 19 firstValue++;
Netaphous 64:8ada3e0b2048 20 currentSize--;
Netaphous 64:8ada3e0b2048 21 }
aburch1 72:ef4a4e3089c1 22 int next = nextSpace();
aburch1 72:ef4a4e3089c1 23 array[next] = _measure;
Netaphous 64:8ada3e0b2048 24 currentSize++;
Netaphous 64:8ada3e0b2048 25 }
aburch1 80:959151952153 26
aburch1 80:959151952153 27 Measure CircularArray::pullValue()
aburch1 80:959151952153 28 {
aburch1 80:959151952153 29 return array[firstValue];
aburch1 80:959151952153 30 }
aburch1 81:996c0a3319b4 31 char temp2[256];
Netaphous 65:3723d2729b68 32 void CircularArray::readX(int x)
Netaphous 64:8ada3e0b2048 33 {
Netaphous 64:8ada3e0b2048 34 if(x > currentSize)
Netaphous 64:8ada3e0b2048 35 {
Netaphous 64:8ada3e0b2048 36 x = currentSize;
aburch1 81:996c0a3319b4 37 logger->SendMessage("Changed print amount to currentSize\n\r");
Netaphous 64:8ada3e0b2048 38 }
Netaphous 64:8ada3e0b2048 39 int currentElement = nextSpace() - x;
Netaphous 64:8ada3e0b2048 40 if(currentElement < 0)
Netaphous 64:8ada3e0b2048 41 {
Netaphous 64:8ada3e0b2048 42 currentElement += maxSize;
Netaphous 64:8ada3e0b2048 43 }
aburch1 79:4e6b53eb678b 44
aburch1 79:4e6b53eb678b 45 char* ptr;
Netaphous 64:8ada3e0b2048 46 for(int i = 0; i < x; i++)
Netaphous 64:8ada3e0b2048 47 {
aburch1 79:4e6b53eb678b 48 ptr = array[currentElement].date.ToString();
aburch1 81:996c0a3319b4 49 snprintf(temp2, 256, "%i. %s T: %f | H: %f | P: %f |\n\r",i + 1,ptr , array[currentElement].temperature, array[currentElement].humidity, array[currentElement].pressure);
aburch1 81:996c0a3319b4 50 logger->SendMessage(temp2);
Netaphous 64:8ada3e0b2048 51 currentElement++;
Netaphous 64:8ada3e0b2048 52 currentElement = currentElement % maxSize;
Netaphous 64:8ada3e0b2048 53 }
Netaphous 64:8ada3e0b2048 54 }
Netaphous 65:3723d2729b68 55 void CircularArray::readAll()
Netaphous 64:8ada3e0b2048 56 {
Netaphous 65:3723d2729b68 57 readX(currentSize);
Netaphous 64:8ada3e0b2048 58 }
Netaphous 64:8ada3e0b2048 59 void CircularArray::deleteX(int x)
Netaphous 64:8ada3e0b2048 60 {
Netaphous 64:8ada3e0b2048 61 if(x >= maxSize)
Netaphous 64:8ada3e0b2048 62 {
Netaphous 64:8ada3e0b2048 63 deleteAll();
Netaphous 64:8ada3e0b2048 64 }
Netaphous 64:8ada3e0b2048 65 else
Netaphous 64:8ada3e0b2048 66 {
Netaphous 64:8ada3e0b2048 67 firstValue += x;
Netaphous 64:8ada3e0b2048 68 currentSize -= x;
Netaphous 64:8ada3e0b2048 69 firstValue = firstValue % maxSize;
Netaphous 64:8ada3e0b2048 70 }
Netaphous 64:8ada3e0b2048 71 }
Netaphous 64:8ada3e0b2048 72 void CircularArray::deleteAll()
Netaphous 64:8ada3e0b2048 73 {
Netaphous 64:8ada3e0b2048 74 currentSize = 0;
Netaphous 64:8ada3e0b2048 75 }
Netaphous 64:8ada3e0b2048 76 int CircularArray::getSize()
Netaphous 64:8ada3e0b2048 77 {
Netaphous 64:8ada3e0b2048 78 return currentSize;
Netaphous 64:8ada3e0b2048 79 }
Netaphous 64:8ada3e0b2048 80 int CircularArray::nextSpace()
Netaphous 64:8ada3e0b2048 81 {
Netaphous 64:8ada3e0b2048 82 int nextSpace = firstValue + currentSize;
Netaphous 64:8ada3e0b2048 83 nextSpace = nextSpace % maxSize;
Netaphous 64:8ada3e0b2048 84 return nextSpace;
Netaphous 64:8ada3e0b2048 85 }