コード例 #1
0
ファイル: options.c プロジェクト: junwuwei/brltty
static DATA_OPERANDS_PROCESSOR(processConfigurationOperands) {
  const ConfigurationFileProcessingData *conf = data;
  int ok = 1;
  DataString keyword;

  if (getDataString(file, &keyword, 0, "configuration directive")) {
    DataString value;

    if (getDataString(file, &value, 0, "configuration value")) {
      char *v = makeUtf8FromWchars(value.characters, value.length, NULL);

      if (v) {
        if (!processConfigurationDirective(keyword.characters, v, conf)) ok = 0;

        free(v);
      } else {
        ok = 0;
      }
    } else {
      conf->info->warning = 1;
    }
  } else {
    conf->info->warning = 1;
  }

  return ok;
}
コード例 #2
0
void FileReaderTXT::getTimeStamp(long *seconds, long *useconds, int num)
{
	string x = getDataString(num);
	vector<string> result;
	splitString(x, &result, '.');

	if (result.size() != 2) {
		*seconds = 0;
		*useconds = 0;
		return;
	}

	char *p;
	*seconds = strtol(result.at(0).c_str(), &p, 10);

	if (*p != '\0') {
		*seconds = 0;
		*useconds = 0;
		return;
	}

	*useconds = strtol(result.at(1).c_str(), &p, 10);

	if (*p != '\0') {
		*seconds = 0;
		*useconds = 0;
		return;
	}
}
コード例 #3
0
const vector<string> FileReaderTXT::getDataStrings(int num, char separator)
{
	string x = getDataString(num);
	vector<string> result;
	splitString(x, &result, separator);

	return result;
}
コード例 #4
0
bool FileReaderTXT::getDataBool(int num, bool defaultValue) const
{
	string x = getDataString(num);
	if (x == "1") {
		return true;
	} else if (x == "") {
		return defaultValue;
	}
	return false;
}
コード例 #5
0
double FileReaderTXT::getDataDouble(int num) const
{
	string x = getDataString(num);
	char *p;
	double result = strtod(x.c_str(), &p);

	if (*p != '\0' || isnanLocal(result)) {
		return 0.0;
	}

	return result;
}
コード例 #6
0
ファイル: profile.c プロジェクト: junwuwei/brltty
static DATA_OPERANDS_PROCESSOR(processPropertyOperands) {
  const ProfileActivationData *pad = data;
  int ok = 1;
  DataString name;

  if (getDataString(file, &name, 0, "property name")) {
    DataString value;

    if (getDataString(file, &value, 0, "property value")) {
      char *v = makeUtf8FromWchars(value.characters, value.length, NULL);

      if (v) {
        if (!processPropertyAssignment(file, &name, &v, pad)) ok = 0;
        if (v) free(v);
      } else {
        ok = 0;
      }
    }
  }

  return ok;
}
コード例 #7
0
ファイル: ttb_native.c プロジェクト: MarkMielke/brltty
static int
getCharacterOperand (DataFile *file, wchar_t *character) {
  DataString string;
  const char *description = "unicode character";

  if (getDataString(file, &string, 0, description)) {
    if (!(string.characters[0] & ~UNICODE_CHARACTER_MASK)) {
      *character = string.characters[0];
      return 1;
    } else {
      reportDataError(file, "invalid %s: %.*" PRIws,
                      description, string.length, string.characters);
    }
  }

  return 0;
}
コード例 #8
0
ファイル: ttb_native.c プロジェクト: MarkMielke/brltty
static int
getByteOperand (DataFile *file, unsigned char *byte) {
  DataString string;
  const char *description = "local character";

  if (getDataString(file, &string, 1, description)) {
    if ((string.length == 1) && iswLatin1(string.characters[0])) {
      *byte = string.characters[0];
      return 1;
    } else {
      reportDataError(file, "invalid %s: %.*" PRIws,
                      description, string.length, string.characters);
    }
  }

  return 0;
}
コード例 #9
0
long FileReaderTXT::getDataInteger(int num, int defaultValue) const
{
	string x = getDataString(num);

	if (x == "") {
		return defaultValue;
	}

	char *p;
	long result = strtol(x.c_str(), &p, 10);

	if (*p != '\0') {
		return defaultValue;
	}

	return result;
}
コード例 #10
0
void BluetoothController::sendBlueToothData()  {
  static long previousMillis = 0;                             
  long currentMillis = millis();
  if(currentMillis - previousMillis > sendInterval) {   // send data back to smartphone
    previousMillis = currentMillis; 

    // Data frame transmitted back from Arduino to Android device:
    // < 0X02   Buttons state   0X01   DataField#1   0x04   DataField#2   0x05   DataField#3    0x03 >  
    // < 0X02      "01011"      0X01     "120.00"    0x04     "-4500"     0x05  "Motor enabled" 0x03 >    // example

    Serial2.print((char)STX);                                             // Start of Transmission
    Serial2.print(getButtonStatusString());  Serial2.print((char)0x1);    // buttons status feedback
    Serial2.print(getDataInt());             Serial2.print((char)0x4);    // datafield #1
    Serial2.print(getDataFloat());           Serial2.print((char)0x5);    // datafield #2
    Serial2.print(getDataString());                                       // datafield #3
    Serial2.print((char)ETX);                                             // End of Transmission
  }  
}
コード例 #11
0
ファイル: SimulatorWin.cpp プロジェクト: hugohuang1111/Bird
void SimulatorWin::setupUI()
{
    auto menuBar = player::PlayerProtocol::getInstance()->getMenuService();

    // FILE
    menuBar->addItem("FILE_MENU", tr("File"));
    menuBar->addItem("EXIT_MENU", tr("Exit"), "FILE_MENU");

    // VIEW
    menuBar->addItem("VIEW_MENU", tr("View"));
    SimulatorConfig *config = SimulatorConfig::getInstance();
    int current = config->checkScreenSize(_project.getFrameSize());
    for (int i = 0; i < config->getScreenSizeCount(); i++)
    {
        SimulatorScreenSize size = config->getScreenSize(i);
        std::stringstream menuId;
        menuId << "VIEWSIZE_ITEM_MENU_" << i;
        auto menuItem = menuBar->addItem(menuId.str(), size.title.c_str(), "VIEW_MENU");

        if (i == current)
        {
            menuItem->setChecked(true);
        }
    }

    menuBar->addItem("DIRECTION_MENU_SEP", "-", "VIEW_MENU");
    menuBar->addItem("DIRECTION_PORTRAIT_MENU", tr("Portrait"), "VIEW_MENU")
        ->setChecked(_project.isPortraitFrame());
    menuBar->addItem("DIRECTION_LANDSCAPE_MENU", tr("Landscape"), "VIEW_MENU")
        ->setChecked(_project.isLandscapeFrame());

    menuBar->addItem("VIEW_SCALE_MENU_SEP", "-", "VIEW_MENU");
    std::vector<player::PlayerMenuItem*> scaleMenuVector;
    auto scale100Menu = menuBar->addItem("VIEW_SCALE_MENU_100", tr("Zoom Out").append(" (100%)"), "VIEW_MENU");
    auto scale75Menu = menuBar->addItem("VIEW_SCALE_MENU_75", tr("Zoom Out").append(" (75%)"), "VIEW_MENU");
    auto scale50Menu = menuBar->addItem("VIEW_SCALE_MENU_50", tr("Zoom Out").append(" (50%)"), "VIEW_MENU");
    auto scale25Menu = menuBar->addItem("VIEW_SCALE_MENU_25", tr("Zoom Out").append(" (25%)"), "VIEW_MENU");
    int frameScale = int(_project.getFrameScale() * 100);
    if (frameScale == 100)
    {
        scale100Menu->setChecked(true);
    }
    else if (frameScale == 75)
    {
        scale75Menu->setChecked(true);
    }
    else if (frameScale == 50)
    {
        scale50Menu->setChecked(true);
    }
    else if (frameScale == 25)
    {
        scale25Menu->setChecked(true);
    }
    else
    {
        scale100Menu->setChecked(true);
    }

    scaleMenuVector.push_back(scale100Menu);
    scaleMenuVector.push_back(scale75Menu);
    scaleMenuVector.push_back(scale50Menu);
    scaleMenuVector.push_back(scale25Menu);

    menuBar->addItem("REFRESH_MENU_SEP", "-", "VIEW_MENU");
    menuBar->addItem("REFRESH_MENU", tr("Refresh"), "VIEW_MENU");

    HWND &hwnd = _hwnd;
    ProjectConfig &project = _project;
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    dispatcher->addEventListenerWithFixedPriority(EventListenerCustom::create("APP.EVENT", [&project, &hwnd, scaleMenuVector](EventCustom* event){
        auto menuEvent = dynamic_cast<AppEvent*>(event);
        if (menuEvent)
        {
            rapidjson::Document dArgParse;
            dArgParse.Parse<0>(menuEvent->getDataString().c_str());
            if (dArgParse.HasMember("name"))
            {
                string strcmd = dArgParse["name"].GetString();

                if (strcmd == "menuClicked")
                {
                    player::PlayerMenuItem *menuItem = static_cast<player::PlayerMenuItem*>(menuEvent->getUserData());
                    if (menuItem)
                    {
                        if (menuItem->isChecked())
                        {
                            return;
                        }

                        string data = dArgParse["data"].GetString();
                        auto player = player::PlayerProtocol::getInstance();

                        if ((data == "CLOSE_MENU") || (data == "EXIT_MENU"))
                        {
                            player->quit();
                        }
                        else if (data == "REFRESH_MENU")
                        {
                            player->relaunch();
                        }
                        else if (data.find("VIEW_SCALE_MENU_") == 0) // begin with VIEW_SCALE_MENU_
                        {
                            string tmp = data.erase(0, strlen("VIEW_SCALE_MENU_"));
                            float scale = atof(tmp.c_str()) / 100.0f;
                            project.setFrameScale(scale);

                            auto glview = static_cast<GLViewImpl*>(Director::getInstance()->getOpenGLView());
                            glview->setFrameZoomFactor(scale);

                            // update scale menu state
                            for (auto &it : scaleMenuVector)
                            {
                                it->setChecked(false);
                            }
                            menuItem->setChecked(true);

                            // update window size
                            RECT rect;
                            GetWindowRect(hwnd, &rect);
                            MoveWindow(hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top + GetSystemMetrics(SM_CYMENU), FALSE);
                        
                            // fix: can not update window on some windows system 
                            ::SendMessage(hwnd, WM_MOVE, NULL, NULL);
                        }
                        else if (data.find("VIEWSIZE_ITEM_MENU_") == 0) // begin with VIEWSIZE_ITEM_MENU_
                        {
                            string tmp = data.erase(0, strlen("VIEWSIZE_ITEM_MENU_"));
                            int index = atoi(tmp.c_str());
                            SimulatorScreenSize size = SimulatorConfig::getInstance()->getScreenSize(index);

                            if (project.isLandscapeFrame())
                            {
                                std::swap(size.width, size.height);
                            }

                            project.setFrameSize(cocos2d::Size(size.width, size.height));
                            project.setWindowOffset(cocos2d::Vec2(player->getPositionX(), player->getPositionY()));
                            player->openProjectWithProjectConfig(project);
                        }
                        else if (data == "DIRECTION_PORTRAIT_MENU")
                        {
                            project.changeFrameOrientationToPortait();
                            player->openProjectWithProjectConfig(project);
                        }
                        else if (data == "DIRECTION_LANDSCAPE_MENU")
                        {
                            project.changeFrameOrientationToLandscape();
                            player->openProjectWithProjectConfig(project);
                        }
                    }
                }
            }
        }
    }), 1);

    AppDelegate *app = _app;
    auto listener = EventListenerCustom::create(kAppEventDropName, [&project, app](EventCustom* event)
    {
        AppEvent *dropEvent = dynamic_cast<AppEvent*>(event);
        if (dropEvent)
        {
            string dirPath = dropEvent->getDataString() + "/";
            string configFilePath = dirPath + CONFIG_FILE;

            if (FileUtils::getInstance()->isDirectoryExist(dirPath) &&
                FileUtils::getInstance()->isFileExist(configFilePath))
            {
                // parse config.json
                ConfigParser::getInstance()->readConfig(configFilePath);

                project.setProjectDir(dirPath);
                project.setScriptFile(ConfigParser::getInstance()->getEntryFile());
                project.setWritablePath(dirPath);

                app->setProjectConfig(project);
                app->reopenProject();
            }
        }
    });
    dispatcher->addEventListenerWithFixedPriority(listener, 1);
}
コード例 #12
0
ファイル: Main Program.c プロジェクト: phuongtg/micro2-1
int main(void)
{
	//========= Peripheral Enable and Setup ===========//
	setup_LCD(); //LCD Screen setup
	setup_tmp36(); //TMP36 ADC thermometer setup


	setup_GPS(); //GPS Pin Setup
	setup_microSD(); //MicroSD Pin Setup
	setupTMP102();  
	setup_PID(&pid);
	setupBMS();
	setup_pwm();

	//Setup the buttons
	
	setup_buttonInterrupts();
	sleepEnablePeripherals();
	setup_timerInterrupt();

	
	//========= Peripheral enable and run ============//
	enable_LCD(); //Start LCD Commmunication
	enable_GPS(); //Start GPS Communication
	clearDisplay(); //Refresh Display



	while(1)
	{	
		//Listen for the GPS Data
		listen_GPS();
		//Open the datalog file for writing
		open_datalog();

		//Obtain vehicle speed
		char *velocity;
		char velocityArray[] = "000";
		
		//velocity = velocityArray;
		velocity = getVelocity();
		//Convert string to int
		int speedInteger = atoi(velocity);
		//Convert knots to mph

		
		speedInteger = 1.15 * speedInteger;
		//Return to string
		sprintf(velocity, "%i", speedInteger);
		// velocity = "50";
		selectLineOne();
		//Show velocity
		putPhrase("V:");
		putPhrase(velocity);

		//Analog Temperature Sensor
		int anag_tempValue = get_analog_temp();
		sprintf(anag_temp, "%i", anag_tempValue);

		//Digital Temperature Sensor
		int digi_tempValue = getTemperature();
		sprintf(digi_temp, "%i", digi_tempValue);

		//Get BMS Level
		char load[] = "89";
		char *load_value;
		load_value = load;
		//-------BMS Communication------
		sendStartSequence();
		getDataString();
		load_value = getLoad();
		//------------------------------

		

			
		//If Cruise Control is on
		if(enableSys)
		{	
			//If initialized
			if(obtain_speed)
			{	//Debouncing
				//SysCtlDelay(533333);
				obtain_speed = 0;
				clearDisplay();

				//Get set velocity
				set_velocity = 10;
			}

			//If driver increases set speed
			if(incr_speed)
			{	
				//SysCtlDelay(533333);

				incr_speed = 0;
				set_velocity += 1;
			}

			//if driver decresaes set speed
			else if(decr_speed)
			{	
				//SysCtlDelay(533333);
				decr_speed = 0;
				set_velocity -= 1;
			}

			//==============PID Portion of the Main Loop ==============//
			float process_value = atof(velocity); //Convert String to Int
			float error = set_velocity - process_value; //Calculate error
			float u_t = UpdatePID(&pid, error, 1.0); //Feed error to the PID
			
			uint32_t duty_cycle = u_t*scaleFactor;
			if(duty_cycle < 950){
				duty_cycle = 50;
			}
			else if(duty_cycle > 0){
				duty_cycle = 950;
			}
			pwm_out(1000, duty_cycle); //Scale and output the PID output

			//====================================================//

			//Show other essentials to the LCD
			putPhrase("mph/"); 

			char set_point[5];
			sprintf(set_point, "%imph", (int) set_velocity);
			putPhrase(set_point);
			putPhrase(" ON"); //Cruise control on

		}

		else
		{
			//Spacer
			putPhrase("mph ");
			putPhrase("Standby  ");

		}

		//Select bottom line
		selectLineTwo();

		//Display analog and digital temperatures
		putPhrase("T:");
		putPhrase(anag_temp);
		putPhrase("/");
		putPhrase(digi_temp);
		putPhrase("C  ");


		//Show Load level
		putPhrase("B:");
		putPhrase(load_value);
		putPhrase("%");

		
		write_datalog(velocity, "ddmm.mmmmmmX", "ddmm.mmmmmX", getTime(), anag_temp, digi_temp, load_value);
		close();

		//Put system in low power mode
		SysCtlSleep();	


}
}
コード例 #13
0
bool JsonActionResolver::resolve(std::string jsonMessage, ClientAction &action) {
  const char *json = jsonMessage.c_str();
  picojson::value v;
  std::string err;
  picojson::parse(v, json, json + strlen(json), &err);
  if (!err.empty()) {
    std::cout << "Error while parsing json: " << err << std::endl;
    return false;
  }
  if (!v.is<picojson::object>()) {
    std::cout << "JSON is not an object" << jsonMessage << std::endl;
    return false;
  }

  std::string message;
  if (!getString(v, "message", message)) {
    return false;
  }

  std::transform(message.begin(), message.end(), message.begin(), ::tolower);
  if (message == "start_tournament") {
    // Requires password
    if (!getDataString(v, "password", action)) return false;
    if (!getDataInt(v, "numberOfGames", action)) action.ints.insert(std::pair<std::string, int>("numberOfGames", 1));
    action.type = ClientAction::START_TOURNAMENT;
    return true;
  } else if (message == "end_tournament") {
    // Requires password
    if (!getDataString(v, "password", action)) return false;
    action.type = ClientAction::END_TOURNAMENT;
    return true;
  } else if (message == "end_game") {
    // Requires password
    if (!getDataString(v, "password", action)) return false;
    action.type = ClientAction::END_GAME;
    return true;
  } else if (message == "authenticate_admin") {
    // Requires password
    if (!getDataString(v, "password", action)) return false;
    action.type = ClientAction::AUTHENTICATE_ADMIN;
    return true;
  } else if (message == "update_settings") {
    // Requires password
    if (!getDataString(v, "password", action)) return false;
    getDataFloat(v, "wormWidth", action);
    getDataFloat(v, "wormSpeed", action);
    getDataFloat(v, "turnSpeed", action);
    getDataInt(v, "countdown", action);
    getDataInt(v, "minTimeBetweenGaps", action);
    getDataInt(v, "maxTimeBetweenGaps", action);
    getDataInt(v, "minTimeInGap", action);
    getDataInt(v, "maxTimeInGap", action);
    action.type = ClientAction::UPDATE_SETTINGS;
    return true;
  }
  else if (message == "register") {
    // Requires name
    if (!getDataString(v, "name", action)) return false;
    action.type = ClientAction::REGISTER;
		return true;
  } else if (message == "unregister") {
    action.type = ClientAction::UNREGISTER;
    return true;
  } else if (message == "start_moving") {
    action.type = ClientAction::START_MOVING;
		return true;
	} else if (message == "left_down") {
    action.type = ClientAction::LEFT_DOWN;
		return true;
	} else if (message == "left_up") {
    action.type = ClientAction::LEFT_UP;
		return true;
	} else if (message == "right_down") {
    action.type = ClientAction::RIGHT_DOWN;
		return true;
	} else if (message == "right_up") {
    action.type = ClientAction::RIGHT_UP;
		return true;
	}
	std::cout << "Message not recognized: " << message << std::endl;
	return false;
}
コード例 #14
0
QString UniformItem::getCsv() const
{
    QString result = QString("%1:%2:").arg(name).arg(int(type));
    result += getDataString();
    return result;
}