Esempio n. 1
0
static bool_t try_open_file()
{
    uint16_t result;

    sampleFileIsOpen = bFalse;
    while(bTrue)
    {
        // Make file name
        tiny_sprintf(samplesFileName, "0:DATA%d.TXT", fileCounter);

        result = f_open(&samplesFile, samplesFileName, FA_CREATE_NEW | FA_WRITE);

        if(result == FR_EXIST)
        {
            if(++fileCounter > 9999) // Cannot create file
            {
                fileCounter = 0;
                return bFalse;
            }
        }
        else if(result == FR_OK)
        {
            sampleFileIsOpen = bTrue;

            // Write file HEADER
            tiny_fprintf(&samplesFile, "TIME\tP\tH\tT\tPF\tHF\tTF\tPR\tHR\tTR\r\n");

            return bTrue;
        }
        else
            return bFalse;
    }
}
Esempio n. 2
0
void run_printf_test( void )
{
    uint16_t uval = 0;
    int16_t ival = 0;

    hal_initialize();

    gfx_init();
    backlight_init();
    backlight_set_brightness(90);
    tty_enable_view(bTrue);

#ifdef TEST_FOREVER
    for(;;)
#endif
    {
        tiny_sprintf(buffer, "test: %u, %d, %x, %B", ival, ival, ival, ival);

        tiny_printf("uint: %u, int: %d, hex: %x or %X, bhex: %b or %B, escape: %%\n",
                uval, ival, uval, uval, uval, uval);

        tiny_printf("string test %d: %s (OK)\n", uval, buffer);

        uval++;
        ival = ival > 0 ? -uval : uval;

        delay_ms(500);
    }
}
Esempio n. 3
0
int main(void)
{
	/*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32l1xx_md.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
*/
  /* Configure Clocks for Application need */
  RCC_Configuration();
  uint8_t rxBuf[4];
  uint8_t txBuf[16];

  uint8_t chByte[2];
  uint8_t chMainStep=MAIN_STEP_IDLE;
  int16_t* iCurentAdcValue=(int16_t*)chByte; // теперь тут будет лежать последнее измеренное число
  /* Configure RTC Clocks */
  RTC_Configuration();

  /* Enable debug features in low power modes (Sleep, STOP and STANDBY) */
#ifdef  DEBUG_SWD_PIN
  DBGMCU_Config(DBGMCU_SLEEP | DBGMCU_STOP | DBGMCU_STANDBY, ENABLE);
#endif
  
  /* Configure SysTick IRQ and SysTick Timer to generate interrupts */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 500);

  /* Init I/O ports */
  conf_analog_all_GPIOS();   /* configure all GPIOs as analog input */

  InitButton();
  MesureCurInit();

  LCD_GLASS_Init();/* Initializes the LCD glass */

//  RCC_AHBPeriphClockCmd(LD_GPIO_PORT_CLK , ENABLE);
  //RCC_AHBPeriphClockCmd(LD_GPIO_PORT_CLK 		| P_GATE1_GPIO_PORT_CLK |
