Beispiel #1
0
void lcd_command(uint8_t c){
  int fd;
  uint8_t buf[2];

  buf[0] = 0;
  buf[1] = c;
  fd = lcd_open();
  write(fd, buf, 2);
  close(fd);
}
Beispiel #2
0
/**********************************************************************
 *
 * Function: c_entry
 *
 * Purpose: Application entry point from the startup code
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 *********************************************************************/
void c_entry(void)
{
    SWIM_WINDOW_T win1;
    COLOR_T clr, *fblog;
    int idx;
    INT_32 lcddev;
    UNS_16 xgs, ygs, curx, cury, curym, xidx;

    /* Disable interrupts in ARM core */
    disable_irq_fiq();

    /* Set virtual address of MMU table */
    cp15_set_vmmu_addr((void *)
		(IRAM_BASE + (256 * 1024) - (16 * 1024)));

    /* Setup miscellaneous board functions */
    phy3250_board_init();
  
    /* Setup LCD muxing for STN Color 16BPP */
    clkpwr_setup_lcd(CLKPWR_LCDMUX_TFT16, 1);

    /* Enable clock to LCD block (HCLK_EN)*/
    clkpwr_clk_en_dis(CLKPWR_LCD_CLK, 1);
	
    /* Setup LCD paramaters in the LCD controller */
    lcddev = lcd_open(CLCDC, (INT_32) &LCD_DISPLAY);

    /* Upper Panel Frame Base Address register */
    lcd_ioctl(lcddev, LCD_SET_UP_FB, PHY_LCD_FRAME_BUF); 

    /* Enable LCD controller and power signals */
    lcd_ioctl(lcddev, LCD_PWENABLE, 1);

    /* Enable LCD backlight */
    phy3250_lcd_backlight_enable(TRUE);

    /* Enable LCD power */
    phy3250_lcd_power_enable(TRUE);

    /* Set frame buffer address */
    fblog = (COLOR_T *) 
            cp15_map_physical_to_virtual(PHY_LCD_FRAME_BUF);

    /* Create a SWIM window */
    swim_window_open(&win1, LCD_DISPLAY.pixels_per_line,
        LCD_DISPLAY.lines_per_panel, fblog, 0, 0,
		(LCD_DISPLAY.pixels_per_line - 1), 
		(LCD_DISPLAY.lines_per_panel - 1),1, WHITE, BLACK, BLACK);

    /* Compute vertical size for bars */
    ygs = LCD_DISPLAY.lines_per_panel / 3;

    /* Draw Red bars */
    cury = 0;
    curx = 0;
    curym = ygs - 1;
    xgs = LCD_DISPLAY.pixels_per_line / RED_COLORS;
    clr = BLACK;
    for (xidx = 0; xidx < RED_COLORS; xidx++)
    {
        swim_set_pen_color(&win1, clr);
        for (idx = 0; idx <= xgs; idx++)
        {
            swim_put_line(&win1, curx, cury, curx, curym);
            curx++;
        }
        clr = clr + 0x0800;
        }

    /* Draw green bars */
    cury = cury + ygs;
    curx = 0;
    curym = cury + (ygs - 1);
    xgs = LCD_DISPLAY.pixels_per_line / GREEN_COLORS;
    clr = BLACK;
    for (xidx = 0; xidx < GREEN_COLORS; xidx++)
    {
        swim_set_pen_color(&win1, clr);
        for (idx = 0; idx <= xgs; idx++)
        {
            swim_put_line(&win1, curx, cury, curx, curym);
            curx++;
        }
        clr = clr + 0x0020;
    }

    /* Draw blue bars */
    cury = cury + ygs;
    curx = 0;
    curym = cury + (ygs - 1);
    xgs = LCD_DISPLAY.pixels_per_line / BLUE_COLORS;
    clr = BLACK;
    for (xidx = 0; xidx < BLUE_COLORS; xidx++)
    {
        swim_set_pen_color(&win1, clr);
        for (idx = 0; idx <= xgs; idx++)
        {
            swim_put_line(&win1, curx, cury, curx, curym);
            curx++;
        }
        clr = clr + 0x0001;
    }
}
Beispiel #3
0
/***********************************************************************
 *
 * Function: c_entry
 *
 * Purpose: Application entry point from the startup code
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Always returns 1, or <0 on an error
 *
 * Notes: None
 *
 **********************************************************************/
