Skip to content

Instantly share code, notes, and snippets.

@txomon
Last active August 29, 2015 13:56
Show Gist options
  • Save txomon/9098779 to your computer and use it in GitHub Desktop.
Save txomon/9098779 to your computer and use it in GitHub Desktop.
main.c
/*
* main implementation: use this 'C' sample to create your own application
*
*/
#define PE_MCUINIT
#include "constantes.h"
#include <stdio.h>
//#include "MCUinit.h"
//#include <Driver_SLCD.h>
//#include "derivative.h" /* include peripheral declarations */
//void MCU_init(void); /* Device initialization function declaration */
#include "constantes.h"
int temp[4] = {0, 0, 0, 0};
static inline void calcula_max(float *save, float value)
{
if(value > *save)
*save = value;
}
static inline void calcula_min(float *save, float value)
{
if(value < *save)
*save = value;
}
static inline void calcula_med(float *save, float value)
{
*save += value;
}
static inline void calcula_qua(float *save, float value)
{
*save += value * value;
}
int main(int argc, char **argv)
{
int row, column;
float *iter;
float value;
int channel;
struct resul {
float max, min, med, qua;
} res[4] = {{0, 32278, 0, 0}, {0, 32278, 0, 0}, {0, 32278, 0, 0}, {0,
32278, 0, 0}};
//int res[4][4] = {{0, 0, 0, 0}, {65535, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0,
// 0}};
iter = (float *)tabla;
for(row = 0; row < 128; row++) {
for(column = 0; column < 4; column++) {
calcula_max(&(res[column].max), *iter);
calcula_min(&(res[column].min), *iter);
calcula_med(&(res[column].med), *iter);
calcula_qua(&(res[column].qua), *iter);
iter++;
}
}
for(column = 0; column < 4; column++) {
res[column].med = res[column].med / 128;
res[column].qua = res[column].qua / 128;
}
printf("Results are:\n");
for(column = 0; column < 4; column++)
printf("\t%d Maximum: %f\n", column, res[column].max);
for(column = 0; column < 4; column++)
printf("\t%d Minimum: %f\n", column, res[column].min);
for(column = 0; column < 4; column++)
printf("\t%d Average: %f\n", column, res[column].med);
for(column = 0; column < 4; column++)
printf("\t%d Quadratic: %f\n", column, res[column].qua);
value = 0;
channel = 0;
for(column = 0; column < 4; column++) {
if(value < res[column].max) {
value = res[column].max;
channel = column;
}
}
printf("Channel %d is the max max with %f\n", channel, value);
value = 65535;
channel = 0;
for(column = 0; column < 4; column++) {
if(value > res[column].max) {
value = res[column].max;
channel = column;
}
}
printf("Channel %d is the max min with %f\n", channel, value);
value = -65565;
channel = 0;
for(column = 0; column < 4; column++) {
if(value < res[column].min) {
value = res[column].min;
channel = column;
}
}
printf("Channel %d is the min max with %f\n", channel, value);
value = 0;
channel = 0;
for(column = 0; column < 4; column++) {
if(value > res[column].min) {
value = res[column].min;
channel = column;
}
}
printf("Channel %d is the min min with %f\n", channel, value);
value = 0;
channel = 0;
for(column = 0; column < 4; column++) {
if(value < res[column].med) {
value = res[column].med;
channel = column;
}
}
printf("Channel %d is the med max with %f\n", channel, value);
value = 0;
channel = 0;
for(column = 0; column < 4; column++) {
if(value > res[column].med) {
value = res[column].med;
channel = column;
}
}
printf("Channel %d is the med min with %f\n", channel, value);
value = 0;
channel = 0;
for(column = 0; column < 4; column++) {
if(value > res[column].qua) {
value = res[column].qua;
channel = column;
}
}
printf("Channel %d is the qua max with %f\n", channel, value);
value = 0;
channel = 0;
for(column = 0; column < 4; column++) {
if(value < res[column].qua) {
value = res[column].qua;
channel = column;
}
}
printf("Channel %d is the qua min with %f\n", channel, value);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment