/**
  * @brief  Execute the demo application.
  * @param  None
  * @retval None
  */
static void Demo_Exec(void)
{
  RCC_ClocksTypeDef RCC_Clocks;
  
  /* 串口配置 */
  USART1_Config();
  NVIC_Config();
  
  /* Initialize LEDs to be managed by GPIO */
  STM_EVAL_LEDInit(LED4);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED5);
  STM_EVAL_LEDInit(LED6);
  
  //每次系统初始化后,都读取flash查看存储空间剩余情况
  flash_readIndex(IndexList,uniIndexLength, &IndexCount);
  
  while(1)
  {
    DemoEnterCondition = 0x00;
    
    /* Reset UserButton_Pressed variable */
    UserButtonPressed = 0x00;
//    SerialButtonPressed = 0x00;
    
    /* SysTick end of count event each 2.5ms */
    RCC_GetClocksFreq(&RCC_Clocks);
    SysTick_Config(RCC_Clocks.HCLK_Frequency / TimeDev);
    
    

    /******************************************/
    /***空闲状态,清空flash或者发送数据选项****/
    /******************************************/
    /* Waiting User Button is pressed */
    while (UserButtonPressed == 0x00)
    {
      /********通过串口与上位机通信*******************/
      /* if Send serial data Button(PB11) is pressed */
      if(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11) == Bit_SET)//不太灵敏
      {
        while(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11) == Bit_SET);
        
        /*串口通信状态指示灯*/
        STM_EVAL_LEDOn(LED4);
        STM_EVAL_LEDOn(LED3);
        STM_EVAL_LEDOn(LED5);
        STM_EVAL_LEDOn(LED6);
        
        //读取flash中index区域
        flash_readIndex(IndexList,uniIndexLength, &IndexCount);
        
        
        //与上位机握手操作
        unsigned char* shakeHandSend = "ready? ";//最后一个字符必须是空格字符
        while (*shakeHandSend != ' ')
        {
          SendChar(*shakeHandSend);
          shakeHandSend++;
        }
        
        Delay(100);//等待1s确认接收自上位机的握手信号"ok!"
        if (serialRecv[0] == 'o'&&serialRecv[1] == 'k'&&serialRecv[2] == '!')
        {
          //与上位机握手成功,可发送数据
          serialFlag = 1;
        }
        else
        {
          //与上位机握手失败,无法发送数据
          serialFlag = 0;
          
          /*串口握手失败指示灯*/
          STM_EVAL_LEDOff(LED4);
          Delay(10);
          STM_EVAL_LEDOff(LED3);
          Delay(10);
          STM_EVAL_LEDOff(LED5);
          Delay(10);
          STM_EVAL_LEDOff(LED6);
          Delay(100);
        }
        
        
        if (1 == serialFlag)
        {
          //先发送IndexList数据给上位机,上位机选择需要的记录段(segment)反馈给下位机,下位机据此发送相应记录段给上位机
          uint8_t i;
          unsigned char sendData[4];
          
          SendString("index");
          SendCounter = 0;
          while(SendCounter < IndexCount)
          {
            uint32_to_uint8(sendData,IndexList[SendCounter]);
            i = 0;
            while(i < 4)
            {
              SendChar((unsigned char)sendData[i]);
              i+= 1 ;
            }
            SendCounter += 1;
          }
          
          
          /*开始发送segment数据给上位机*/
          
          while(serialRecv[0] == 'o');//等待确认接收自上位机的选择信号"0"——"6"
          Delay(2);//等待20ms后开始发送data,实现收发同步
          
          if (serialRecv[0] == '0'||serialRecv[0] == '1'||serialRecv[0] == '2'||serialRecv[0] == '3'||serialRecv[0] == '4'||serialRecv[0] == '5'||serialRecv[0] == '6')
          {
            tempCount = IndexList[(serialRecv[0]-48)*uniIndexLength+2];
            tempCount2 = 0;
            //读取flash user data area中对应数据
            while (tempCount > lowerComputerBufferNum)
            {
              
              flash_readData(SendData,lowerComputerBufferNum, tempCount2*lowerComputerBufferNum, IndexList[(serialRecv[0]-48)*uniIndexLength]);
              SendCounter = 0;
              while(SendCounter < lowerComputerBufferNum)
              {
                SendChar((unsigned char)SendData[SendCounter]);
                SendCounter += 1 ;
              }
              tempCount -= lowerComputerBufferNum;
              tempCount2 += 1;
              Delay(9);//延时9ms以便上位机有时间处理缓冲区(上位机缓冲区大小同下位机) 
            }
            
            if (tempCount != 0)
            {
               flash_readData(SendData,tempCount, tempCount2*lowerComputerBufferNum, IndexList[(serialRecv[0]-48)*uniIndexLength]);
               SendCounter = 0;
               while(SendCounter < tempCount)
               {
                  SendChar((unsigned char)SendData[SendCounter]);
                  SendCounter += 1 ;
               } 
            }
          }
          
          /*选择是否擦除对应segment和index*/
          //接收自上位机的删除信号 'Y' for 删除,'N' for 不删除
          if(serialRecv[1] == 'Y')
          {
             //uint32_t tempIndexList[uniIndexLength*7];
             flash_init_sector(IndexList[(serialRecv[0]-48)*uniIndexLength]);//擦除该index所对应flash user data area区域
             flash_init_sector(((uint32_t)0x08010000));//先擦除Index区域(sector 4)
             i = 0;
             uint8_t k = 0;
             while(i < IndexCount)
             {
               if (i != (serialRecv[0]-48)*uniIndexLength)
               {
                  IndexList[k] = IndexList[i];
                  IndexList[k+1] = IndexList[i+1];
                  IndexList[k+2] = IndexList[i+2];
                  k += uniIndexLength;
               }
               i += uniIndexLength;
             }
             flash_writeIndex(IndexList,IndexCount-uniIndexLength);//后重写该条index记录
             IndexCount -= 3;
          }
          
        }
      }
      
      /********************清空flash********************************/
      /* if Button(PB12) is pressed, flash user area will be erased*/
      if(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12) == Bit_SET)
      {
        /*waiting Button(PB12) being released*/
        while(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12) == Bit_SET);
        
        /* flash初始化 */
        flash_init();
        IndexCount = 0;
        /*灯全闪烁后全灭,指示flash中用户数据被擦除*/
         STM_EVAL_LEDToggle(LED4);
         STM_EVAL_LEDToggle(LED3);
         STM_EVAL_LEDToggle(LED5);
         STM_EVAL_LEDToggle(LED6);
         Delay(10);
         STM_EVAL_LEDOff(LED4);
         STM_EVAL_LEDOff(LED3);
         STM_EVAL_LEDOff(LED5);
         STM_EVAL_LEDOff(LED6);
         Delay(100);
      }
      
      /* Toggle LED4 */
      STM_EVAL_LEDToggle(LED6);
      Delay(50);
      //LED4 3 5用于二进制编码指示flash存储区占用个数
      if((IndexCount/uniIndexLength)&(0x01))//最低位
      { 
        STM_EVAL_LEDOn(LED5);
      }
      else
      {
         STM_EVAL_LEDOff(LED5);
      }
      if((IndexCount/uniIndexLength)&(0x02))
      { 
        STM_EVAL_LEDOn(LED3);
      }
      else
      {
         STM_EVAL_LEDOff(LED3);
      }
      if((IndexCount/uniIndexLength)&(0x04))//最高位
      { 
        STM_EVAL_LEDOn(LED4);
      }
      else
      {
         STM_EVAL_LEDOff(LED4);
      }
    }
    
    /* Waiting User Button is Released */
    while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET)
    {}
    
    
    
    /******************************************/
    /***退出空闲状态,采样状态配置初始化*******/
    /******************************************/
    STM_EVAL_LEDOn(LED4);
    STM_EVAL_LEDOff(LED4);
    Delay(10);
    STM_EVAL_LEDOn(LED3);
    STM_EVAL_LEDOff(LED3);
    Delay(10);
    STM_EVAL_LEDOn(LED5);
    STM_EVAL_LEDOff(LED5);
    Delay(10);
    STM_EVAL_LEDOn(LED6);
    STM_EVAL_LEDOff(LED6);
    Delay(10);
    
    
    
    
    /*各段记录相互独立的标志位均清零*/
    Counter = 0;//分组采用计数器复位
    DataWriteErrorFlag = 0;//flash写入错误标志位复位
    NoWrittenFlag = 0;//未写入标志位复位
    WritingSectorFlag = 0;//正在写入sector标志位复位
    totalDataNumber = 0;//各段记录数据个数计数器复位
    
    
    UserButtonPressed = 0x00;

    
    /* MEMS configuration */
    LIS302DL_InitStruct.Power_Mode = LIS302DL_LOWPOWERMODE_ACTIVE;
    LIS302DL_InitStruct.Output_DataRate = LIS302DL_DATARATE_400;//加速度传感器采用率400HZ
    LIS302DL_InitStruct.Axes_Enable = LIS302DL_XYZ_ENABLE;
    LIS302DL_InitStruct.Full_Scale = LIS302DL_FULLSCALE_2_3;//18 mg/digit
    LIS302DL_InitStruct.Self_Test = LIS302DL_SELFTEST_NORMAL;
    LIS302DL_Init(&LIS302DL_InitStruct);
    
    /* Required delay for the MEMS Accelerometre: Turn-on time = 3/Output data Rate 
    = 3/400 = 7.5ms */
    Delay(1);
    
    /* MEMS High Pass Filter configuration */
    LIS302DL_FilterStruct.HighPassFilter_Data_Selection = LIS302DL_FILTEREDDATASELECTION_OUTPUTREGISTER;
    LIS302DL_FilterStruct.HighPassFilter_CutOff_Frequency = LIS302DL_HIGHPASSFILTER_LEVEL_1;
    LIS302DL_FilterStruct.HighPassFilter_Interrupt = LIS302DL_HIGHPASSFILTERINTERRUPT_1_2;
    LIS302DL_FilterConfig(&LIS302DL_FilterStruct);
    
    LIS302DL_Read(Buffer, LIS302DL_OUT_X_ADDR, 6);
    X_Offset = Buffer[0];
    Y_Offset = Buffer[2];
    Z_Offset = Buffer[4];
  
    
    
    /******************************************/
    /***********开始进入采样模式,写入flash****/
    /******************************************/
    DemoEnterCondition = 0x01;
    /* Waiting User Button is pressed */
    while (UserButtonPressed == 0x00) //利用采样间隙写入缓冲器内数据,提高效率
    {
      if((0 == Counter)&&(1 == NoWrittenFlag)&&(0 == DataWriteErrorFlag))
      {
        if (WritingSectorFlag == 0)
        {
          writingDataAddr = getFreeDataStartAddr();
          if (writingDataAddr == 0)
          {
            NoFreeSectors = 1;//无空闲sector块置位
            NoWrittenFlag = 0;
            
            /* 指示灯全亮,指示存储空间已满 */
            STM_EVAL_LEDOn(LED4);
            STM_EVAL_LEDOn(LED3);
            STM_EVAL_LEDOn(LED5);
            STM_EVAL_LEDOn(LED6);
            break;//退出采样模式
          }
          else
          {
            //一次完整flash写入
            flash_init_sector(writingDataAddr);//保险起见,先擦除该空闲sector块
            DataWriteErrorFlag = flash_writeData(Total_Buffer, Total_Buffer_Number,writingDataAddr);
            NoWrittenFlag = 0;//表示已写入(flash)
            WritingSectorFlag = 1;//正在写入sector标志位置位,表示启用该块sector
          }
        }
        else
        {
          //flash写入
          DataWriteErrorFlag = flash_writeData(Total_Buffer, Total_Buffer_Number,writingDataAddr);
          NoWrittenFlag = 0;//表示已写入(flash)
        }
      }
      if(DataWriteErrorFlag != 0)
      {
        flash_init_sector(writingDataAddr);//flash写入错误后,擦除相应存储空间,退出采样状态
        WritingSectorFlag = 0;//归还对该块存储空间的使用权
        
        /* 指示灯全亮后全灭,指示进入采样状态 */
        STM_EVAL_LEDOn(LED4);
        STM_EVAL_LEDOn(LED3);
        STM_EVAL_LEDOn(LED5);
        STM_EVAL_LEDOn(LED6);
        Delay(100);
        STM_EVAL_LEDOff(LED4);
        STM_EVAL_LEDOff(LED3);
        STM_EVAL_LEDOff(LED5);
        STM_EVAL_LEDOff(LED6);
        Delay(100);
        break;
      }
      
      /* 指示灯全灭,指示进入采样状态 */
      STM_EVAL_LEDOff(LED4);
      STM_EVAL_LEDOff(LED4);
      STM_EVAL_LEDOff(LED3);
      STM_EVAL_LEDOff(LED5);
      STM_EVAL_LEDOff(LED6);
    }
    
    /* Waiting User Button is Released */
    while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET)
    {}
    
   
    
    /******************************************/
    /***********退出采样模式,做善后处理*******/
    /******************************************/
    DemoEnterCondition = 0x00;//防止此时进入采样模式
    
    /*如果退出采样模式时尚有数据未写入flash,在此一并写入flash*/
    if(1 == NoWrittenFlag)  flash_writeData(Total_Buffer, Counter,writingDataAddr);
    
    if ((0 == NoFreeSectors)&&(1 == WritingSectorFlag))
    {
      /* 指示灯全灭后全亮,指示进入数据善后状态 */
      STM_EVAL_LEDOff(LED4);
      STM_EVAL_LEDOff(LED3);
      STM_EVAL_LEDOff(LED5);
      STM_EVAL_LEDOff(LED6);
      Delay(10);
      STM_EVAL_LEDOn(LED4);
      STM_EVAL_LEDOn(LED3);
      STM_EVAL_LEDOn(LED5);
      STM_EVAL_LEDOn(LED6);
      Delay(10);
      
      /*至此,一条“完整”记录写入flash完毕,需要在flash中建立关于这条记录的索引index*/    
      flash_readIndex(IndexList,uniIndexLength, &IndexCount);//从flash中读取原IndexList
      IndexList[IndexCount] = writingDataAddr;//写入最新的数据地址块首地址
      srand((int)time(0));
      IndexList[IndexCount+1] = rand()%100;//写入最新的记录名
      IndexList[IndexCount+2] = totalDataNumber;//写入最新的段记录总个数
      flash_init_sector(((uint32_t)0x08010000));//先擦除Index区域(sector 4)
      flash_writeIndex(IndexList,IndexCount+3);//后写入
      IndexCount += 3;
    }
         
    /* Disable SPI1 used to drive the MEMS accelerometre */
    SPI_Cmd(LIS302DL_SPI, DISABLE);  
  }
}
Beispiel #2
0
void _ttywrch(int ch)
{
    SendChar (ch);
}
Beispiel #3
0
int fputc(int ch, FILE *stream)
{
  SendChar(ch);
  return ch;
}
Beispiel #4
0
int fputc(int ch, FILE *f)
{
  SendChar(ch);
  return ch;
}
Beispiel #5
0
/****************************************************************************
* 名    称: SendBeginCMD()
* 功    能: 发送帧头命令
* 入口参数: 无      
* 出口参数: 无
****************************************************************************/
void SendBeginCMD()
{
 SendChar(0xEE);
}
Beispiel #6
0
/****************************************************************************
* 名    称: SetTouchScreen_Adj()
* 功    能: 触摸屏校准,校准完毕后下发结束信息
* 入口参数: 无
* 出口参数: 无
****************************************************************************/
void SetTouchScreen_Adj()
{
  SendBeginCMD();
  SendChar(0x72);
  SendEndCmd();
}
void Uart_SendByte(int data)
{
	SendChar(data);
}
Beispiel #8
0
int main(void) {

    int accelData[3];
    int analogData[BUFFER];
    int i=0;
    for(i=0;i<BUFFER;i++){ analogData[i]=0;	}
    int a = 0;
    int analogIn = 0;
    int analogMin, analogMax;

    /* Initialize system */
    SystemInit();

    /* Initialize delay */
    //TM_DELAY_Init();

    /* Initialize PG13 (GREEN LED) and PG14 (RED LED) */
    TM_GPIO_Init(GPIOG, GPIO_PIN_13 | GPIO_PIN_14, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Fast);
    TM_GPIO_SetPinValue(GPIOG, GPIO_PIN_14, 1); // Red: ON

#ifdef ENABLE_USART
    /* Initialize USART1 at 115200 baud, TX: PA10, RX: PA9 */
    TM_USART_Init(USART1, TM_USART_PinsPack_1, 115200);
#endif

#ifdef ENABLE_VCP
    /* Initialize USB Virtual Comm Port */

    TM_USB_VCP_Result status = TM_USB_VCP_NOT_CONNECTED;
    while (TM_USB_VCP_GetStatus() != TM_USB_VCP_CONNECTED) {
    	TM_USB_VCP_Init();
    	TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_14);
    	Delay(500000);
    }
    SendString("USB VCP initialized and connected\n");
    TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_14 | GPIO_PIN_13); // Red: OFF, Gr: ON