int c_entry(void)
{
  SWIM_WINDOW_T win1;
  COLOR_T *fblog;
  INT_32 lcddev;

  /* Disable interrupts in ARM core */
  disable_irq_fiq();

  /* Setup miscellaneous board functions */
  phy3250_board_init();

  /* Set virtual address of MMU table */
  cp15_set_vmmu_addr((void *)
                     (IRAM_BASE + (256 * 1024) - (16 * 1024)));

  /* Initialize interrupt system */
  int_initialize(0xFFFFFFFF);

  /* Install standard IRQ dispatcher at ARM IRQ vector */
  int_install_arm_vec_handler(IRQ_VEC, (PFV) lpc32xx_irq_handler);

  /* Install RTC interrupt handler as a IRQ interrupts */
  int_install_irq_handler(IRQ_RTC, (PFV) rtc_user_interrupt);

  /* Open RTC */
  rtcdev = rtc_open(RTC, 0);
  if (rtcdev == 0)
  {
    /* Error */
    return -1;
  }

  /* Set a 1s match rate */
  secs = lsecs = 0;
  mstp.match_num      = 0;
  mstp.use_match_int  = TRUE;
  mstp.enable_onsw    = FALSE;
  mstp.match_tick_val = secs + 1;
  rtc_ioctl(rtcdev, RTC_ENABLE, 0);
  rtc_ioctl(rtcdev, RTC_SET_COUNT, 0);
  rtc_ioctl(rtcdev, RTC_CLEAR_INTS, RTC_MATCH0_INT_STS);
  rtc_ioctl(rtcdev, RTC_SETUP_MATCH, (INT_32) &mstp);

  /* Setup LCD muxing for STN Color 16BPP */
  clkpwr_setup_lcd(CLKPWR_LCDMUX_TFT16, 1);

  /* Enable clock to LCD block (HCLK_EN)*/
  clkpwr_clk_en_dis(CLKPWR_LCD_CLK, 1);

  /* Setup LCD paramaters in the LCD controller */
  lcddev = lcd_open(CLCDC, (INT_32) & LCD_DISPLAY);

  /* Upper Panel Frame Base Address register */
  lcd_ioctl(lcddev, LCD_SET_UP_FB, PHY_LCD_FRAME_BUF);

  /* Enable LCD controller and power signals */
  lcd_ioctl(lcddev, LCD_PWENABLE, 1);

  /* Enable LCD backlight */
  phy3250_lcd_backlight_enable(TRUE);

  /* Enable LCD power */
  phy3250_lcd_power_enable(TRUE);

  /* Set frame buffer address */
  fblog = (COLOR_T *) cp15_map_physical_to_virtual(PHY_LCD_FRAME_BUF);

  /* Create a SWIM window */
  swim_window_open(&win1, LCD_DISPLAY.pixels_per_line,
                   LCD_DISPLAY.lines_per_panel, fblog, 0, 0,
                   (LCD_DISPLAY.pixels_per_line - 1), (LCD_DISPLAY.lines_per_panel - 1),
                   1, WHITE, BLACK, BLACK);
  swim_put_ltext(&win1, "RTC example: This example will print the message "
                 "TICK whenever an RTC interrupt occurs (1 second intervals). It will "
                 "quit after 10 seconds\n");

  /* Enable RTC (starts counting) */
  rtc_ioctl(rtcdev, RTC_ENABLE, 1);

  /* Enable RTC interrupt in the interrupt controller */
  int_enable(IRQ_RTC);

  /* Enable IRQ interrupts in the ARM core */
  enable_irq();

  /* Loop for 10 seconds and let interrupts toggle the LEDs */
  while (secs < 10)
  {
    if (lsecs < secs)
    {
      swim_put_ltext(&win1, "TICK\n");
      lsecs = secs;
    }
  }
  /* Disable RTC interrupt in the interrupt controller */
  int_disable(IRQ_RTC);

  /* Disable interrupts in ARM core */
  disable_irq_fiq();

  /* Prior to closing the RTC, the ONSW key value is set. This will
     allow the RTC to keep it's value across resets as long as RTC
   power is maintained */
  rtc_ioctl(rtcdev, RTC_SETCLR_KEY, 1);

  /* Close RTC and LCD */
  rtc_close(rtcdev);
  lcd_close(lcddev);

  return 1;
}
Beispiel #4
0
/**********************************************************************
 *
 * Function: c_entry
 *
 * Purpose: Application entry point from the startup code
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 *********************************************************************/
void c_entry(void)
{
    SWIM_WINDOW_T win1;
    COLOR_T clr, *fblog;
    int idx;
    UNS_16 xgs, ygs, curx, cury, curym, xidx;

    /* Disable interrupts in ARM core */
    disable_irq_fiq();

    /* Set virtual address of MMU table */
    cp15_set_vmmu_addr((void *)
		(IRAM_BASE + (256 * 1024) - (16 * 1024)));

	/* Initialize interrupt system */
    int_initialize(0xFFFFFFFF);

    /* Install standard IRQ dispatcher at ARM IRQ vector */
    int_install_arm_vec_handler(IRQ_VEC, (PFV) lpc32xx_irq_handler);

    /* Setup miscellaneous board functions */
    phy3250_board_init();

    /* enable clock to ADC block - 32KHz clock */
    clkpwr_clk_en_dis(CLKPWR_ADC_CLK,1);

    /* TSC IRQ goes active when the FIFO reaches the Interrupt level */
    int_install_irq_handler(IRQ_TS_IRQ, (PFV) tsc_user_interrupt);

    /* Enable interrupt */
    int_enable(IRQ_TS_IRQ);

    /* Open TSC, sets default timing values, fifo = 16, 
	 resolution = 10bits */
    tscdev = tsc_open(TSC, 0);

    /* TSC Auto mode enable, this also sets AUTO bit */
    tsc_ioctl(tscdev,TSC_AUTO_EN, 1);
	  
    /* Setup LCD muxing for STN Color 16BPP */
    clkpwr_setup_lcd(CLKPWR_LCDMUX_TFT16, 1);

    /* Enable clock to LCD block (HCLK_EN)*/
    clkpwr_clk_en_dis(CLKPWR_LCD_CLK, 1);
	
    /* Setup LCD paramaters in the LCD controller */
    lcddev = lcd_open(CLCDC, (INT_32) &LCD_DISPLAY);

    /* Upper Panel Frame Base Address register */
    lcd_ioctl(lcddev, LCD_SET_UP_FB, PHY_LCD_FRAME_BUF); 

    /* Enable LCD controller and power signals */
    lcd_ioctl(lcddev, LCD_PWENABLE, 1);

    /* Enable LCD backlight */
    phy3250_lcd_backlight_enable(TRUE);

    /* Enable LCD power */
    phy3250_lcd_power_enable(TRUE);
	
    /* write cursor image array data to cursor image RAM */
    lcd_ioctl(lcddev, LCD_CRSR_INIT_IMG, (INT_32) &cursorimage[0]);

    /* enable the default cursor 0 */
    lcd_ioctl(lcddev,LCD_CRSR_EN,1);

    /* set the cursor X/Y position */
    lcd_ioctl(lcddev, LCD_CRSR_XY, 0x0); 

    /* set the cursor pallette BGR value, col0*/
    lcd_ioctl(lcddev, LCD_CRSR_PAL0, 0x00ff0000); 

    /* set the cursor pallette BGR value, col1 */
    lcd_ioctl(lcddev, LCD_CRSR_PAL1, 0x000000ff); 

    /* Enable IRQ interrupts in the ARM core */
    enable_irq();

    /* Set frame buffer address */
    fblog = (COLOR_T *)cp15_map_physical_to_virtual(PHY_LCD_FRAME_BUF);

    /* Create a SWIM window */
    swim_window_open(&win1, LCD_DISPLAY.pixels_per_line,
        LCD_DISPLAY.lines_per_panel, fblog, 0, 0,
		(LCD_DISPLAY.pixels_per_line - 1), 
		(LCD_DISPLAY.lines_per_panel - 1),
        1, WHITE, BLACK, BLACK);

	/* Compute vertical size for bars */
	ygs = LCD_DISPLAY.lines_per_panel / 3;

	/* Draw Red bars */
	cury = 0;
	curx = 0;
	curym = ygs - 1;
	xgs = LCD_DISPLAY.pixels_per_line / RED_COLORS;
	clr = BLACK;
	for (xidx = 0; xidx < RED_COLORS; xidx++)
	{
		swim_set_pen_color(&win1, clr);
		for (idx = 0; idx <= xgs; idx++)
		{
			swim_put_line(&win1, curx, cury, curx, curym);
			curx++;
		}

		clr = clr + 0x0800;
	}

	/* Draw green bars */
	cury = cury + ygs;
	curx = 0;
	curym = cury + (ygs - 1);
	xgs = LCD_DISPLAY.pixels_per_line / GREEN_COLORS;
	clr = BLACK;
	for (xidx = 0; xidx < GREEN_COLORS; xidx++)
	{
		swim_set_pen_color(&win1, clr);
		for (idx = 0; idx <= xgs; idx++)
		{
			swim_put_line(&win1, curx, cury, curx, curym);
			curx++;
		}

		clr = clr + 0x0020;
	}

	/* Draw blue bars */
	cury = cury + ygs;
	curx = 0;
	curym = cury + (ygs - 1);
	xgs = LCD_DISPLAY.pixels_per_line / BLUE_COLORS;
	clr = BLACK;
	for (xidx = 0; xidx < BLUE_COLORS; xidx++)
	{
		swim_set_pen_color(&win1, clr);
		for (idx = 0; idx <= xgs; idx++)
		{
			swim_put_line(&win1, curx, cury, curx, curym);
			curx++;
		}

		clr = clr + 0x0001;
	}


    /* lets stay here forever */
    while(1);

}
Beispiel #5
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;
}