Project aiming to make a self-controlled solar reflector

Dependencies:   Accelerometer LCD Inverter Algorithm MotorDriver Anemometer GUI ArduinoJson Misc Definitions Pushbutton WebSocketClient temp_fan

main.cpp

Committer:
khaiminhvn
Date:
2021-03-12
Revision:
8:a1481d5f0572
Parent:
7:2b6438e586e6
Child:
9:6e950b9a9a81

File content as of revision 8:a1481d5f0572:

/* 
For settings of system behaviour, see Defs_sett.h
For pin assignment list, see PinAssignment.h
*/

//INCLUDES
#include "mbed.h"
#include "stdio.h"
#include "string"     // std::string, std::to_string
#include "Accelerometer.h"
#include "Anemometer.h"
#include "Algorithm.h"
#include "MotorDriver.h"
#include "Defs_Sett.h"
#include "Pushbutton.h"
#include "PinAssignment.h"
#include "LCD.h"
#include <string>

#define timer_read_s(x)     chrono::duration_cast<chrono::seconds>((x).elapsed_time()).count()

//Initialize Global Variables
I2C i2c(PIN_SDA,PIN_SCL);
Anemometer ane; //
//MotorDriver motor;
LowPowerTimer t,t_mode;
int mode = OP_CALIBRATION;

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
int main()
{
i2c.frequency(I2C_FREQ);
//Accelerometer acc(&i2c); //Accelerometer
LCD lcd(&i2c);

float ang_P,ang_R;
float ref_R1,ref_R2;
int t_elapsed;
int wthres = WIND_THRES_INIT;
char buffer[16];

//FLAGS
int flag_time = 1; //Normal mode time
int flag_idle = 0; //Idling time
int flag_disp = 1; //Anti-flickering

//PUSH BUTTONS
Pushbutton bt_fn(PIN_BTFN,&mode,&flag_disp);
Pushbutton bt_inc(PIN_BTINC);
Pushbutton bt_dec(PIN_BTDEC);

string topL = "PUT SENSORS IN";
string botL = "CALIBRATION SLOT";

t.start(); //Start timer

lcd.LCD_display(topL, botL);

while(1)
{
    switch(mode)
    {
        case OP_PLACEMENT:{
            topL = "PUT SENSOR ON";
            botL = "PANEL&REFLECTORS";
            if(flag_disp){
                lcd.LCD_display(topL,botL);
                flag_disp = 0;
            }
            
            break;
        }
////////////////////////////////////////////////////////////////////////////////
        case OP_NORMAL:{
            topL = "NORMAL";
            botL = "";
            if(flag_disp){
                lcd.LCD_display(topL,botL);
                flag_disp = 0;
            }
            
            break;
        }
////////////////////////////////////////////////////////////////////////////////
        case OP_WIND:{
            ane.checkWind(&mode);
            topL = "WIND SAFETY";
            botL = "";
            if(flag_disp){
                lcd.LCD_display(topL,botL);
                flag_disp = 0;
            }
            
            break;
        }
////////////////////////////////////////////////////////////////////////////////
        case OP_MANUAL1:{
            topL = "MANUAL: M1";
            botL = "";
            if(flag_disp){
                lcd.LCD_display(topL,botL);
                flag_disp = 0;
            }
            
            break;
        }
////////////////////////////////////////////////////////////////////////////////
        case OP_MANUAL2:{
            topL = "MANUAL: M2";
            botL = "";
            if(flag_disp){
                lcd.LCD_display(topL,botL);
                flag_disp = 0;
            }
                        
            break;
        }
////////////////////////////////////////////////////////////////////////////////
        case OP_WSETTING:{
            topL = "Threshold:";
            botL = "";
            if(flag_disp){
                lcd.LCD_display(topL,botL);
                flag_disp = 0;
            }
            
            break;
        }
    }
    wait_us(LOOP_DELAY);
}

}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////