Skip to content

Commit

Permalink
Fixed merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
k105la committed Aug 7, 2020
2 parents 5b4ac3b + d9a5f78 commit 7bf12f5
Show file tree
Hide file tree
Showing 11 changed files with 2,590 additions and 39 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
PanFLUte (Pneumonia analyzing node for FLU to everyone) is an open source spirometer.
It is used to measures the amount of air you're able to breathe in and out.

## Software block diagram
The block diagram representing the general scheme of the software.
<p align=center>
<img src="https://imgur.com/klRlwUa.png"/>
</p>

# Installation
### Compiling firmware in Docker
1. ```git clone https://github.com/COVID-19-electronic-health-system/PanFLUte.git```
Expand Down
2 changes: 1 addition & 1 deletion board/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MCU=attiny441
MCU=attiny841
PROGRAMMER=atmelice_isp
F_CPU=1000000
CC=avr-gcc
Expand Down
41 changes: 23 additions & 18 deletions board/adc/adc.c
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
#include "../driver/adc.h"




/** @defgroup group1 TinyADC Library
* This is a minimal ADC Library with init and read functions only.
* @{
*/

/** @brief class C1 in group 1 */

void adcInit(void) {
/* Enable ADC */
/// Enables ADC.
ADCSRA = (1 << ADEN) | (1 << ADSC);
/* Left Adjust Results */
//ADCSRB = (1 << ADLAR);
//printf("ADC has started\n");
}

/*
void getPSI(void) {
ADCSRA |= (1 << ADSC); // Start ADC conversion
float rawPresureData = ADCH; // Max is 8bit value
printf("PSI: %.2f", (rawPresureData / 255.0) * 14.5);
delay_ms(100);
float adcRead(void) {
/// Returns calibrated adc values.
float sum = 0; // Sum of averaged adc values
int adc_values_arr[N];
for (int i = 0; i < N; i++) {
while(ADCSRA & (1 << ADSC));
ADCSRA |= (1 << ADSC); // Start ADC conversion
int ten_bit_value = ADCL + (ADCH * 256);
adc_values_arr[i] = ten_bit_value;
sum += adc_values_arr[i];
}
calibrated_adc_value = floor((sum / 55.0) - OFFSET);
return calibrated_adc_value;
}

uint8_t adcStart(void) {
ADCSRA |= (1 << ADSC); // Start ADC conversion
loop_until_bit_is_clear(ADCSRA, ADSC);
uint8_t rawPresureData = ADCH; // Max is 8bit value
return rawPresureData;
}
*/
17 changes: 13 additions & 4 deletions board/driver/adc.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#ifndef ADC_H
#define ADC_H

#include <stdio.h>
#include <avr/io.h>
#include <stdint.h>
#define OFFSET 44
#include <math.h>
#include <util/delay.h>
#define OFFSET 44 // Value which offsets adc to 0
#define N 55 // Numbers of values averaged from adc

int adc_values_arr[N];
float calibrated_adc_value;
void adcInit(void);
//void getPSI(void);
//uint8_t adcStart(void);
float adcRead(void);

#endif // ADC_H
9 changes: 8 additions & 1 deletion board/driver/mpx5100.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#ifndef MPX5100_H
#define MPX5100_H

#include "../driver/adc.h"
// #define SIGNAL_OFFSET // This value corresponds to an air flow of 0
#define MAX_PRESSURE 120.0 // Pressure in KPa

float pascal, adc_val;
void getPascal(void);

#endif // MPX5100_H
5 changes: 5 additions & 0 deletions board/driver/usart.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef USART_H
#define USART_H

#include <stdio.h>
#include <stdlib.h>
#include <avr/io.h>
Expand All @@ -8,3 +11,5 @@ void usartInit(unsigned int ubrr);
void usartTransmit(unsigned char data);
unsigned char usartReceive(void);
int print(char c, FILE *stream);

#endif // USART_H
11 changes: 4 additions & 7 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
static FILE mystdout = FDEV_SETUP_STREAM(print, NULL, _FDEV_SETUP_RW);

int main(void) {
adcInit();
usartInit(MYUBRR);
adcInit();
usartInit(MYUBRR);
stdout = &mystdout;
while(1) {
while(ADCSRA & (1 << ADSC));
ADCSRA |= (1 << ADSC); // Start ADC conversion
// TODO: Must subtract ADCH from offset.
printf("PSI: %.2f\n", (ADCH / 255.0) * 14.5);
}
adcRead();
}
}
16 changes: 16 additions & 0 deletions board/mpx5100/mpx5100.c
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
#include "../driver/adc.h"


/** @defgroup group2 MPX5100 Library
* This is library interfaces with the mpx5100.
* @{
*/

/** This function return the sensor reading in Pascals. */
void getPascal(void) {
adc_val = adcRead();
pascal = ((adc_val / 1023.0) * MAX_PRESSURE) * 1000.0;
printf("%.2f Pa\n" pascal);
_delay_ms(250);
}

/** @} */ // end of group2
10 changes: 8 additions & 2 deletions board/usart/usart.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#include "../driver/usart.h"

/** @defgroup group3 USART Library
* This library contains all the neccessary code for serial transmission.
* @{
*/

/** This function enables the receiver and tranmitter.*/
void usartInit(unsigned int ubrr) {
/* Set baud rate */
UBRR0H = (unsigned char)(ubrr >> 8);
Expand All @@ -11,15 +17,15 @@ void usartInit(unsigned int ubrr) {
UCSR0A = (1 << U2X0); // Double the USART Transmission Speed
}


/** This function transmit data on the TX pin.*/
void usartTransmit(unsigned char data) {
/* Wait for empty transmit buffer */
while(!(UCSR0A & (1 << UDRE0)));
/* Put data into buffer, sends the data */
UDR0 = data;
}


/** This function receives data from the RX pin.*/
unsigned char usartReceive(void) {
/* Wait for data to be received */
while(!(UCSR0A & (1 << RXC0)));
Expand Down
Loading

0 comments on commit 7bf12f5

Please sign in to comment.