MAIN

Dependencies:   LPS25H hts221

Fork of SOFT253_Template_Weather_OS_54 by Stage-1 Students SoCEM

log.cpp

Committer:
J_Satchell
Date:
2017-05-15
Revision:
36:af6abc6f7590
Child:
37:13f74964a045

File content as of revision 36:af6abc6f7590:

#include "Data.hpp"

Data queue_array[120];
int rear = 0;
int front = 0;

Mutex mutex_l;

void log_init()
{

}

void log_push(Data data)
{
    rear = (rear + 1) % 120;
    
    if (rear == front){
        front = (front + 1) % 120;        
    }
    
    queue_array[rear] = data;    
}

Data log_pop()
{
    Data record;
    if (front != rear)
            {   record = queue_array[rear];             
                rear = (rear + 1) % 120;
            }
        return record;
        
}

int log_length()
{
    
    int length;
    length = (120 + rear - front) % 120; 
    
    return length;
    
}

Data log_get(int index)
{
    
    Data record;
    record = queue_array[(front + index) % 120];
    
    return record;
    
}