/*
   calcRH002
   Bereken de spanningen bij een bepaalde temperatuur voor een RH002 vochtsensor
   
   Pros 2013
 */


#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>

#define ROWS    7

double          R[ROWS][15] = {
    {4000.02100.01175.0612.0335.0210.0125.089.062.041.030.021.515.310.27.93},       //  5
    {4000.01620.0874.0465.0275.0166.0107.876.150.735.125.618.312.88.987.05},        // 10
    {2290.01250.0650.0353.0226.0131.093.065.041.530.021.915.610.77.915.75},         // 15
    {1822.0942.0482.0286.0175.0112.079.552.935.925.118.613.19.46.544.75},           // 20
    {1450.0710.0358.0232.0145.095.068.043.031.021.015.811.0,  8.2,  5.4,  3.9},           // 25
    {1063.0523.0292.0187.0114.078.655.337.126.618.613.19.326.594.583.23},           // 30
    {780.0385.0238.0150.097.065.045.032.022.916.510.87.95.33.892.66}                // 35
};

double          V = 1140.0;
//     result=$(echo "x=((1140/(${R}+31))*31)+0.5; scale=0; x/1" | bc -l)


int main(int argcchar *argv[])
{
    int             colrow;
    unsigned int    result;
    double          valtmp;

    printf("const unsigned int U[%d][15] PROGMEM = {\n    { "ROWS);
    for (row = 0row < ROWSrow++) {
        for (col = 0col < 15col++) {
            val = R[row][col];
            tmp = V / (val + 31.0);
            tmp *= 31.0;
            tmp += 0.5;
            result = (unsigned inttmp;
            if (col < 14) {
                printf("%d, "result);
            } else {
                if (row < (ROWS - 1)) {
                    printf("%d },\n    { "result);
                } else {
                    printf("%d }\n};\n "result);
                }
            }
        }
    }

    return (0);
}