Esempio n. 1
0
void ssp3_init(void)
{	
#if 0
     SPI_InitTypeDef  SPI_InitStructure;
     int_dis(INT_SRC_NBR_SPI3);
 
     sFLASH_LowLevel_Init();
     /*!< Deselect the FLASH: Chip Select high */
     mx25l64_cs_set();
     /*!< SPI configuration */
     SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
     SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
     SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
     SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
     SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
     SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
     SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
     SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
     SPI_InitStructure.SPI_CRCPolynomial = 7;
     SPI_Init(SPI3, &SPI_InitStructure);
     /*!< Enable the sFLASH_SPI  */
     SPI_Cmd(SPI3, ENABLE);
#endif
}
Esempio n. 2
0
QPoint EffectInstance::get_location(int location, int centering)
{
    QPoint l;
    QPoint c;

    if(location == Effect::Position::Any){
        std::uniform_int_distribution<> int_dis(0, Effect::Position::Last - 2);
        location = int_dis(owner->parent_pony->gen);
    }else if(location == Effect::Position::Any_NotCenter){
        std::uniform_int_distribution<> int_dis(0, Effect::Position::Last - 3);
        location = int_dis(owner->parent_pony->gen);
    }

    if(centering == Effect::Position::Any){
        std::uniform_int_distribution<> int_dis(0, Effect::Position::Last - 2);
        centering = int_dis(owner->parent_pony->gen);
    }else if(centering == Effect::Position::Any_NotCenter){
        std::uniform_int_distribution<> int_dis(0, Effect::Position::Last - 3);
        centering = int_dis(owner->parent_pony->gen);
    }

    switch(location){
        case Effect::Position::Top_Right: {
            l.setY(0);
            l.setX(owner->parent_pony->width());
            break;
        }
        case Effect::Position::Top_Left: {
            l.setY(0);
            l.setX(0);
            break;
        }
        case Effect::Position::Bottom_Right: {
            l.setY(owner->parent_pony->height());
            l.setX(owner->parent_pony->width());
            break;
        }
        case Effect::Position::Bottom_Left: {
            l.setY(owner->parent_pony->height());
            l.setX(0);
            break;
        }
        case Effect::Position::Top: {
            l.setY(0);
            l.setX(owner->parent_pony->width()/2);
            break;
        }
        case Effect::Position::Bottom: {
            l.setY(owner->parent_pony->height());
            l.setX(owner->parent_pony->width()/2);
            break;
        }
        case Effect::Position::Left: {
            l.setY(owner->parent_pony->height()/2);
            l.setX(0);
            break;
        }
        case Effect::Position::Right: {
            l.setY(owner->parent_pony->height()/2);
            l.setX(owner->parent_pony->width());
            break;
        }
        case Effect::Position::Center: {
            l.setY(owner->parent_pony->height()/2);
            l.setX(owner->parent_pony->width()/2);
            break;
        }
    }

    switch(centering){
        case Effect::Position::Top_Right: {
            c.setY(0);
            c.setX(image_width);
            break;
        }
        case Effect::Position::Top_Left: {
            c.setY(0);
            c.setX(0);
            break;
        }
        case Effect::Position::Bottom_Right: {
            c.setY(image_height);
            c.setX(image_width);
            break;
        }
        case Effect::Position::Bottom_Left: {
            c.setY(image_height);
            c.setX(0);
            break;
        }
        case Effect::Position::Top: {
            c.setY(0);
            c.setX(image_width/2);
            break;
        }
        case Effect::Position::Bottom: {
            c.setY(image_height);
            c.setX(image_width/2);
            break;
        }
        case Effect::Position::Left: {
            c.setY(image_height/2);
            c.setX(0);
            break;
        }
        case Effect::Position::Right: {
            c.setY(image_height/2);
            c.setX(image_width);
            break;
        }
        case Effect::Position::Center: {
            c.setY(image_height/2);
            c.setX(image_width/2);
            break;
        }
    }

    return l - c;
}
Esempio n. 3
0
// Initialize current behavior
void Pony::setup_current_behavior()
{
    if(current_behavior->type == Behavior::State::Following || current_behavior->type == Behavior::State::MovingToPoint) {
        if(current_behavior->type == Behavior::State::Following){
            // Find follow_object (which is not empty, because we checked it while initializing)
            auto found = std::find_if(config->ponies.begin(), config->ponies.end(),
                                          [&current_behavior](const std::shared_ptr<Pony> &p) {
                                              return p->name.toLower() == current_behavior->follow_object.toLower();
                                          });
            if(found != config->ponies.end()){
                follow_object = (*found)->name;
                // Destanation point = follow object position + x/y_coordinate offset
                current_behavior->state = Behavior::State::Following;
                current_behavior->destanation_point = QPoint((*found)->x_pos + current_behavior->x_coordinate, (*found)->y_pos + current_behavior->y_coordinate);
            }else{
                // If we did not find the targeted pony in active pony list, then set this behavior to normal for the time being
                follow_object = "";
                current_behavior->state = Behavior::State::Normal;
            }
        }

        if(current_behavior->type == Behavior::State::MovingToPoint) {
            current_behavior->destanation_point = QPoint(((float)current_behavior->x_coordinate / 100.0f) * QApplication::desktop()->availableGeometry(this).width(),
                                                        ((float)current_behavior->y_coordinate / 100.0f) * QApplication::desktop()->availableGeometry(this).height());
        }
    }

    int64_t dur_min = std::round(current_behavior->duration_min*1000);
    int64_t dur_max = std::round(current_behavior->duration_max*1000);
    if(dur_min == dur_max) {
        behavior_duration = dur_min;
    }else{
        std::uniform_int_distribution<> dis(dur_min, dur_max);
        behavior_duration = dis(gen);
    }


    if(config->getSetting<bool>("general/debug")) {
            qDebug() << "Pony:"<<name<<"behavior: "<< current_behavior->name <<"for" << behavior_duration << "msec";
    }

    // Update pony position (so it won't jump when we change desktops or something else unexpected happens)
    if(old_behavior != nullptr){
        x_pos = x() + old_behavior->x_center;
        y_pos = y() + old_behavior->y_center;
    }
    behavior_started = QDateTime::currentMSecsSinceEpoch();
    current_behavior->init();

    // Select speech line to display:
    // starting_line for current behavior or random
    // Do not choose random line when following a linked behavior,
    //    instead use the ending_line of the previous behavior if current
    //    behavior does not have a starting line
    // If ending_line is present, use that instead of choosing a new one
    if(speak_lines.size() > 0 && config->getSetting<bool>("speech/enabled")) {
        Speak* current_speech_line = nullptr;

        if(current_behavior->starting_line != ""){
            // If we have a starting_line, use that

            if( speak_lines.find(current_behavior->starting_line) == speak_lines.end()) {
                qWarning() << "Pony:"<<name<<"starting line:"<< current_behavior->starting_line<< "from:"<< current_behavior->name << "not present.";
            }else{
                current_speech_line = speak_lines.at(current_behavior->starting_line).get();
            }            
        }else if(old_behavior != nullptr && old_behavior->ending_line != "" && old_behavior->linked_behavior != current_behavior->name){
            // If we do not have a starting line, and this is a linked behavior, use old behavior's ending line if present
            // old_behavior == nullptr only if we didn't have any previous behaviors (i.e. at startup)

            if( speak_lines.find(old_behavior->ending_line) == speak_lines.end()) {
                qWarning() << "Pony:"<<name<<"ending line:"<< old_behavior->ending_line<< "from:"<< old_behavior->name << "not present.";
            }else{
                current_speech_line = speak_lines.at(old_behavior->ending_line).get();
            }
        }else if(!current_behavior->ending_line.isEmpty() || in_interaction || current_behavior->state == Behavior::State::Following){
            // Don not choose a random line if we have an ending one, or we are in an interaction, or we are following
            return;
        }else if(old_behavior == nullptr || old_behavior->linked_behavior != current_behavior->name) {
            // If we do not have a starting line and this is NOT a linked behavior, then choose one randomly
            // old_behavior == nullptr only if we didn't have any previous behaviors (i.e. at startup)

            std::uniform_real_distribution<> real_dis(0, 100);
            // Speak only with the specified probability
            if((random_speak_lines.size()) > 0 && (real_dis(gen) <= config->getSetting<float>("speech/probability"))) {
                std::uniform_int_distribution<> int_dis(0, random_speak_lines.size()-1);
                current_speech_line = random_speak_lines[int_dis(gen)];
            }
        }

        if(current_speech_line != nullptr) {
            // Show text only if we found a suitable line

            text_label.setText(current_speech_line->text);
            speech_started = behavior_started;
            text_label.adjustSize();
            text_label.move(x_pos-text_label.width()/2, y() - text_label.height());
            text_label.show();
            if(config->getSetting<bool>("sound/enabled")) {
                current_speech_line->play();
            }
        }
    }
}