Пример #1
0
void LCD_config()
{
    function_set(1,1,0);    //DL = 1 for 8-bit interface, N = 1 to set the fonts for 2 line display and if N = 1 then value of F doesn't matter

    LCD_clear_display();

    display_control(1,0,0); //D = 1, so that display is On, C = 0, so that cursor is Off, B = 0 so that cursor is not blinking
    Entry_mode_set(1,0);    // I_D = 1 so that the cursor position should increment after each character display. S = 0 because we don't want the display to shift after each character display

    _delay_ms(50);
}
Пример #2
0
int main(int argc, char* argv[])
{

 	#ifdef __linux__
 	struct sigaction sig_struct;
	sig_struct.sa_handler = sig_handler;
	sig_struct.sa_flags = 0;
	sigemptyset(&sig_struct.sa_mask);

	if (sigaction(SIGINT, &sig_struct, NULL) == -1)
    {
		cout << "Problem with sigaction" << endl;
		exit(1);
	}
	#endif // __linux__


/// ===    File read needed if moving something from PC to here
//    myFP = fopen(netname, "a+");
//    if(myFP == NULL)
//        {
//        cout<<"ERROR opening"<<endl;
//        exit(1);
//        }
//    fread(read_buf, 1, 100, myFP);
//    int buffersize = strlen(read_buf);
//    fclose(myFP);
//    cout<<"read the file: "<<read_buf<<endl;
// =============================================================

    int lcdp=lcd_open();
    int adcp=ADS1015_Init("/dev/i2c-1");

    PCA9685 myPCA={0x40, 0, 69, 0, 0, 0x11, 0x4, 50, 0x79,}; // control structure
    myPCA.file=PCA_Init("/dev/i2c-1");
    PCA9685_start(myPCA.file);

    //adcresult=read_convert_register(adcp);
    //sprintf(dis_buf, "ADC: %6.3f V", adcresult);
    //lcd_write(dis_buf);


	lcd_write("Hello from Steve's\nLCD stuff");
	lcd_clear();
	get_NIST();

	mcp23s17_enable_interrupts(GPIO_INTERRUPT_PIN);
	//mcp23s17_enable_interrupts(SW_GPIO_INTERRUPT_PIN);

	cout.setf(ios::fixed);
	//=== SET CURRENT TIME ==========================
	struct tm *newtime;								//--- for time now
	time_t long_time;								//--- Get time as long integer.
	double DeltaT=0.0;								//--- time since is in minutes

	Observer PLACENTIA={"Yorba Linda",Rad(33.909),Rad(-117.782),30.0,0};
	//Observer PHILLY={"Philly",Rad(40.0),Rad(-75.0),0.0,0};
	double sdctime;
	SATELSET Eset;
	SATPOS satpos;
	//ELLIPSE myEllipse;
	//double SP,JDG,E2JD,JDN;
	double JDG,E2JD,JDN;
	VectorIJK test,test1;           //ptest;
	//VectLook testlook;
	SATSUB SB;

	clock_t goal;
	clock_t wait=(clock_t)2 * CLOCKS_PER_SEC;       // change the 2 for update rate, 2= about 2 seconds

	Read_TLE(argv[1], Eset);                        // read the 2 line data

	do
	{
		time( &long_time );
		newtime=gmtime( &long_time );                   // time, expressed as a UTC time, GMT timezone
		JDN=JD_Now(newtime);							//--- JD based on system clock as GMT
		JDG=ThetaG_JD(JDN);								//--- in radians
		E2JD=Epoch2JD(Eset.iEpochYear,Eset.dEpochDay);	//--- JD based on TLE epoch
		double local_time=0.0;
		double test_time=0.0;

        local_time=newtime->tm_yday+1+(newtime->tm_hour+(newtime->tm_min+newtime->tm_sec/60.0)/60.0)/24.0;
        test_time=local_time-Eset.dEpochDay;
        //cout<<"test_time delta days "<<test_time<<endl;
        test_time*=1440.0;
        //cout<<"test_time delta minutes "<<test_time<<endl;

/**************************************
 local_time minus Eset.dEpochDay matches JDN-E2JD.
 And is easier to check and calculate and no need for
 all the JD and JD0 code.
*************************************/
		sdctime=JDN-E2JD;								//--- delta days
		sdctime*=1440.0;                                // delta minutes
		//sdctime=fmod(sdctime,60);
        //cout<<"Current sdctime "<<sdctime<<endl;

		DeltaT=sdctime;

        //satpos=SatPos(DeltaT, &Eset);				    //--- get satellite position
		satpos=clean_SatPos(DeltaT, &Eset);

		cout<<"=====Satellite ECI position============================\n"<<satpos;

		test=Obs_Position(PLACENTIA,JDG);				//--- get observer position
		//test1=Obs_to_ECI(PHILLY,JDG);                 //-- test data from TS Kelso
		test1=Obs_to_ECI(PLACENTIA,JDG);
		testlook=LookAngles(satpos, PLACENTIA,JDG);		//--- get look angles
		SB= SatSubPoint(satpos,JDG);

		cout<<"=====Observer ECI====================\n"<<test1;
		cout<<"=====Observer Look angles============\n"<<testlook; // for antenna tracker
		cout<<"=====Sat Sub Point===================\n"<<SB;



/// used before
    //int s_count=read_convert_register_count(adcp);
    //set_count(myPCA.file, 0, 5, s_count); // file channel, start count, end count




/// LCD setup and stuff

    adcresult=read_convert_register_volts(adcp);
    sprintf(dis_buf, "ADC: %6.3f V", adcresult);
    lcd_write(dis_buf);

    /// aztovolts is the target reference position
    double aztovolts = (Deg(testlook.AZ)) * (3.2/360.0);

    /// wtf is the difference of the pot input, adcresults, and reference
    double wtf = aztovolts - adcresult; /// double - float

    printf("\nVOLTS ADC: %6.3f V\n",adcresult);
    printf("AZ Degrees: %6.3f \n",Deg(testlook.AZ));
    printf("AZ to volts: %6.3f V\n",aztovolts);
    printf("DELTA: %6.3f \n",wtf);

    /**
    volts   0       1.6     3.2
    count   200     320     450
            max left    no motion   max right
            1 ms    1.5 ms  2ms
            50 hz timing
    **/

    /// for applying delta Vin
    //float PCAcount = (wtf*80)+320;   ///this is for  0 - 3.2 Vin
    float PCAcount = (wtf*80)+300;   ///this is for  0 - 3.2 Vin, 340 from measurements

    if(wtf< -1.25)
        PCAcount = 240;
    else if(wtf> 1.25)
            PCAcount = 425;


    //set_count(myPCA.file, 0, 5, PCAcount); // file channel, start count, end count
    set_count(myPCA.file, 0, 1, PCAcount); // file channel, start count, end count
    //set_count(myPCA.file, 1, 1, PCAcount); // file channel, start count, end count

    printf("MOTOR count: %6.3f \n",PCAcount);



//#define TRACK 0
//#define LOCATION 1
//#define SATDATA 2
//#define NIST 3

    if(display_count < 5)
    {
        display_control(TRACK, PLACENTIA, SB, Eset, testlook);
        display_count++;
        LED_off(GPIO_INTERRUPT_PIN);
    }
    else
    {
        display_control(LOCATION, PLACENTIA, SB, Eset, testlook);
        display_count++;
        LED_on(GPIO_INTERRUPT_PIN);
    }

    if(display_count > 10)
    {
        display_count = 0;
	}

        /**
            ====================
            Look angles:visible
            AZ:123456 EL:123456
            Sat LAT/LONG
            LT:123456 LG:123456
            ====================
            Location Yorba Linda
            LT:123456 LG:123456
            Range: 123456

            ====================
            Tracking:ISS (ZARYA)
            Incl:12345
            MM: 123456
            MA: 123456

        **/
/// LCD done

		goal = wait + clock();
		while( goal > clock() );

        #ifdef __linux__
        if(ctrl_c_pressed)
            {
                cout << "Ctrl^C Pressed" << endl;
                cout << "unexporting pins" << endl;
                //gpio26->unexport_gpio();
                //gpio16->unexport_gpio();
                mcp23s17_disable_interrupts(GPIO_INTERRUPT_PIN);
                //mcp23s17_disable_interrupts(SW_GPIO_INTERRUPT_PIN);

                cout << "deallocating GPIO Objects" << endl;
                //delete gpio26;
                //gpio26 = 0;
                //delete gpio16;
                //gpio16 =0;
                break;

            }
        #endif // __linux__
	}

	#ifdef __linux__
    	while(1);
    #elif _WIN32
        while(!(_kbhit()));
    #else
    #endif

	//while(1);
    //while(!(_kbhit()));

		//pthread_exit(NULL);
		set_all(myPCA.file, 0, 0);      /// kill the servos
		lcd_close();                    /// kill the LCD

	return 0;
}