#endif

#ifdef ENABLE_MMA

    /* Initialize MMA845X */
    uint8_t mma_status = MMA845X_Initialize(MMA_RANGE_4G);
    if (mma_status == MMA_OK) {
    	SendString("MMA initialized\n");
    } else {
    	SendString("MMA initialization failed, error code: ");
    	// Add 48 to the byte value to have character representation, (48 = '0')
    	SendChar('0'+mma_status);
    	SendChar('\n');
    }

#endif

    /* Initialize Display */
	TM_ILI9341_Init();
	TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_1);
	TM_ILI9341_SetLayer1();
	TM_ILI9341_Fill(ILI9341_COLOR_BLACK); /* Fill data on layer 1 */

	/* Initialize ADC1 */
	TM_ADC_Init(CURRENT_ADC, CURRENT_CH);

	/* Initialize PE2 and PE3 for digital output (Motor direction) */
    TM_GPIO_Init(GPIOE, GPIO_PIN_2 | GPIO_PIN_3, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Fast);
    // Set them to HIGH/LOW
    TM_GPIO_SetPinHigh(GPIOE, GPIO_PIN_3);
    TM_GPIO_SetPinLow(GPIOE, GPIO_PIN_2);

#ifdef ENABLE_PWM
    /* Set up PE5 (in front of PE4) for PWM (TIM9 CH1 PP2) (Motor speed control) */
    TM_PWM_TIM_t TIM9_Data;
    // Set PWM to 1kHz frequency on timer TIM4, 1 kHz = 1ms = 1000us
	TM_PWM_InitTimer(TIM9, &TIM9_Data, 1000);
	// Initialize PWM on TIM9, Channel 1 and PinsPack 2 = PE5
	TM_PWM_InitChannel(&TIM9_Data, TM_PWM_Channel_1, TM_PWM_PinsPack_2);
	// Set channel 1 value, 50% duty cycle
	TM_PWM_SetChannelPercent(&TIM9_Data, TM_PWM_Channel_1, 50);
