signed char GetFloat(const char *prompt, const char *unit, double* Value, double Min, double Max, double Precision) {
    double Output;
    char WholePlaces;
    char FractionalPlaces;
    signed char ret = 0;


    if ((Max >= 10000) || (Min <= -10000)) WholePlaces = 5;
    else if (Max >= 1000 | Min <= -1000) WholePlaces = 4;
    else if (Max >= 100 | Min <= -100) WholePlaces = 3;
    else if (Max >= 10 | Min <= -10) WholePlaces = 2;
    else WholePlaces = 2;

    if (Precision >= 1.0) FractionalPlaces = 0;
    else if (Precision >= 0.1) FractionalPlaces = 1;
    else if (Precision >= 0.01) FractionalPlaces = 2;
    else if (Precision >= 0.001) FractionalPlaces = 3;
    else if (Precision >= 0.0001) FractionalPlaces = 4;


    Output = *Value;
    LCD_ClearDisplay();
    LCD_PrintString(prompt);

    LCD_SetPosition(1, 0);
    LCD_PrintFloat(Output, WholePlaces, FractionalPlaces, 1);
    LCD_PrintString(unit);

    while (1) {
        LCD_SetPosition(1, 0);
        LCD_PrintFloat(Output, WholePlaces, FractionalPlaces, 1);
        ret = GetInput();
        if (ret < 0) return ret;
        switch (ret) {
            case USER_INPUT_CLICK: //user has pressed the switch to accept.                     
                *Value = Output;
                return (0);
            case USER_INPUT_CANCEL:
                return -2;
                
            case USER_INPUT_BACK:
                return -1;
                
            case USER_INPUT_INC: //Rot+
                Output += GetRotaryMultiplier() * Precision;
                if (Output > Max) Output = Max;
                break;
            case USER_INPUT_DEC:
                Output -= GetRotaryMultiplier() * Precision;
                if (Output < Min) Output = Min;
                break;
        }
    }
    return (0);
}
示例#2
0
int main(void)
{

  /* USER CODE BEGIN 1 */
	uint8_t damogranlabs_logo[]={
		0x0F,
		0x13,
		0x11,
		0x11,
		0x0e,
		0x00,
		0x00		
	};
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART1_UART_Init();

  /* USER CODE BEGIN 2 */
	LCD_Init(2, 20);
	LCD_CreateChar(0, damogranlabs_logo); 
	
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
	LCD_PrintString(2, 1, "n: ");
	LCD_PrintNumber(2, 4, -10);
	
	LCD_PrintString(2, 10, "f: ");
	LCD_PrintFloat(2, 13, -326.5635, 5);
	
	while (1)
  {
		LCD_PrintStringWindow(1, 3, 14, 350, "Find us on github and www.damogranlabs.com");
		LCD_Clear();
		LCD_PrintString(1, 1, "www.damogranlabs.com");
		LCD_PutCustom(2, 10, 0);
		LCD_ClearArea(1, 5, 12); 
		HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
		HAL_Delay(2000);
		
		
		
				/* USER CODE END WHILE */

		/* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */

}
signed char ShowVoltage() {    
    double Batt;
    LCD_ClearDisplay();
    bLock_BatteryVoltage = 1;
    Batt = BatteryVoltage;
    bLock_BatteryVoltage = 0;
    Batt *= Config.Volts_per_Count;
    LCD_PrintString("BATTERY VOLTAGE:\0");
    LCD_SetPosition(1, 0);
    LCD_PrintFloat(Batt, 2, 2, 0);
    LCD_PrintString(" VOLTS\0");
    return GetClick();
}
signed char RunOrbitProgram() {
    signed char retCode = 0;
    UI_Location = UI_LOC_ORBITRUN;
    signed char ret;
    double EndPos;
    double OriginPos;
    double TimeRemaining;
    double DistanceRemaining;
    double MPos;
   
    LCD_ClearDisplay();
    LCD_PrintString("MOVING TO START\0");
    OriginPos=(double)CurrentOrbitProgram.Origin_deg;
    MoveToAngle(OriginPos, 90);
    while (bMove_InProgress) {
        Idle();
        ret = GetInput_nonblocking();
        if (ret == USER_INPUT_CANCEL) {
            retCode = -2;
            goto labelFinished;
        }
        if (ret < 0) {
            retCode = ret;
            goto labelFinished;
        }
    }


    double Distance = CurrentOrbitProgram.CycleCount_rev * 360;
    if (CurrentOrbitProgram.EndMode == 2) Distance = 7776000;
    if (!CurrentOrbitProgram.IsClockWise) Distance = -Distance;

    bLock_Motor_Position = 1;
    OriginPos = Motor_Position;
    bLock_Motor_Position = 0;
    OriginPos *= Config.Degrees_Per_Count;

    EndPos = OriginPos + Distance;


    LCD_ClearDisplay();
    LCD_PrintString("RUNNING: T-HH:MM:SS\0");

    if (CurrentOrbitProgram.EndMode == 2) {
        LCD_ClearDisplay();
        LCD_PrintString("ORBIT RUNNING\0");
        LCD_SetPosition(1, 0);
        LCD_PrintString("INFINITE RUNTIME\0");
    }

    double SpdConvert = 1 / CurrentOrbitProgram.Speed_deg_sec;
    ret = GetInput_nonblocking();

    Move(Distance, CurrentOrbitProgram.Speed_deg_sec);
    while (bMove_InProgress) {

        bLock_Motor_Position = 1;
        MPos = Motor_Position;
        bLock_Motor_Position = 0;
        MPos *= Config.Degrees_Per_Count;

        DistanceRemaining = EndPos - MPos;
        if (DistanceRemaining < 0) DistanceRemaining = -DistanceRemaining;
        TimeRemaining = DistanceRemaining*SpdConvert;
        DistanceRemaining *= 0.002778;

        if (!(CurrentOrbitProgram.EndMode == 2)) {
            LCD_SetPosition(0, 11);
            PrintTime(TimeRemaining, 0b1110, 0);
            LCD_SetPosition(1, 0);
            LCD_PrintFloat(DistanceRemaining, 5, 2, 0);
            LCD_PrintString(" REV REMAIN\0");
        }

        ret = GetInput_nonblocking();
        if (ret == USER_INPUT_CANCEL) {
            retCode = -2;
            goto labelFinished;
        }
        if (ret < 0) {
            retCode = ret;
            goto labelFinished;
        }

        Idle();
    }

labelFinished:
    bMove_InProgress = 0;
    bFollowMode = 0;
    bSpeedMode = 1;
    Speed_SetToThis = 0;
    Speed_SetPending = 1;
    LCD_ClearDisplay();
    LCD_PrintString("STOPPING...\0");
    while (Speed_SetPending);
    while (Speed_IsAccelerating){
        Idle();
    }
    bMove_InProgress = 0;
    bFollowMode = 0;
    bSpeedMode=0;
    return retCode;
}