///		  	  	  	  P_GATE2_GPIO_PORT_CLK 	| N_GATE1_GPIO_PORT_CLK |
//		  	  	  	  N_GATE2_GPIO_PORT_CLK		, ENABLE);

  Delay.Init();
  DbgUART.UART_Init(USART3);
  i2cMgr.SetDbgUART(&DbgUART);
  i2cMgr.Init();
  calipers.Init();
  calipers.Callback=CallBackCalipers;



  // Setup i2cCmd  to write config data to ADC
  txBuf[0]=0x88; //Bits 3 and 2 control the ADS1100Тs data rate "1 0"= 16SPS
  I2C_command.Address=0x48;
  I2C_command.DataToRead.Length = 0;
  I2C_command.DataToRead.Buf=rxBuf;
  I2C_command.DataToWrite.Buf = txBuf;
  I2C_command.DataToWrite.Length = 1;
  I2C_command.Callback=CallBackI2C;
  i2cMgr.AddCmd(I2C_command);

  // Setup i2cCmd  to read data from ADC
  I2C_command.Address=0x48;
  I2C_command.DataToRead.Length = 4;
  I2C_command.DataToRead.Buf=rxBuf;
  I2C_command.DataToWrite.Buf = txBuf;
  I2C_command.DataToWrite.Length = 0;
  I2C_command.Callback=CallBackI2C;

  /* Display Welcome message */ 
 // LCD_GLASS_ScrollSentence((uint8_t*)"      CELESTIA ONLINE ",1,SCROLL_SPEED);

  Delay.Reset(&TimeDelay);
  Delay.Reset(&DbgDelay);
  MesureCurStop();
  char chI2cCounter=0;
  MesureCurUpward();
  chflagI2C=1;
  while(1){
	  i2cMgr.Task();
	  calipers.Task();
	  switch (chMainStep)
	  {
	  case MAIN_STEP_IDLE:
		  if (calipers.GetState()==SPI_END_RX)  //при выходе из холостго режима пропускаем первый отсчет со штангена, чтобы ток в датчике
		  {
			  chMainStep=MAIN_STEP_WAIT_CALIPERS_START;
			  DbgUART.SendPrintF("OUT IDLE  \n");
			  MesureCurUpward();					// включаем ток
			  chflagI2C=0;
		  }
		  break;
	  case MAIN_STEP_WAIT_CALIPERS_START:
		  if (calipers.GetState()==SPI_IDLE) // давно небыло посылок с штангена,
		  {
			  DbgUART.SendPrintF("IN IDLE  \n");
			  chMainStep=MAIN_STEP_IDLE;   // переходим в холостой режим
			  MesureCurStop();				//отключаем ток в датчике.
		  }
		  if (calipers.GetState()==SPI_START_RX)  // начало приема данных со штангена
		  {
			  //DbgUART.SendPrintF("IN I2C  \n");
			  chMainStep=MAIN_STEP_WAIT_I2C;
			  i2cMgr.AddCmd(I2C_command);
		  }
		  break;
	  case MAIN_STEP_WAIT_I2C:
		  if (chflagI2C==1) // закончилась работа с I2C
		  {
			    chMainStep=MAIN_STEP_WAIT_CALIPERS_END;
			    MesureCurToggle();				// переключаем направление тока
		  }
		  break;
	  case MAIN_STEP_WAIT_CALIPERS_END:
		  if (calipers.GetState()==SPI_END_RX) // закончилcz прием данных о штангена
		  {
			  	chByte[0]=rxBuf[1];
			  	chByte[1]=rxBuf[0];
			  	DbgUART.SendPrintF("ACD_VAL=%d  \n",*iCurentAdcValue);
			    LCD_GLASS_Clear();
			    tiny_sprintf(strDisp, " %d ", calipers.iSpiDataRx );
			    LCD_GLASS_DisplayString( (unsigned char *) strDisp );
			    DbgUART.SendPrintF("CALIPERS_VAL=%d  \n",calipers.iSpiDataRx);
			    DbgUART.SendPrintF("OUT I2CE  \n");
			  chMainStep=MAIN_STEP_WAIT_CALIPERS_START;
		  }
		  break;
	  } //switch

	 // if (Delay.Elapsed(&DbgDelay,100))  DbgUART.SendPrintF("i2c flag=%d  main_state=%d \n ",chflagI2C, chMainStep) ;
	/*  if (chflagI2C==1) // закончилась работа с I2C
	  {
		  MesureCurToggle();
		  chflagI2C=0;
	  }
	  if (Delay.Elapsed(&DbgDelay,250))
	  {
		  if (chI2cCounter<=10)
		  {
			  //MesureCurToggle();
			  chByte[0]=rxBuf[1];
		  	  chByte[1]=rxBuf[0];
			  DbgUART.SendPrintF("ACD_VAL=%d  \n",*iCurentAdcValue);
			  rxBuf[0]=0;
			  rxBuf[1]=0;
			  chI2cCounter++;
			  //chflagI2C=0;
			  i2cMgr.AddCmd(I2C_command);
		  }
	  }
*/

    if (flag_UserButton == TRUE)
    {
       clearUserButtonFlag();

       chI2cCounter=0;

    }
  }

}
Esempio n. 4
0
void dashboard_draw_func(handle_t obj)
{
    gui_widget_t *w = (gui_widget_t *) obj;

    gfx_set_color(COLOR_BLACK);
    gfx_fill_rectangle(w->left, w->top, w->width, w->height);

    if(gui_widget_get_state(w, STATE_FOCUSED))
        gfx_set_color(COLOR_YELLOW);
    else
        gfx_set_color(COLOR_DARK_YELLOW);

    gfx_draw_rectangle(w->left, w->top, w->width, w->height);

    gfx_set_color(COLOR_WHITE);
    gfx_set_font(&FONT_DIALOG_12);
    gfx_set_text_pos(w->left + 10, w->top + 10);
    gfx_outtext("Pressure:", 100);
    gfx_set_text_pos(w->left + 10, w->top + 90);
    gfx_outtext("Humidity:", 100);
    gfx_set_text_pos(w->left + 10, w->top + 170);
    gfx_outtext("Temperature:", 100);

    if(w->extra != NULL)
    {
        dashboard_data_t *data = (dashboard_data_t*) w->extra;
        char buf[16];
        int16_t trend;

        // Min & max

        gfx_set_text_pos(w->left + 10, w->top + 60);
        gfx_set_color(COLOR_CYAN);
        gfx_outtext("min: ", 10);
        if(data->pressure.min != 0x8000)
            tiny_sprintf(stringCache, "%d1 hPa", data->pressure.min);
        else
            tiny_sprintf(stringCache, "---");
        gfx_set_color(data->alarmMask & ALARM_MIN_P ? COLOR_RED : COLOR_WHITE);
        gfx_outtext_ram(stringCache, 25);
        gfx_set_color(COLOR_CYAN);
        gfx_outtext(", max: ", 10);
        if(data->pressure.max != 0x8000)
            tiny_sprintf(stringCache, "%d1 hPa", data->pressure.max);
        else
            tiny_sprintf(stringCache, "---");
        gfx_set_color(data->alarmMask & ALARM_MAX_P ? COLOR_RED : COLOR_WHITE);
        gfx_outtext_ram(stringCache, 25);
        
        gfx_set_text_pos(w->left + 10, w->top + 140);
        gfx_set_color(COLOR_MAGENTA);
        gfx_outtext("min: ", 10);
        if(data->humidity.min != 0x8000)
            tiny_sprintf(stringCache, "%d2 %%RH", data->humidity.min);
        else
            tiny_sprintf(stringCache, "---");
        gfx_set_color(data->alarmMask & ALARM_MIN_H ? COLOR_RED : COLOR_WHITE);
        gfx_outtext_ram(stringCache, 25);
        gfx_set_color(COLOR_MAGENTA);
        gfx_outtext(", max: ", 10);
        if(data->humidity.max != 0x8000)
            tiny_sprintf(stringCache, "%d2 %%RH", data->humidity.max);
        else
            tiny_sprintf(stringCache, "---");
        gfx_set_color(data->alarmMask & ALARM_MAX_H ? COLOR_RED : COLOR_WHITE);
        gfx_outtext_ram(stringCache, 25);
        
        gfx_set_text_pos(w->left + 10, w->top + 220);
        gfx_set_color(COLOR_YELLOW);
        gfx_outtext("min: ", 10);
        if(data->temperature.min != 0x8000)
            tiny_sprintf(stringCache, "%d2 *C", data->temperature.min);
        else
            tiny_sprintf(stringCache, "---");
        gfx_set_color(data->alarmMask & ALARM_MIN_T ? COLOR_RED : COLOR_WHITE);
        gfx_outtext_ram(stringCache, 25);
        gfx_set_color(COLOR_YELLOW);
        gfx_outtext(", max: ", 10);
        if(data->temperature.max != 0x8000)
            tiny_sprintf(stringCache, "%d2 *C", data->temperature.max);
        else
            tiny_sprintf(stringCache, "---");
        gfx_set_color(data->alarmMask & ALARM_MAX_T ? COLOR_RED : COLOR_WHITE);
        gfx_outtext_ram(stringCache, 25);

        // TREND

        trend = (data->pressure.trend - data->pressure.trendLast);
        if(trend < 2 && trend > -2)
            draw_minus(w->left + 170, w->top + 38);
        else
        {
            draw_arrow(w->left + 170, w->top + 23, (bool_t) (trend > 0));
            tiny_sprintf(buf, "%c%d1", trend > 0? '+' : ' ', trend);
            gfx_set_text_pos(w->left + 150, w->top + 43);
            gfx_outtext_ram(buf, 16);
        }

        trend = (data->humidity.trend - data->humidity .trendLast);
        if (trend < 5 && trend > -5)
            draw_minus(w->left + 170, w->top + 118);
        else
        {
            draw_arrow(w->left + 170, w->top + 103, (bool_t) (trend > 0));
            tiny_sprintf(buf, "%c%d2", trend > 0? '+' : ' ', trend);
            gfx_set_text_pos(w->left + 150, w->top + 123);
            gfx_outtext_ram(buf, 16);
        }

        trend = (data->temperature.trend - data->temperature.trendLast);
        if (trend < 2 && trend > -2)
            draw_minus(w->left + 170, w->top + 198);
        else
        {
            draw_arrow(w->left + 170, w->top + 183, (bool_t) (trend > 0));
            tiny_sprintf(buf, "%c%d2", trend > 0? '+' : ' ', trend);
            gfx_set_text_pos(w->left + 150, w->top + 203);
            gfx_outtext_ram(buf, 16);
        }

        // Big digits
        
        gfx_set_font(&FONT_ARIALBLACK_36);
        gfx_set_color(COLOR_WHITE);
    
        gfx_set_text_pos(w->left + 10, w->top + 18);
        tiny_sprintf(stringCache, "%d1", data->pressure.val);
        gfx_outtext_ram(stringCache, 10);

        gfx_set_text_pos(w->left + 10, w->top + 98);
        tiny_sprintf(stringCache, "%d2", data->humidity.val);
        gfx_outtext_ram(stringCache, 10);

        gfx_set_text_pos(w->left + 10, w->top + 178);
        tiny_sprintf(stringCache, "%d2", data->temperature.val);
        gfx_outtext_ram(stringCache, 10);
    }
}