#endif

	/* Initialize DAC channel 2, pin PA5 (Shaker control) */
	//TM_DAC_Init(TM_DAC2);
	/* Set 12bit analog value of 2047/4096 * 3.3V */
	//TM_DAC_SetValue(TM_DAC2, 4096);

#ifdef ENABLE_DAC
	// DAC PIN PA5
	/* Initialize DAC1, use TIM4 for signal generation */
	TM_DAC_SIGNAL_Init(TM_DAC2, TIM4);
	/* Output predefined triangle signal with frequency of 5kHz */
	TM_DAC_SIGNAL_SetSignal(TM_DAC2, TM_DAC_SIGNAL_Signal_Sinus, 50);
#endif

	/* MAIN LOOP */
    while (1) {

    	// Read acceleration data
#ifdef ENABLE_MMA
		MMA845X_ReadAcceleration(accelData);
#endif

		// Read analog input
		analogData[a] = TM_ADC_Read(CURRENT_ADC, CURRENT_CH);
		a++;
		if(a==BUFFER) {a=0;}

		// Analog average
		analogIn=0;
		analogMax=0;
		analogMin=4096;
		for(i=0;i<BUFFER;i++){
			if(analogData[i] > analogMax) { analogMax = analogData[i]; }
			if(analogData[i] < analogMin) { analogMin = analogData[i]; }
			analogIn+=analogData[i];
		}
		analogIn/=BUFFER;

		// Print graphs
		printGraphsLCD(accelData, analogData[a], analogIn, analogMin, analogMax);

		// Toggle Green led
		TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_13);

    }
}
Beispiel #9
0
int main()
{
	char tegn;
	char TestStreng[40] = "This string is stored in SRAM memory\r\n";

	// Initialize USART
	// Important : Also other Baud Rates and Data Bits should be tested
	// Corresponding changes has to be made in the terminal program used
	// for the test
	InitUART(9600, 8);

	while (1)
	{
		// Testing SendChar
		SendChar('A');
		SendChar('B');
		SendChar('C');
		SendChar('\r');
		SendChar('\n');

		// Testing ReadChar() : Read and echo
		tegn = ReadChar();
		SendChar(tegn);
		SendChar('\r');
		SendChar('\n');

		// Testing CharReady()
		while ( !CharReady() )
	{}
		SendChar( ReadChar() );
		SendChar('\r');
		SendChar('\n');
		
		// Sending string stored in Flash (constant string)
		SendString("This string is stored as a constant in flash memory\r\n");
		
		// Sending string stored in SRAM (modify-able string)
		SendString(TestStreng);
		
		// Testing SendInteger()
		SendInteger(12345);
		SendChar('\r');
		SendChar('\n');
		SendInteger(-1000);
		SendChar('\r');
		SendChar('\n');
	}
}
Beispiel #10
0
void dc18_change_state(void)
{
    uint16_t i;
    uint32_t t;

    gSTATE_CHANGE = TRUE;

    switch (badge_state)
    {
    case DEFCON:
        if (gSW == SW_1) badge_state = JOEGRAND;
        else if (gSW == SW_0)
        {
            // clear frame buffer and variables in preparation for the next state
            dc18_clear_fb();
            gLoc = 0;
            gIconIdx = 0;
            badge_state = BADGE;
        }
        else gSTATE_CHANGE = FALSE;
        break;
    case BADGE:
        if (gSW == SW_1)
        {
            ++gIconIdx; // point to next icon
            if (gIconIdx >= NUM_GLYPHS) gIconIdx = 0; // wrap-around
        }
        else if (gSW == SW_0)
        {
            if (gIconIdx == 0) gIconIdx = NUM_GLYPHS; // wrap-around backwards
            --gIconIdx; // point to next icon
        }
        else if (gSW == SW_BOTH)
        {
            if (gLoc < GLYPHS_PER_IMAGE - 1)
                ++gLoc; // move to next image location
            else
                badge_state = DEFCON; // if all glyphs have been entered, go to the next state
        }
        else gSTATE_CHANGE = FALSE;
        break;
    case JOEGRAND:
        if (gSW == SW_1) badge_state = BY;
        else if (gSW == SW_BOTH) badge_state = KINGPIN;
        else gSTATE_CHANGE = FALSE;
        break;
    case KINGPIN:
        if (gSW == SW_0) badge_state = JOEGRAND;
        else gSTATE_CHANGE = FALSE;
        break;
    case BY:
        if (gSW == SW_1) badge_state = NINJA;
        else if (gSW == SW_0) badge_state = AKA;
        else gSTATE_CHANGE = FALSE;
        break;
    case AKA:
        if (gSW == SW_0) badge_state = BY;
        else gSTATE_CHANGE = FALSE;
        break;
    case NINJA:
        if (gSW == SW_1) badge_state = DEFCON;
        else if (gSW == SW_0)
        {
            // clear frame buffer and variables in preparation for the next state
            dc18_clear_fb();
            gLoc = 0;
            gTumblerIdx = MIDDLE;
            badge_state = EIGHTEEN;
        }
        else if (gSW == SW_BOTH)
        {
            // display indication that we are transmitting/blocking
            // (indicator is cleared automatically when we return to main loop)
            for (i = 0; i < TX_ICON_WIDTH; ++i)
            {
                gFB[1 + i] = (uint8_t)dc18TX[i];
                gFB[129 + i] = (uint8_t)dc18TX[i + TX_ICON_WIDTH];
            }
            dc18_update_lcd();

            if (gNINJA_EN == 0)
                t = dc18_encode_tumblers(gTumblers); // encode tumbler states into 24-bit value
            else
                t = 0; // badge is still locked, so transmit three NULLs instead of valid code

            // transmit code via bit-banged serial port
            // for ~15 seconds (1200bps / 64 bits/message = 18.75 messages/s)
            for (i = 0; i < 227; ++i)
            {
                SendChar('N');
                SendChar('I');
                SendChar('N');
                SendChar('J');
                SendChar('A');
                SendChar((unsigned char)((t >> 16) & 0xFF)); // MSB first
                SendChar((unsigned char)((t >> 8) & 0xFF));
                SendChar((unsigned char)(t & 0xFF));
            }
        }
        else gSTATE_CHANGE = FALSE;
        break;
    case EIGHTEEN:
        if (gNINJA_EN == 0) // unlocked
        {
            if (gSW == SW_0) badge_state = NINJA;
            else gSTATE_CHANGE = FALSE;
        }
        else // locked
        {
            if (gSW == SW_1)
            {
                if (gTumblerIdx == MIDDLE) gTumblerIdx = TOP; // change tumbler position
                else if (gTumblerIdx == BOTTOM) gTumblerIdx = MIDDLE;
            }
            else if (gSW == SW_0)
            {
                if (gTumblerIdx == MIDDLE) gTumblerIdx = BOTTOM;
                else if (gTumblerIdx == TOP) gTumblerIdx = MIDDLE;
            }
            else if (gSW == SW_BOTH)
            {
                gTumblers[gLoc] = gTumblerIdx; // store current position

                if (gLoc < TUMBLERS_PER_IMAGE - 1)
                {
                    ++gLoc; 											 // move to next image location
                    gTumblerIdx = MIDDLE; 				 // set to default position
                }
                else
                {
                    // all tumblers have been set...
                    t = dc18_encode_tumblers(gTumblers); // encode tumbler states into 24-bit value
                    if (dc18_ninja_validate(t) == 1)  	 // check for validity
                        gNINJA_EN = 0; 										 // if valid, ninja mode unlocked!
                    else
                        gNINJA_EN = 0xFF;									 // else we stay locked. boo hoo.

                    badge_state = NINJA;
                }
            }
            else gSTATE_CHANGE = FALSE;
        }
        break;
    case USB:
        if (gSW == SW_1) badge_state = DEFCON;
        else gSTATE_CHANGE = FALSE;
        break;
    default:
        gSTATE_CHANGE = FALSE;
        break;
    }
Beispiel #11
0
void    R_FOG( void ) {
//===============

    int         width;
    int         dec;
    int         exp;
    int         logval;
    char        *buf;
    ftnfile     *fcb;
    char        ch;
    extended    value;
    extended    absvalue;

    width = IOCB->fmtptr->fmt3.fld1;
    dec = IOCB->fmtptr->fmt3.fld2;
    exp = IOCB->fmtptr->fmt3.fld3;
    fcb = IOCB->fileinfo;
    buf = &fcb->buffer[ fcb->col ];
    if( IOCB->typ <= PT_LOG_4 ) {
        R_FOLog();
    } else if( IOCB->typ <= PT_INT_4 ) {
        OutInt( width, 1 );
    } else {
        if( GetRealRtn( &value, width ) ) {
            absvalue = value;
            if( value < 0.0 ) {
                absvalue = -value;
            }
            /* round to "dec" digits */
            absvalue = absvalue + .5 * pow( 10, -dec );
            if( ( IOCB->typ == PT_REAL_4 ) || ( IOCB->typ == PT_CPLX_8 ) ) {
                logval = Div10S( absvalue );
            } else if((IOCB->typ == PT_REAL_8) || (IOCB->typ == PT_CPLX_16)) {
                logval = Div10L( absvalue );
            } else {
                logval = Div10X( absvalue );
            }
               //  use E format if less than 0.1 unless value is zero
               //  use E format if there are more digits than the width
            if( (( absvalue < 0.1 ) || ( logval >= dec )) &&
                 ( value != 0.0 ) ) {
                ch = 'E';
                if( exp == 0 ) { // if Gw.d
#if defined( _M_IX86 ) || defined( __AXP__ ) || defined( __PPC__ )
                    if( ( ( absvalue <= P1d_99 ) || ( absvalue >= P1d100 ) ) &&
                        ( absvalue != 0.0 ) ) {
                        ch = NULLCHAR;   // no exponent letter
                        exp = 3;
                    } else {
#endif
                        exp = 2;
#if defined( _M_IX86 ) || defined( __AXP__ ) || defined( __PPC__ )
                    }
#endif
                }
                R_F2E( value, buf, width, dec, (IOCB->flags & IOF_PLUS) != 0,
                       IOCB->scale, exp, ch );
                fcb->col += width;
            } else {
                if( exp == 0 ) { // if Gw.d
                    exp = 4;
                } else {
                    exp += 2;
                }
                width -= exp;
                if( width > 0 ) {
                    dec -= ( logval + 1 );
                    if( ( dec <= width ) && ( dec >= 0 ) ) {
                        R_F2F( value, buf, width, dec,
                               ( IOCB->flags & IOF_PLUS ) != 0, 0 );
                        fcb->col += width;
                        if( *buf == '*' ) {
                            // fill remaining field
                            SendChar( '*', exp );
                        } else {
                            SendChar( ' ', exp );
                        }
                    } else {
                        SendChar( '*', width + exp );
                    }
                } else {
                    SendChar( '*', width + exp );
                }
            }
        } else { // undefined chars will be filled in for value
            fcb->col += width;
        }
    }
}
Beispiel #12
0
static void FOHex( uint width ) {
//===============================

    uint        len;
    int         trunc;
    ftnfile     *fcb;
    PTYPE       typ;
    char        *buff;

    fcb = IOCB->fileinfo;
    typ = IOCB->typ;
    len = GetLen();
    trunc = 0;

//  Use this method when real and imaginary parts are formatted using
//  one edit descriptor:
/*
    if( ( IOCB->typ == PT_CPLX_8 ) || ( IOCB->typ == PT_CPLX_16 ) ) {
        len *= 2;
        IOCB->flags &= ~IOF_FMTREALPART;  // we'll print both parts at once
    }
*/
//  Use this method when real and imaginary parts each require an
//  edit descriptor:

    if( IOCB->typ == PT_CPLX_8 ) {
        if( !(IOCB->flags & IOF_FMTREALPART) ) {
            IORslt.scomplex.realpart = IORslt.scomplex.imagpart;
        }
    } else if( IOCB->typ == PT_CPLX_16 ) {
        if( !(IOCB->flags & IOF_FMTREALPART) ) {
            IORslt.dcomplex.realpart = IORslt.dcomplex.imagpart;
        }
    } else if( IOCB->typ == PT_CPLX_32 ) {
        if( !(IOCB->flags & IOF_FMTREALPART) ) {
            IORslt.xcomplex.realpart = IORslt.xcomplex.imagpart;
        }
    }
    if( width == 0 ) {
        width = 2*len;
    }

    trunc = ( len * 2 ) - width;
    if( trunc < 0 ) {
        SendChar( ' ', -trunc );
    }
    if( trunc <= 0 ) {
        trunc = 0;
    }

    if( typ != PT_CHAR ) {
        len *= 2;
        HexFlip( (char *)&IORslt, len );
        BToHS( (char *)&IORslt , len, IOCB->buffer );
        strupr( IOCB->buffer );
        SendStr( IOCB->buffer + trunc, len - trunc );
    } else {
        buff = IOCB->buffer;
        len *= 2;
        if( len > IO_FIELD_BUFF ) {
            buff = RChkAlloc( len + 1 );
        }
        pgm_BToHS( IORslt.string.strptr, len, buff );
        strupr( buff );
        SendStr( buff + trunc, len - trunc );
        if( len > IO_FIELD_BUFF ) {
            RMemFree( buff );
        }
    }
}
Beispiel #13
0
int main(void)
{
    // Prepare for UART communication with external world. The default baud rate
    // is 921,600 bps
    IOWR_FIFOED_AVALON_UART_DIVISOR(UART_BASE, BAUD_RATE(921600.0f));

    // Make sure UART interrupts are disabled
    alt_ic_irq_disable(UART_IRQ_INTERRUPT_CONTROLLER_ID, UART_IRQ);

    // Clear the input and output buffers
    FlushRx(UART_BASE);
    FlushTx(UART_BASE);
    
    #define MAX_CMD_LEN 64
    char cmd[MAX_CMD_LEN];
    s8 cmdIndex = 0;

    // Sit in an infinite loop waiting for serial commands
    while(1)
    {
        while (IORD_FIFOED_AVALON_UART_STATUS(UART_BASE) & FIFOED_AVALON_UART_CONTROL_RRDY_MSK)
        {
            // Read the Uart
            char rx = IORD_FIFOED_AVALON_UART_RXDATA(UART_BASE);
            
            // If this is the end of a command, then try to parse it
            if (('\r' == rx) || ('\n' == rx))
            {
                cmd[cmdIndex] = '\0';
                ExecuteCmd(cmd, UART_BASE);
                FlushRx(UART_BASE);
                FlushTx(UART_BASE);
                cmdIndex = 0;
            }
            
            // If this is a backspace
            else if ('\b' == rx)
            {
                SendStr("\b \b", UART_BASE);
                if (cmdIndex > 0)
                    cmdIndex--;
            }
            
            // This is any other character
            else
            {
                // echo the character
                SendChar(rx, UART_BASE);
                
                // Add it to the buffer, if possible, making sure to save the 
                // space for the null terminator (when completing the command)
                if (cmdIndex < (MAX_CMD_LEN - 1))
                    cmd[cmdIndex++] = rx;
                
                // Otherwise, report the error and reset the buffer
                else
                {
                    cmdIndex = 0;
                    SendStr(NO_ANSWER, UART_BASE);
                }
            }
        }
    }
}
Beispiel #14
0
/* ---------------------------------------------------------------------------
-- Routine to send a command string (including potentially nulls) to printer
--
-- Usage:  void SendCommand(char *str)
--
-- Inputs: str - command string
---------------------------------------------------------------------------- */
void SendCommand(char *str) {
	while (*str) SendChar(*(str++));
	return;
}
Beispiel #15
0
void appcall(void)
{
	u16 i;

  switch(uip_conn->lport) 
  {
  /* http port */
  	case HTONS(80):
		/* when syn_rcv the uip_connected() return not zero ,it means 
		   client connect to host*/
		if(uip_connected()) { 
		 	/* init the byte count */
			hs.count = 0;					
			return;
		}
		else if(uip_poll()) {	 
		/* If we are polled ten times, we abort the connection. This is
		   because we don't want connections lingering indefinately in
		   the system.  */
			if(hs.count++ >= 10) {
				uip_abort();
			}
			return;
		}
		else if(uip_newdata())
		{	if(uip_appdata[0]!='G' || uip_appdata[1]!='E' || uip_appdata[2]!='T' || uip_appdata[3]!=' ')
				uip_abort();
			/* control the led on and off */
			/* 0123456789abcdef */
			/* GET /swc.html?sw7=1 */
			if(uip_appdata[4]=='/' && uip_appdata[5]=='s' && uip_appdata[6]=='w' && uip_appdata[7]=='c')
			{	if(uip_appdata[16]=='7')
				{	if(uip_appdata[18]=='1') 
					{	P1_7=0;
						htmlpage[0x146]='0';
					}
					else
					{	P1_7=1;
						htmlpage[0x146]='1';
						
					}
				}
				if(uip_appdata[16]=='6')
				{	if(uip_appdata[18]=='1') 
					{	P1_6=0;
						htmlpage[0x17d]='0';
					}
					else
					{	P1_6=1;
						htmlpage[0x17d]='1';
						
					}
				}
			}

			{
				xdata u8 val[16];
				sprintf(val,"%04.2f",get_adc_val()*5.0/1024);
				memcpy(&htmlpage[0x1ae],val,5);
			}
//			tt = 0;
//			htmlpage[0x1ae]=(unsigned char)(tt>>8)/10+'0';	 //整数
//			htmlpage[0x1af]=(unsigned char)(tt>>8)%10+'0';
//
//			htmlpage[0x1af+2]=(tt & 0x00ff)/10+'0';			//小数
//			htmlpage[0x1af+3]=(tt & 0x00ff)%10+'0';
			

			hs.dataptr=htmlpage;
			hs.count=sizeof(htmlpage)-1;
		}


		//若收到client的ack包,说明先前的数据已成功发送,进行剩下的数据处理,若没数据要发,就关闭连接		  
		if(uip_acked()) {//若没发送完,长度和开始指针还是存在hs->count 和hs->dataptr中		
			if(hs.count >= uip_conn->len) {	 /* uip_conn.len contain the bytes sent just now */
				hs.count -= uip_conn->len;
				hs.dataptr += uip_conn->len;
			}
			else {
				hs.count = 0;
			}
		
			if(hs.count == 0) {		   			
				uip_close();	 /* 数据发送完成,关闭连接 */
			}
		}
		/* 在没有重发数据且在ESTABLISHED状态时,才会出现uip_flags = UIP_POLL; */
		if(!uip_poll()) {
		/* Send a piece of data, but not more than the MSS of the	connection.	*/
			uip_send(hs.dataptr, hs.count);
		}

		return;
			
	case HTONS(8079):		//*串口参数配置	
		if (uip_newdata())	//*UIP_CONNECTED UIP_NEWDATA UIP_ACKDATA
		{	if(uip_appdata[0]=='s' && uip_appdata[1]=='e' && uip_appdata[2]=='t')
			if(uip_appdata[3]=='c' && uip_appdata[4]=='o' && uip_appdata[5]=='m')
			{			
			//	u8 *str[]={"24","48","96","192","288","384","576","1152"};
				u8 code tab[] = {112,184,220,238,244,247,250,253};
				xputs("set ok, please change buard rate\r\n");
				Delay_x(500);

				i = uip_appdata[6] - '0';
				if(i >= 0 && i <=7)
				{
					TH1 = tab[i];
					TL1=TH1;
				}


//				switch(uip_appdata[6])
//				{	case '0':  //2400bps
//						TH1 = 112;
//						//RCAP2H=0xf7;
//						//RCAP2L=0x00;
//						//puts("300bps\r\n");
//						break;
//					case '1':
//						TH1 = 184;	//4800bps
//						//RCAP2H=0xfb;
//						//RCAP2L=0x80;
//						//puts("600bps\r\n");
//						break;
//					case '2':
//						TH1 = 220; //9600bps
//						//RCAP2H=0xfd;
//						//RCAP2L=0xc0;
//						//puts("1200bps\r\n");
//						break;
//					case '3':
//						TH1 = 
//						//RCAP2H=0xfe;
//						//RCAP2L=0xe0;
//						//puts("2400bps\r\n");
//						break;
//					case '4':
//						//RCAP2H=0xff;
//						//RCAP2L=0x70;
//						//puts("4800bps\r\n");
//						break;
//					case '5':
//						//RCAP2H=0xff;
//						//RCAP2L=0xb8;
//						//puts("9600bps\r\n");
//						break;
//					case '6':
//						//RCAP2H=0xff;
//						//RCAP2L=0xdc;
//						//puts("19200bps\r\n");
//						break;
//					case '7':
//						//RCAP2H=0xff;
//						//RCAP2L=0xee;
//						//puts("38400bps\r\n");
//						break;
//					case '8':
//						//RCAP2H=0xff;
//						//RCAP2L=0xf4;
//						//puts("57600bps\r\n");
//						break;
//					case '9':
//						//RCAP2H=0xff;
//						//RCAP2L=0xfa;
//						//puts("115200bps\r\n");
//						break;
//					default:
//						//RCAP2H=0xff;
//						//RCAP2L=0xb8;
//						//puts("9600bps\r\n");
//						break;
//				}					
			}
		}		
	return;	   
	/*---------------------------------------------------------------------------------*/
	//用于数据传送的端口	
	case HTONS(8080):
		if (uip_newdata())	//UIP_CONNECTED UIP_NEWDATA UIP_ACKDATA
		{
			if(uip_len)
			{
				for(i=0; i<uip_len; i++ )
				{
					SendChar(uip_appdata[i]);
//					if(-1 != SendChar(uip_appdata[i]))
//						i++;
				}
			}	
		}
		if(uip_poll())
		{
			u16 dt_len = SIO_RBUFLEN;
			
			if(dt_len > 0)
			{
				for(i=0; i<dt_len; i++)
				{
					tx_buf[i] = GetKey();
				}	
				uip_slen = dt_len;
				uip_send(tx_buf,uip_slen);
			}
		}					
	return;	  
/*---------------------------------------------------------------------------------*/
//采用client时,这部分需要取消
//	default:
//    uip_abort();
//    break;
  }
  
  if(uip_conn->rport == HTONS(8888))
  {
	if(uip_connected())
	{
		code char hello[] = "Hello world\r\n"; 
		xlog("建立连接\r\n");
		uip_slen = strlen(hello);
		uip_send(hello,uip_slen);
		client_connect_flag = 1;
	}
	else if(uip_newdata())
	{
		uip_send(uip_appdata,uip_len);	//照原样输出	
	}
	else if(uip_aborted())
	{
		client_connect_flag = 0;
		xlog("rst ");
	}
	else if(uip_closed())
	{
		client_connect_flag = 0;
		xlog("disc ");	
	}
  }  
}
void main(void)
{
 Init(); 
 while(1)
 {
     P2 = Tab[i];
    Key = P2;
    if ((K1 & K2 & K3) == 0)
      {
      if (flag == 0)
        {
         // Obsluga przycisków dla LCD i 7segCC
         P1 = Key;
         if (Key == 0xE7) {SendChar('1');}  // 
         if (Key == 0xEB) {SendChar('2');}  // 
         if (Key == 0xED) {SendChar('3');} // 
         if (Key == 0xD7) {SendChar('4');} // 
         if (Key == 0xDB) {SendChar('5');} // 
         if (Key == 0xDD) {SendChar('6');} //  kody do wyslania 
         if (Key == 0xB7) {SendChar('7');} // 
         if (Key == 0xBB) {SendChar('8');} // 
         if (Key == 0xBD) {SendChar('9');} // 
         if (Key == 0x7B) {SendChar('0');} // 
         if (Key == 0x77) {SendChar('*');} // 
         if (Key == 0x7D) {SendChar('#');} // 
         flag2=!flag2;

        flag = 1;
       }  
     }
    else
      {
        if (i == 3) {i = 0;} else {i++;}
      flag = 0;
     }
 }
}
// sends a carriage return, to look nice on the display when using strings
void SendCR(void)
{
	SendChar(0x0d);
}
Beispiel #18
0
/****************************************************************************
* 名    称: GUI_CleanScreen()
* 功    能: 清屏
* 入口参数: 无  
* 出口参数: 无
****************************************************************************/
void GUI_CleanScreen()
{
  SendBeginCMD();
  SendChar(0x01);
  SendEndCmd();
}
Beispiel #19
0
/* finds dictionary matches for characters in current sector */
void DictSearch(unsigned int dictpos, unsigned int bytestodo)
{

	register unsigned int i, j;

#if (GREEDY == 0)

	unsigned int matchlen1, matchpos1;

	/* non-greedy search loop (slow) */

	i = dictpos; j = bytestodo;

	while (j) /* loop while there are still characters left to be compressed */
	{
		FindMatch(i, THRESHOLD);

		if (matchlength > THRESHOLD)
		{
			matchlen1 = matchlength;
			matchpos1 = matchpos;

			for ( ; ; )
			{
				FindMatch(i + 1, matchlen1);

				if (matchlength > matchlen1)
				{
					matchlen1 = matchlength;
					matchpos1 = matchpos;
					SendChar(dict[i++]);
					j--;
				}
				else
				{
					if (matchlen1 > j)
					{
						matchlen1 = j;
						if (matchlen1 <= THRESHOLD) { SendChar(dict[i++]); j--; break; }
					}

					SendMatch(matchlen1, (i - matchpos1) & (DICTSIZE - 1));
					i += matchlen1;
					j -= matchlen1;
					break;
				}
			}
		}
		else
		{
			SendChar(dict[i++]);
			j--;
		}
	}

#else

	/* greedy search loop (fast) */

	i = dictpos; j = bytestodo;

	while (j) /* loop while there are still characters left to be compressed */
	{
		FindMatch(i, THRESHOLD);

		if (matchlength > j) matchlength = j;     /* clamp matchlength */

		if (matchlength > THRESHOLD)  /* valid match? */
		{
			SendMatch(matchlength, (i - matchpos) & (DICTSIZE - 1));
			i += matchlength;
			j -= matchlength;
		}
		else
		{
			SendChar(dict[i++]);
			j--;
		}
	}

#endif

}
Beispiel #20
0
/****************************************************************************
* 名    称: SetHandShake()
* 功    能: 握手
* 入口参数: 无      
* 出口参数: 无
****************************************************************************/
void SetHandShake(void)
{
  SendBeginCMD();
  SendChar(0x00);
  SendEndCmd();
}
Beispiel #21
0
/* Terminal writig */
void terminal( char * string){

	int retPls = 0;
	char string_save[200];
	int n;
	float m,o;

	if(strcmp (string,"help")==0){
		SendStr(" \n\r");
		SendStr("                                                                               \r");
		SendStr("\r\n ***********************************************************************************");
		SendStr("\r\n **                                 help menu                                     **");
		SendStr("\r\n ***********************************************************************************");
		SendStr("\r\n                                                                                    ");
		SendStr(" \r auto        start automatic mode and stop manual mode   \r\n");
		SendStr(" \r manual      start manual mode and stop automatic mode   \r\n");
		SendStr(" \r speed	     update speed value (only in manual mode)    \r\n");
		SendStr(" \r steering    update steering value (only in manual mode) \r\n");
		SendStr(" \r camera      update position and voltage analog values for propulsion module \r\n");
		SendStr(" \r meas        print currents and voltage analog values for propulsion module \r\n");
		SendStr(" \r help        print supported commands                                             \r\n");
		SendStr("\r control:# ");
	}
	else if(strcmp (string,"auto")==0){
		SendStr("\n\r automatic mode is running\n\r");
		i2c_cgroup_function(1);
		SendStr("\r control:# ");
	}
  else if(strcmp (string,"manual")==0){
		SendStr("\n\r manual mode is running\n\r");
		SendStr("\r control:# ");
	}
	else if(strcmp (string,"speed")==0){
		SendStr("\n\r enter a value between 0 (stop) and 254 (full speed), 255 (reverse, speed is fixed): \n\r");
	  char value[4];
		int i;
		GetStr(value);
		if(value[0]=='-')
			SendStr("\n\r error : failed value (0 to 255) ");
		if ( value[0] == '2'){
			if ( value[1] == '5'){
				if (value[2] == '5'){
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}
					retPls = atoi(value);
					PWM_CH2_Pulse(retPls);
					PWM_CH1_Pulse(0);
				}
			}
		}
		else if(value[3]=='\0'){
			if(value[2]!='\0'){
				if(value[0] =='2'){
					if(value[1]<='5'){
						if(value[2]<='5'){
							for(i=0;i<=3;i++){
								SendChar(value[i]);
							}
							retPls = atoi(value);
							PWM_CH1_Pulse(retPls);
							PWM_CH2_Pulse(0);
						}
						else
							SendStr("\n\r error : failed value (0 to 255) ");
					}
					else
						SendStr("\n\r error : failed value (0 to 255) ");
				}
				else if (value[0]<='2'){
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}
					retPls = atoi(value);
					PWM_CH1_Pulse(retPls);
					PWM_CH2_Pulse(0);
				}
				else
					SendStr("\n\r error : failed value (0 to 255)");
			}
			else
				for(i=0;i<=3;i++){
					SendChar(value[i]);
				}
				retPls = atoi(value);
				PWM_CH1_Pulse(retPls);
				PWM_CH2_Pulse(0);
		}
		else
			SendStr("\n\r error : failed value (0 to 255) ");
			SendStr("\n\r control:# ");
	}
	else if(strcmp (string,"steering")==0){
		SendStr("\n\r enter value between -127 (full left) and 128 (full right), 0 is the middle position : \n\r");
	  char value[5];
		int i;
		GetStr(value);
		if(value[0]=='-'){
			if(value[1]=='0')
				SendChar(value[1]);
			else if (value[3]=='\0' || value[2]=='\0'){
				for(i=0;i<=3;i++){
					SendChar(value[i]);
				}
				retPls = atoi(value);
				PWM_CH3_Pulse(retPls);
				HAL_Delay(500);
				PWM_CH3_Pulse(65499);
				HAL_Delay(500);
			}
			else if(value[4]=='\0'){
				if(value[3]!='\0'){
					if(value[1] =='1'){
						if(value[2]<='2'){
							if(value[3]<='7'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}
								retPls = atoi(value);
								PWM_CH3_Pulse(retPls);
								HAL_Delay(500);
								PWM_CH3_Pulse(65499);
								HAL_Delay(500);
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");
				}
				else
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}
					retPls = atoi(value);
					PWM_CH3_Pulse(retPls);
					HAL_Delay(500);
					PWM_CH3_Pulse(65499);
					HAL_Delay(500);
			}
			else {
				SendStr("\n\r error : failed value (-127 to 128) ");
			}
		}
		else{
			if(value[3]=='\0'){
				if(value[2]!='\0'){
					if(value[0] =='1'){
						if(value[1]<='2'){
							if(value[2]<='8'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}
								retPls = atoi(value);
								PWM_CH3_Pulse(retPls);
								HAL_Delay(500);
								PWM_CH3_Pulse(65499);
								HAL_Delay(500);
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");
				}
				else
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}
					retPls = atoi(value);
					PWM_CH3_Pulse(retPls);
					HAL_Delay(500);
					PWM_CH3_Pulse(65499);
					HAL_Delay(500);
			}
			else{
				SendStr("\n\r error : failed value (-127 to 128) ");
			}
		}
		SendStr("\n\r control:# ");
	}
	else if(strcmp (string,"camera")==0){
		SendStr("\n\r enter value between -127 (full left) and 128 (full right), 0 is the middle position : \n\r");
	  char value[5];
		int i;
		GetStr(value);
		if(value[0]=='-'){
			if(value[1]=='0'){
				SendChar(value[1]);
				retPls = atoi(value);
				PWM_CH4_Pulse(retPls);
				HAL_Delay(5000);
			}
			else if (value[3]=='\0' || value[2]=='\0'){
				for(i=0;i<=3;i++){
					SendChar(value[i]);
				}
				retPls = atoi(value);
				PWM_CH4_Pulse(retPls);
				HAL_Delay(5000);
			}
			else if(value[4]=='\0'){
				if(value[3]!='\0'){
					if(value[1] =='1'){
						if(value[2]<='2'){
							if(value[3]<='7'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}
								retPls = atoi(value);
								PWM_CH4_Pulse(retPls);
								HAL_Delay(5000);
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");
				}
				else{
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}
					retPls = atoi(value);
					PWM_CH4_Pulse(retPls);
					HAL_Delay(5000);
				}
			}
			else
				SendStr("\n\r error : failed value (-127 to 128) ");
		}
		else{
			if(value[3]=='\0'){
				if(value[2]!='\0'){
					if(value[0] =='1'){
						if(value[1]<='2'){
							if(value[2]<='8'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}
								retPls = atoi(value);
								PWM_CH4_Pulse(retPls);
								HAL_Delay(5000);
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");
				}
				else{
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}
					retPls = atoi(value);
					PWM_CH4_Pulse(retPls);
					HAL_Delay(5000);
				}
			}
			else
				SendStr("\n\r error : failed value (-127 to 128) ");
		}
		SendStr("\n\r control:# ");
	}
	else if(strcmp (string,"meas")==0){
		SendStr("\n\r currents and voltage analog values for propulsion module : \n\r");
		n=adc1();
		m=n*3.3/255;
		o=m*100/24;
		sprintf(string_save," ADC value: adc1=%d, V=%f, I=%f \r\n control :# ", n,m,o);
		SendStr(string_save);
		SendStr("\n\r control:# ");
	}
	else{
		SendStr("\n\r ERROR : command not supported. Enter help to know the supported command   \n\r");
		SendStr("\r control:# ");
	}
}
Beispiel #22
0
/****************************************************************************
* 名    称: TestTouchScreen()
* 功    能: 触摸屏体验
* 入口参数: 无
* 出口参数: 无
****************************************************************************/
void TestTouchScreen()
{
  SendBeginCMD();
  SendChar(0x73);
  SendEndCmd();
}
VOID CALLBACK TimeCheck( HWND hwnd, UINT uMsg,UINT_PTR idEvent,DWORD dwTime) // every 100 ms
{
	char c;
	static bool init = false;
	static int inputCount = 0;
	if (!init)
	{
		init = true;
	//	char word[MAX_WORD_SIZE];
	//	GetCurrentDir(word, MAX_WORD_SIZE);
		InitChatbot(computerName);
		RECT rect;
		GetClientRect(hwnd, &rect);
		InvalidateRect(hwnd, &rect, TRUE);
		strcpy(response,"Chatbot initialization complete");
	}

	static int counter = 0;
	++counter; // increament each timer interrupt, tracking how long since last key input from user
	static char lastchar = 0;
	static bool keyhit = false;
	while ((c = ReadChar())) // returns 0 if nothing found
	{
		keyhit = true; // user input seen since last output
		RECT rect;
		GetClientRect(hwnd, &rect);
		InvalidateRect(hwnd, &rect, TRUE);
		if ( c == 8) // backspace
		{
			if ( msgPtr != inputMessage) *--msgPtr = 0;
		}
		else if ( c == '\n' || c == '\r') // prepare for NEW input and get response
		{
			if (msgPtr == inputMessage) continue;	// ignore empty lines
			*msgPtr = 0;
			counter = 100;	// treat as end of input
			break;	// dont read until we have responded
		}
		else if (msgPtr == inputMessage && (c == ' ' || c == '\t' )) continue;	// ignore leading whitespace.
		else // accept new character
		{
			*msgPtr++ = c;
			lastchar = c;
			*msgPtr = 0;
		}
		counter = 0; // start time wait over again
	}

	// do we have something we want to respond to?
	bool trigger = false;
	if (counter >= 30 && *inputMessage && (lastchar == '.' || lastchar == '?' || lastchar == '!')) trigger = true; // 3 sec passed and have input ended on closer 
	else if (counter >= 70 && *inputMessage) trigger = true; // 7 seconds + have lingering input
	// or timer oob goes off
	char oob[MAX_WORD_SIZE];
	*oob = 0;
	ProcessInputDelays(oob,keyhit); 

	if (trigger || *oob)
	{
		if (*oob) strcpy(ourMainInputBuffer,oob); // priority is to alarm callback. others will be only if no user input anyway
		else  
		{
			strcpy(ourMainInputBuffer,inputMessage);
			// clear all signs of user input
			lastchar = 0;	
			*inputMessage = 0;
			msgPtr = inputMessage;
			keyhit = false;
		}

		PerformChat(loginID,computerID,ourMainInputBuffer,NULL,ourMainOutputBuffer);
		strcpy(response,ourMainOutputBuffer);
		callBackDelay = 0; // now turned off after an output
		ProcessOOB(ourMainOutputBuffer); // process relevant out of band messaging and remove

		char word[MAX_WORD_SIZE];
		char* p = SkipWhitespace(ourMainOutputBuffer);
		ReadCompiledWord(p,word);
		if (!*word) strcpy(p,"huh?"); // in case we fail to generate output

		// transmit message to user
		++inputCount;
		while (*p) 
		{
			if (SendChar(*p,p[1],inputCount)) p++; // got sent
		}
		SendChar('\n',0,inputCount);
		if (loopBackDelay) loopBackTime = ElapsedMilliseconds() + loopBackDelay; // resets every output

		// write out last sequence id
		FILE* out = fopen("sequence", "wb");
		fprintf(out,"%d",sequence);
		fclose(out);

		counter = 0;
		RECT rect;
		GetClientRect(hwnd, &rect);
		InvalidateRect(hwnd, &rect, TRUE);
	}
}
Beispiel #24
0
/*---------------------------------------------------------------------------------------------------------*/
void _ttywrch(int ch)
{
  SendChar(ch);
  return;
}
Beispiel #25
0
int fputc(int ch, FILE *f)
{
    return (SendChar(ch));
}
static void SendString(const unsigned char *str,  UART_Desc *desc) {
    while(*str!='\0') {
        SendChar(*str++, desc);
    }
}
Beispiel #27
0
void terminal( char * string){
  	if(strcmp (string,"help")==0){
		SendStr(" \n\r");
		SendStr("                                                                               \r");
		SendStr("\r\n ***********************************************************************************");
		SendStr("\r\n **                                 help menu                                     **");
		SendStr("\r\n ***********************************************************************************");
		SendStr("\r\n                                                                                    ");
		SendStr(" \r auto        start automatic mode and stop manual mode   \r\n");
		SendStr(" \r manual      start manual mode and stop automatic mode   \r\n");
		SendStr(" \r speed	     update speed value (only in manual mode)    \r\n");
		SendStr(" \r steering    update steering value (only in manual mode) \r\n");
		SendStr(" \r camera      update position and voltage analog values for propulsion module \r\n");
		SendStr(" \r meas        print currents and voltage analog values for propulsion module \r\n");
		SendStr(" \r help        print supported commands                                             \r\n");
		SendStr("\r control:# ");
	}
	else if(strcmp (string,"auto")==0){
		SendStr("\n\r automatic mode is running\n\r");
		SendStr("\r control:# ");
	}
  else if(strcmp (string,"manual")==0){
		SendStr("\n\r manual mode is running\n\r");
		SendStr("\r control:# ");
	}
	else if(strcmp (string,"speed")==0){
		SendStr("\n\r enter a value between 0 (stop) and 255 (full speed): \n\r"); 	
	  char value[4];
		int i;
		GetStr(value);
		if(value[0]=='-')
			SendStr("\n\r error : failed value (0 to 255) ");
		else if(value[3]=='\0'){ 
			if(value[2]!='\0'){
				if(value[0] =='2'){
					if(value[1]<='5'){
						if(value[2]<='5'){
							for(i=0;i<=3;i++){
								SendChar(value[i]);
							}								
						}
						else
							SendStr("\n\r error : failed value (0 to 255) ");
					}
					else
						SendStr("\n\r error : failed value (0 to 255) ");
				}
				else if (value[0]<='2'){
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}								
				}
				else
					SendStr("\n\r error : failed value (0 to 255)");	
			}
			else
				for(i=0;i<=3;i++){
					SendChar(value[i]);
				}				
		}
		else 
			SendStr("\n\r error : failed value (0 to 255) ");
			SendStr("\n\r control:# ");	
	}
	else if(strcmp (string,"steering")==0){
		SendStr("\n\r enter value between -127 (full left) and 128 (full right), 0 is the middle position : \n\r");
	  char value[5];
		int i;
		GetStr(value);
		if(value[0]=='-'){
			if(value[1]=='0')
				SendChar(value[1]);
			else if (value[3]=='\0' || value[2]=='\0'){
				for(i=0;i<=3;i++){
					SendChar(value[i]);
				}					
			}
			else if(value[4]=='\0'){ 
				if(value[3]!='\0'){
					if(value[1] =='1'){
						if(value[2]<='2'){
							if(value[3]<='7'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}								
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");	
				}
				else
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}				
			}	
			else 
				SendStr("\n\r error : failed value (-127 to 128) ");
			SendStr("\n\r control:# ");	
			
		}
		else{
			if(value[3]=='\0'){ 
				if(value[2]!='\0'){
					if(value[0] =='1'){
						if(value[1]<='2'){
							if(value[2]<='8'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}								
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");	
				}
				else
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}				
			}	
			else 
				SendStr("\n\r error : failed value (-127 to 128) ");
			SendStr("\n\r control:# ");	
		}
	}
	else if(strcmp (string,"camera")==0){
		SendStr("\n\r enter value between -127 (full left) and 128 (full right), 0 is the middle position : \n\r");
	  char value[5];
		int i;
		GetStr(value);
		if(value[0]=='-'){
			if(value[1]=='0')
				SendChar(value[1]);
			else if (value[3]=='\0' || value[2]=='\0'){
				for(i=0;i<=3;i++){
					SendChar(value[i]);
				}					
			}
			else if(value[4]=='\0'){ 
				if(value[3]!='\0'){
					if(value[1] =='1'){
						if(value[2]<='2'){
							if(value[3]<='7'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}								
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");	
				}
				else
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}				
			}	
			else 
				SendStr("\n\r error : failed value (-127 to 128) ");
			SendStr("\n\r control:# ");	
			
		}
		else{
			if(value[3]=='\0'){ 
				if(value[2]!='\0'){
					if(value[0] =='1'){
						if(value[1]<='2'){
							if(value[2]<='8'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}								
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");	
				}
				else
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}				
			}	
			else 
				SendStr("\n\r error : failed value (-127 to 128) ");
			SendStr("\n\r control:# ");	
		}
	}
	else if(strcmp (string,"meas")==0){
		SendStr("\n\r currents and voltage analog values for propulsion module : \n\r");
		SendStr("\r NOT FINISH YET \r");	
			SendStr("\n\r control:# ");		
	}
	else{
		SendStr("\n\r ERROR : command not supported. Enter help to know the supported command   \n\r");
			SendStr("\r control:# ");
	}
}