void FAutomationTestPresetManager::LoadPresets( ) { TArray<FString> PresetFileNames; IFileManager::Get().FindFiles(PresetFileNames, *(GetPresetFolder() / TEXT("*.uap")), true, false); for (TArray<FString>::TConstIterator It(PresetFileNames); It; ++It) { FString PresetFilePath = GetPresetFolder() / *It; FArchive* PresetFileReader = IFileManager::Get().CreateFileReader(*PresetFilePath); if (PresetFileReader != nullptr) { AutomationPresetPtr LoadedPreset = LoadPreset(*PresetFileReader); if (LoadedPreset.IsValid()) { Presets.Add(LoadedPreset); } else { IFileManager::Get().Delete(*PresetFilePath); } delete PresetFileReader; } } }
signed char RunPreset(signed char pnum) { signed char ret; switch (GetPresetType(pnum)) { case 1: LoadPreset(pnum, (unsigned char *) &CurrentPath); ret = RunWaypointProgram(); if (ret<-2) return ret; if (ret < 0) { ret = RealtimeMode(); if (ret<-2) return ret; } break; case 2: LoadPreset(pnum, (unsigned char *) &CurrentOrbitProgram); ret = RunOrbitProgram(); if (ret<-2) return ret; if (ret < 0) { ret = RealtimeMode(); if (ret<-2) return ret; } break; } return 0; }
void Idle() { unsigned int addr = 0; unsigned char MsgAddr = 0; unsigned char PresetNumber = 0; unsigned char *ConfigPtr; ConfigStruct TempConfig; char idx; MULTI temp; PRESET tempPset; if (ExtModeActive) { idx = 255; while (idx--); return; } if (!RX_MsgComplete) { idx = 255; while (idx--); return; } ChkSum = 0; ReadIdx = 1; RX_MsgComplete = 0; MsgAddr = MessageStream_ReadByte(); if (MsgAddr == 0xFF) { TX_Idx = 0; TXBuffer[TX_Idx++] = '$'; MessageStream_WriteByte(MyID); MessageStream_WriteByte('O'); MessageStream_WriteByte('R'); MessageStream_WriteByte('B'); MessageStream_WriteByte('I'); MessageStream_WriteByte('T'); TXBuffer[TX_Idx++] = '#'; idx = TX_Idx; TX_Idx = 0; TX_bCount = idx; } else if (MsgAddr == MyID) { unsigned char CmdID = MessageStream_ReadByte(); switch (CmdID) { case CMD_GET_COMPLETE_STATUS: TX_Idx = 0; TXBuffer[TX_Idx++] = '$'; MessageStream_WriteByte(CmdID); for (idx = 0; idx < 20; idx++) { MessageStream_WriteByte(LCD_Line2[idx]); ChkSum += LCD_Line2[idx]; } for (idx = 0; idx < 20; idx++) { MessageStream_WriteByte(LCD_Line1[idx]); ChkSum += LCD_Line1[idx]; } bLock_Motor_Position = 1; temp.dbl = Motor_Position; bLock_Motor_Position = 0; temp.dbl *= Config.Degrees_Per_Count; MessageStream_WriteByte(temp.ub[0]); MessageStream_WriteByte(temp.ub[1]); MessageStream_WriteByte(temp.ub[2]); MessageStream_WriteByte(temp.ub[3]); ChkSum += temp.ub[0]; ChkSum += temp.ub[1]; ChkSum += temp.ub[2]; ChkSum += temp.ub[3]; temp.dbl = 0; while (!(temp.dbl == Move_speedQ24)) temp.dbl = Move_speedQ24; temp.dbl *= INV_Conversion_Q24_500Hz; temp.dbl *= Config.Degrees_Per_Count; MessageStream_WriteByte(temp.ub[0]); MessageStream_WriteByte(temp.ub[1]); MessageStream_WriteByte(temp.ub[2]); MessageStream_WriteByte(temp.ub[3]); ChkSum += temp.ub[0]; ChkSum += temp.ub[1]; ChkSum += temp.ub[2]; ChkSum += temp.ub[3]; temp.dbl = 0; bLock_BatteryVoltage = 1; temp.dbl = BatteryVoltage; bLock_BatteryVoltage = 0; temp.dbl *= Config.Volts_per_Count; MessageStream_WriteByte(temp.ub[0]); MessageStream_WriteByte(temp.ub[1]); MessageStream_WriteByte(temp.ub[2]); MessageStream_WriteByte(temp.ub[3]); ChkSum += temp.ub[0]; ChkSum += temp.ub[1]; ChkSum += temp.ub[2]; ChkSum += temp.ub[3]; MessageStream_WriteByte(ChkSum); TXBuffer[TX_Idx++] = '#'; idx = TX_Idx; TX_Idx = 0; TX_bCount = idx; break; case CMD_GETDISPLAY: TX_Idx = 0; TXBuffer[TX_Idx++] = '$'; MessageStream_WriteByte(CmdID); for (idx = 0; idx < 20; idx++) { MessageStream_WriteByte(LCD_Line2[idx]); ChkSum += LCD_Line2[idx]; } for (idx = 0; idx < 20; idx++) { MessageStream_WriteByte(LCD_Line1[idx]); ChkSum += LCD_Line1[idx]; } MessageStream_WriteByte(ChkSum); TXBuffer[TX_Idx++] = '#'; idx = TX_Idx; TX_Idx = 0; TX_bCount = idx; break; case CMD_UI_CLICK: isPendingExternalUIEvent = 0; PendingExternalUIEvent = USER_INPUT_CLICK; isPendingExternalUIEvent = 1; AckCmd(CmdID); break; case CMD_UI_CANCEL: isPendingExternalUIEvent = 0; PendingExternalUIEvent = USER_INPUT_CANCEL; isPendingExternalUIEvent = 1; AckCmd(CmdID); break; case CMD_UI_BACK: isPendingExternalUIEvent = 0; PendingExternalUIEvent = USER_INPUT_BACK; isPendingExternalUIEvent = 1; AckCmd(CmdID); break; case CMD_UI_INC: isPendingExternalUIEvent = 0; PendingExternalUIEvent = USER_INPUT_INC; isPendingExternalUIEvent = 1; AckCmd(CmdID); break; case CMD_UI_DEC: isPendingExternalUIEvent = 0; PendingExternalUIEvent = USER_INPUT_DEC; isPendingExternalUIEvent = 1; AckCmd(CmdID); break; case CMD_UI_MACRO: isPendingExternalUIEvent = 0; PendingExternalUIEvent = -MessageStream_ReadByte(); isPendingExternalUIEvent = 1; AckCmd(CmdID); break; case CMD_GET_UI_LOC: TX_Idx = 0; TXBuffer[TX_Idx++] = '$'; MessageStream_WriteByte(CmdID); MessageStream_WriteByte(UI_Location); MessageStream_WriteByte(UI_Location); TXBuffer[TX_Idx++] = '#'; idx = TX_Idx; TX_Idx = 0; TX_bCount = idx; break; case CMD_GET_POS: bLock_Motor_Position = 1; temp.dbl = Motor_Position; bLock_Motor_Position = 0; temp.dbl *= Config.Degrees_Per_Count; MessageStream_WriteMULTI(temp, CmdID); break; case CMD_GET_SPEED: temp.dbl = 0; while (!(temp.dbl == Move_speedQ24)) temp.dbl = Move_speedQ24; temp.dbl *= INV_Conversion_Q24_500Hz; temp.dbl *= Config.Degrees_Per_Count; MessageStream_WriteMULTI(temp, CmdID); break; case CMD_GET_BATTERY: temp.dbl = 0; bLock_BatteryVoltage = 1; temp.dbl = BatteryVoltage; bLock_BatteryVoltage = 0; temp.dbl *= Config.Volts_per_Count; MessageStream_WriteMULTI(temp, CmdID); break; case CMD_GET_PRESET: PresetNumber = MessageStream_ReadByte(); if (PresetNumber > 5) { NackCmd(CmdID, 1); break; } if (PresetNumber == 0) { NackCmd(CmdID, 1); break; } LoadPreset(PresetNumber, (unsigned char *) &tempPset); TX_Idx = 0; TXBuffer[TX_Idx++] = '$'; MessageStream_WriteByte(CmdID); for (idx = 0; idx<sizeof (tempPset); idx++) { MessageStream_WriteByte(tempPset.ub[idx]); ChkSum += tempPset.ub[idx]; } MessageStream_WriteByte(ChkSum); TXBuffer[TX_Idx++] = '#'; idx = TX_Idx; TX_Idx = 0; TX_bCount = idx; break; case CMD_SET_PRESET: PresetNumber = MessageStream_ReadByte(); if (PresetNumber > 5) { NackCmd(CmdID, 1); break; } if (PresetNumber == 0) { NackCmd(CmdID, 1); break; } ChkSum += PresetNumber; for (idx = 0; idx < 120; idx++) { tempPset.ub[idx] = MessageStream_ReadByte(); ChkSum += tempPset.ub[idx]; } if (ChkSum == MessageStream_ReadByte()) { SavePreset(PresetNumber, (unsigned char *) &tempPset); AckCmd(CmdID); } else { NackCmd(CmdID, ChkSum); } break; case CMD_GET_CONFIG: ConfigPtr = (unsigned char *) &Config; TX_Idx = 0; TXBuffer[TX_Idx++] = '$'; MessageStream_WriteByte(CmdID); for (idx = 0; idx<sizeof (Config); idx++) { MessageStream_WriteByte((*ConfigPtr)); ChkSum += (*ConfigPtr); ConfigPtr++; } MessageStream_WriteByte(ChkSum); TXBuffer[TX_Idx++] = '#'; idx = TX_Idx; TX_Idx = 0; TX_bCount = idx; break; case CMD_SET_CONFIG: ConfigPtr = (unsigned char *) &TempConfig; for (idx = 0; idx < sizeof (Config); idx++) { (*ConfigPtr) = MessageStream_ReadByte(); ChkSum += (*ConfigPtr); ConfigPtr++; } if (ChkSum == MessageStream_ReadByte()) { addr=0; EEprom_write(&addr, (unsigned char *) &TempConfig, sizeof (TempConfig)); AckCmd(CmdID); } else { NackCmd(CmdID, ChkSum); } break; default: NackCmd(CmdID, 0xFF); } } return; }
int HandleCLIOptions(int argc,char *argv[], OPTIONS *options) { int i,firstnonoption=0; for (i=1; i< argc;i++) { if (argv[i][0] == '/' || argv[i][0] == '-') { switch (argv[i][1]) { /* An argument -? means help is requested */ case '?': PrintUsage(argv[0]); break; case 'h': case 'H': if (!stricmp(argv[i]+1,"help")) { PrintUsage(argv[0]); } if (!stricmp(argv[i]+1,"height")) { //also might mean height if (i+1<argc) { options->height = strtol(argv[i+1], NULL, 0); i++; } } break; case 'n': case 'N': if (!stricmp(argv[i]+1,"north") || *(argv[i]+2)==0) { //if it's north or n (terminated with 0) if (i+1<argc) { options->north = strtod(argv[i+1], NULL); i++; } } break; case 's': case 'S': if (!stricmp(argv[i]+1,"south") || *(argv[i]+2)==0) { //if it's north or n (terminated with 0) if (i+1<argc) { options->south = strtod(argv[i+1], NULL); i++; } } break; case 'w': case 'W': if (!stricmp(argv[i]+1,"west") || *(argv[i]+2)==0) { //if it's north or n (terminated with 0) if (i+1<argc) { options->west = strtod(argv[i+1], NULL); i++; } } if (!stricmp(argv[i]+1,"width")) { //also might mean height if (i+1<argc) { options->width = strtol(argv[i+1], NULL, 0); i++; } } break; case 'e': case 'E': if (!stricmp(argv[i]+1,"east") || *(argv[i]+2)==0) { //if it's north or n (terminated with 0) if (i+1<argc) { options->east = strtod(argv[i+1], NULL); i++; } } break; case 'x': case 'X': if (i+1<argc) { options->width = strtol(argv[i+1], NULL, 0); i++; } break; case 'y': case 'Y': if (i+1<argc) { options->height = strtol(argv[i+1], NULL, 0); i++; } break; /* //I've stopped using zoom as an argument case 'z': case 'Z': if (i+1<argc) { options->zoom = strtod(argv[i+1], NULL); i++; //move to the next variable, we've got a zoom } break; */ case 'g': //the grid case 'G': if (i+1<argc) { options->gridsize = strtod(argv[i+1], NULL); i++; } break; case 'c': //how to cycle through the colours case 'C': if (i+1<argc) { if (!stricmp(argv[i+1],"day")) options->colourcycle=60*60*24; else if (!stricmp(argv[i+1],"week")) options->colourcycle=60*60*24*7; else if (!stricmp(argv[i+1],"month")) options->colourcycle=60*60*24*30.4375; else if (!stricmp(argv[i+1],"halfyear")) options->colourcycle=60*60*24*182.625; else if (!stricmp(argv[i+1],"year")) options->colourcycle=60*60*24*365.25; else if (!stricmp(argv[i+1],"hour")) options->colourcycle=60*60; else options->colourcycle = strtol(argv[i+1], NULL, 0); i++; } break; case 'p': case 'P': if (!stricmp(argv[i]+1,"preset") || *(argv[i]+2)==0) { //preset or just p if (i+1<argc) { LoadPreset(options, argv[i+1]); i++; } } break; case 'a': //alpha value case 'A': if (i+1<argc) { options->alpha = strtod(argv[i+1], NULL); i++; } break; case 'f': //from time case 'F': if (i+1<argc) { options->fromtimestamp = strtol(argv[i+1], NULL,0); i++; } break; case 't': //to time case 'T': if (i+1<argc) { options->totimestamp = strtol(argv[i+1], NULL,0); i++; } break; case 'k': case 'K': if (i+1<argc) { options->kmlfilenameinput = argv[i+1]; i++; } break; case 'i': case 'I': if (i+1<argc) { options->jsonfilenameinput = argv[i+1]; i++; } break; case 'o': case 'O': if (i+1<argc) { options->pngfilenameinput = argv[i+1]; i++; } break; default: fprintf(stderr,"unknown option %s\n",argv[i]); break; } } else { options->pngfilenameinput = argv[i]; firstnonoption = i; break; } } return firstnonoption; }
void main(void) { signed char ret = 0; signed char lastMenu = 0; char pnum = 0; SetupIO(); MOTOR_FORWARD = 0; MOTOR_REVERSE = 0; Move_shifted_position.ul = 0; Move_position[0].ul = 0; Move_position[1].ul = 0; //PID_SetPoint = 0; char idx; for (idx = 0; idx < 16; idx++) RotaryDetentIntervals[idx] = 0xFF; //LoadSettings(); FactoryDefault(); SetupHardware(); LCD_PowerUp(); LCD_ClearDisplay(); LCD_PrintString("CINEFLUX ORBIT\0"); LCD_SetPosition(1,0); LCD_PrintString(VER); Wait_ms(2000); const char *COMMAND_0 = "ORBIT MODE\0"; const char *COMMAND_1 = "WAYPOINT MODE\0"; const char *COMMAND_3 = "RUN PRESET\0"; const char *COMMAND_2 = "REALTIME MODE\0"; const char *COMMAND_4 = "BATTERY VOLTAGE\0"; const char *COMMAND_5 = "GO TO SLEEP\0"; const char *COMMAND_6 = "EXTERNAL CTRL MODE\0"; const char*CommandMenu[7]; CommandMenu[0] = COMMAND_0; CommandMenu[1] = COMMAND_1; CommandMenu[2] = COMMAND_2; CommandMenu[3] = COMMAND_3; CommandMenu[4] = COMMAND_4; CommandMenu[5] = COMMAND_5; CommandMenu[6] = COMMAND_6; bFollowMode = 1; LCD_ClearDisplay(); LCD_PrintString("MOVE TO ZERO DEGREES\0"); LCD_SetPosition(1, 0); LCD_PrintString("THEN CLICK...\0"); GetClick(); bClear_MotorPosition = 1; while (bClear_MotorPosition) Idle(); Wait_ms(10); bFollowMode = 0; LCD_ClearDisplay(); while (1) { ret = DisplayMenu(CommandMenu, 6, lastMenu); switch (ret) { case 0: lastMenu = 0; if (!CreateOrbitProgram() == 0) RealtimeMode(); break; case 1: lastMenu = 1; if (!CreateWaypointProgram() == 0) RealtimeMode(); break; case 3: lastMenu = 2; ret = GetPresetNumber(); if (ret == -1) break; if (ret == -2) break; pnum = ret; switch (GetPresetType(pnum)) { case 1: LoadPreset(pnum, (unsigned char *) &CurrentPath); if (!RunWaypointProgram() == 0) RealtimeMode(); break; case 2: LoadPreset(pnum, (unsigned char *) &CurrentOrbitProgram); if (!RunOrbitProgram() == 0) RealtimeMode(); break; } break; case 2: lastMenu = 2; RealtimeMode(); break; case 4: lastMenu = 0; ShowVoltage(); break; case 5: lastMenu = 0; GoToSleep(); break; case 6: lastMenu = 0; ExtMode(); break; } } }