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:
Fri Apr 28 17:17:24 2017 +0000
Revision:
79:4e6b53eb678b
Parent:
74:749727490f44
Child:
80:959151952153
Message logger used to print most messages, bugs including commands failing need to be discussed with nicholas

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 */
Netaphous 64:8ada3e0b2048 7 CircularArray::CircularArray(int limit)
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;
Netaphous 64:8ada3e0b2048 13 }
Netaphous 64:8ada3e0b2048 14 void CircularArray::pushValue(Measure _measure)
Netaphous 64:8ada3e0b2048 15 {
Netaphous 64:8ada3e0b2048 16 if(currentSize >= maxSize)
Netaphous 64:8ada3e0b2048 17 {
Netaphous 64:8ada3e0b2048 18 firstValue++;
Netaphous 64:8ada3e0b2048 19 currentSize--;
Netaphous 64:8ada3e0b2048 20 }
aburch1 72:ef4a4e3089c1 21 int next = nextSpace();
aburch1 72:ef4a4e3089c1 22 array[next] = _measure;
Netaphous 64:8ada3e0b2048 23 currentSize++;
Netaphous 64:8ada3e0b2048 24 }
Netaphous 65:3723d2729b68 25 void CircularArray::readX(int x)
Netaphous 64:8ada3e0b2048 26 {
Netaphous 64:8ada3e0b2048 27 if(x > currentSize)
Netaphous 64:8ada3e0b2048 28 {
Netaphous 64:8ada3e0b2048 29 x = currentSize;
Netaphous 64:8ada3e0b2048 30 printf("Changed print amount to currentSize");
Netaphous 64:8ada3e0b2048 31 }
Netaphous 64:8ada3e0b2048 32 int currentElement = nextSpace() - x;
Netaphous 64:8ada3e0b2048 33 if(currentElement < 0)
Netaphous 64:8ada3e0b2048 34 {
Netaphous 64:8ada3e0b2048 35 currentElement += maxSize;
Netaphous 64:8ada3e0b2048 36 }
aburch1 79:4e6b53eb678b 37
aburch1 79:4e6b53eb678b 38 char* ptr;
Netaphous 64:8ada3e0b2048 39 for(int i = 0; i < x; i++)
Netaphous 64:8ada3e0b2048 40 {
aburch1 79:4e6b53eb678b 41 ptr = array[currentElement].date.ToString();
aburch1 74:749727490f44 42 printf("\n\r%i. %s T: %f | H: %f | P: %f |",i + 1,ptr , array[currentElement].temperature, array[currentElement].humidity, array[currentElement].pressure);
Netaphous 64:8ada3e0b2048 43 currentElement++;
Netaphous 64:8ada3e0b2048 44 currentElement = currentElement % maxSize;
Netaphous 64:8ada3e0b2048 45 }
Netaphous 64:8ada3e0b2048 46 }
Netaphous 65:3723d2729b68 47 void CircularArray::readAll()
Netaphous 64:8ada3e0b2048 48 {
Netaphous 65:3723d2729b68 49 readX(currentSize);
Netaphous 64:8ada3e0b2048 50 }
Netaphous 64:8ada3e0b2048 51 void CircularArray::deleteX(int x)
Netaphous 64:8ada3e0b2048 52 {
Netaphous 64:8ada3e0b2048 53 if(x >= maxSize)
Netaphous 64:8ada3e0b2048 54 {
Netaphous 64:8ada3e0b2048 55 deleteAll();
Netaphous 64:8ada3e0b2048 56 }
Netaphous 64:8ada3e0b2048 57 else
Netaphous 64:8ada3e0b2048 58 {
Netaphous 64:8ada3e0b2048 59 firstValue += x;
Netaphous 64:8ada3e0b2048 60 currentSize -= x;
Netaphous 64:8ada3e0b2048 61 firstValue = firstValue % maxSize;
Netaphous 64:8ada3e0b2048 62 }
Netaphous 64:8ada3e0b2048 63 }
Netaphous 64:8ada3e0b2048 64 void CircularArray::deleteAll()
Netaphous 64:8ada3e0b2048 65 {
Netaphous 64:8ada3e0b2048 66 currentSize = 0;
Netaphous 64:8ada3e0b2048 67 }
Netaphous 64:8ada3e0b2048 68 int CircularArray::getSize()
Netaphous 64:8ada3e0b2048 69 {
Netaphous 64:8ada3e0b2048 70 return currentSize;
Netaphous 64:8ada3e0b2048 71 }
Netaphous 64:8ada3e0b2048 72 int CircularArray::nextSpace()
Netaphous 64:8ada3e0b2048 73 {
Netaphous 64:8ada3e0b2048 74 int nextSpace = firstValue + currentSize;
Netaphous 64:8ada3e0b2048 75 nextSpace = nextSpace % maxSize;
Netaphous 64:8ada3e0b2048 76 return nextSpace;
Netaphous 64:8ada3e0b2048 77 }