/* * Perform the Built-in Test * return: Next State */ int bit() { /* Start Counter */ us_timeCount = 0; if (getPower() <= 200U) { /* Change State to EMERGENCY */ return 9U; } else if (getPower() <= 500U) { /* Change State to FAIL */ return 3U; } else { /* Iterate time counter */ us_timeCount++; if (us_timeCount > 5000000U) { /* Change State to READY */ return 4U; /* ReStart Counter */ us_timeCount = 0; } } }
int main(int argc,char **argv){ int width,height; int **pixel; int **out; float **tmp; pixel = readPNG(argv[1],&width,&height); writePNG("res_original.png",pixel,width,height); out = histEQ(pixel,width,height); writePNG("res_Equalized.png",out,width,height); FREE_PIXEL(out); out = getNegative(pixel,width,height); writePNG("res_Negative.png",out,width,height); FREE_PIXEL(out); out = halfIntensity(pixel,width,height); writePNG("res_HalfI.png",out,width,height); FREE_PIXEL(out); out = IRescale(pixel,width,height,min,max,0,100); writePNG("res_scaleto0100.png",out,width,height); FREE_PIXEL(out); out = IRescale(pixel,width,height,min,max,200,255); writePNG("res_scaleto200255.png",out,width,height); FREE_PIXEL(out); tmp = getExp(pixel,width,height,20,1.01); out = Normalize(tmp,width,height); writePNG("res_exp.png",out,width,height); FREE_PIXEL(out); tmp = getLog(pixel,width,height,20.2); out = Normalize(tmp,width,height); writePNG("res_log.png",out,width,height); FREE_PIXEL(out); tmp = getPower(pixel,width,height,1,0.5); out = Normalize(tmp,width,height); writePNG("res_powerg05.png",out,width,height); FREE_PIXEL(out); tmp = getPower(pixel,width,height,1,2); out = Normalize(tmp,width,height); writePNG("res_powerg2.png",out,width,height); FREE_PIXEL(out); tmp = getPower(pixel,width,height,1,2.5); out = Normalize(tmp,width,height); writePNG("res_powerg25.png",out,width,height); FREE_PIXEL(out); //printHist(out,width,height); free(pixel); return 0; }
// Returns the e'th power of X, computing it as needed Ctxt& DynamicCtxtPowers::getPower(long e) { if (v.at(e-1).isEmpty()) { // Not computed yet, compute it now long k = 1L<<(NextPowerOfTwo(e)-1); // largest power of two smaller than e v[e-1] = getPower(e-k); // compute X^e = X^{e-k} * X^k v[e-1].multiplyBy(getPower(k)); v[e-1].modDownToLevel(v[e-1].findBaseLevel()); // mod-switch down to base level } return v[e-1]; }
void holoMove(float x, float y, float rotateX) { // Joystick input must be within {-100 - 100} float leftOriWheel; float rightOriWheel; // Movement leftOriWheel = getMotorPower(getAngle(x, y), LEFT_ORIENTATION_HOLO_WHEEL) * getPower(x, y); rightOriWheel = getMotorPower(getAngle(x, y), RIGHT_ORIENTATION_HOLO_WHEEL) * getPower(x, y); motor[FLWheel] = (int) (((((rightOriWheel/100)*FULL_MOTOR_POWER) + rotateX)/200)*100); motor[FRWheel] = (int) (((((leftOriWheel/100)*FULL_MOTOR_POWER) + -rotateX)/200)*100); motor[BLWheel] = (int) (((((leftOriWheel/100)*FULL_MOTOR_POWER) + rotateX)/200)*100); motor[BRWheel] = (int) (((((rightOriWheel/100)*FULL_MOTOR_POWER) + -rotateX)/200)*100); }
int executeAutomovement(motorGroup *group, int debugStartCol) { switch (group->moving) { case TARGET: if (group->posPID.kP != 0) { int powerLimit = (group->autoStillSpeeding && errorLessThan(group, group->autoSSmargin) ? group->stillSpeed : 127); //limit power if autoStillSpeeding conditions are met group->posPID.integralMax = powerLimit; int PIDpower = PID_runtime(group->posPID, getPosition(group), debugStartCol); setPower(group, copysign(PIDpower, limit(fabs(PIDpower), 0, powerLimit))); } break; case MANEUVER: if (group->forward == (getPosition(group) < group->targetPos)) { group->maneuverTimer = resetTimer(); setPower(group, group->movePower); } else if (time(group->maneuverTimer) > group->maneuverTimeout) { setPower(group, group->endPower); group->moving = NO; } break; case DURATION: if (time(group->maneuverTimer) > group->moveDuration) { setPower(group, group->endPower); group->moving = NO; } else { setPower(group, group->movePower); } break; } return getPower(group); //TODO: be better }
// //////////////////////////////////////////////////////////////////////////// // give Power void giftPower(uint8_t from, uint8_t to, BOOL send) { UDWORD gifval; uint32_t dummy = 0; if (from == ANYPLAYER) { gifval = OILDRUM_POWER; } else { // Give 1/3 of our power away gifval = getPower(from) / 3; usePower(from, gifval); } addPower(to, gifval); if (send) { uint8_t giftType = POWER_GIFT; NETbeginEncode(NET_GIFT, NET_ALL_PLAYERS); NETuint8_t(&giftType); NETuint8_t(&from); NETuint8_t(&to); NETuint32_t(&dummy); NETend(); } else if (to == selectedPlayer) { CONPRINTF(ConsoleString,(ConsoleString,_("%s Gives You %u Power"),getPlayerName(from),gifval)); } }
Word ThRightNormalForm::getShortWord( ) const { Word result; Permutation omega = Permutation::getHalfTwistPermutation( getRank( ) ); int power = getPower( ); if( power<0 ) { const list< Permutation >& decomp = getDecomposition( ); list<Permutation>:: const_iterator it = decomp.begin( ); for( int j=0 ; it!=decomp.end( ) ; ++it, ++j ) { int n = j - decomp.size( ) - power; if( n<0 ) { vector< int > gd = (*it).geodesic(); for( size_t t=0 ; t<gd.size() ; ++t ) result.push_back( gd[t]+1 ); } else { Permutation p = ( n%2 == 1 ? (*it).inverse() * omega : omega * (*it).inverse() ); vector<int> gd = p.geodesic(); for( int t=gd.size( )-1 ; t>=0 ; --t ) result.push_back( -gd[t]-1 ); } } Word omega_w = Word(omega.geodesicWord( )); omega_w = -omega_w; for( int j=decomp.size( ) ; j<-power ; ++j ) result = omega_w*result; } else result = getWord( ); return result; }
mpz_class mm_expression::evaluateNode(mm_expression_node* nd) { //cout << "*** IN EVALUATE : withOUT local vars" << endl; if (nd!=NULL) { if (nd->type == operator_node) { if (!strcmp(nd->argument->value,"+")) return evaluateNode(nd->left) + evaluateNode(nd->right); else if (!strcmp(nd->argument->value,"-")) return evaluateNode(nd->left) - evaluateNode(nd->right); else if (!strcmp(nd->argument->value,"*")) return evaluateNode(nd->left) * evaluateNode(nd->right); else if (!strcmp(nd->argument->value,"/")) return evaluateNode(nd->left) / evaluateNode(nd->right); else if (!strcmp(nd->argument->value,"%")) return evaluateNode(nd->left) % evaluateNode(nd->right); else if (!strcmp(nd->argument->value,"^")) return getPower(evaluateNode(nd->left),evaluateNode(nd->right)); } else { if (nd->argument->type==number) { mpz_class a(nd->argument->value); return a; } else if (nd->argument->type==variable) { mm_variable* var; if (Base->Variables->exists(nd->argument->value)) { var = Base->Variables->getVariable(nd->argument->value); } else if (LocalVariables->exists(nd->argument->value)) { var = LocalVariables->getVariable(nd->argument->value); } else { Base->Error->halt(ERROR_VARIABLE_NOT_FOUND); } mpz_class a(var->value); return a; } else if (nd->argument->type==function) { mm_function* func = Base->Functions->getFunction(nd->argument->func->id); return func->evaluate(nd->argument->func->params); } } } mpz_class nothing = 0; return nothing; }
void CvArea::changePower(PlayerTypes eIndex, int iChange) { FAssertMsg(eIndex >= 0, "eIndex is expected to be >= 0"); FAssertMsg(eIndex < MAX_PLAYERS, "eIndex is expected to be < MAX_PLAYERS"); m_aiPower[eIndex] += iChange; FAssert(getPower(eIndex) >= 0); }
bool Cce122::run(void) { char c = (pCONNECTOR->Get_values()>>1) & 0xFF; if (c>0) { // qWarning()<<"CE122:RECEIVED:"<<QString(c)<<"-"<<(int)c<<"--y="<<top; if (c=='\n') { c=0x0d; // qWarning()<<"CR RECEIVED"; } RefreshCe126(c); pCONNECTOR->Set_values(0); } if (getPower() && printSwitch) { pCONNECTOR->Set_pin(1,true); } else pCONNECTOR->Set_pin(1,false); return true; }
GtkWidget *createResultPopUp ( void ) { GtkWidget *dialog = gtk_dialog_new_with_buttons ("Resultat", (GtkWindow*) app, GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL); //Create labels GtkWidget *vbox = GTK_DIALOG(dialog)->vbox; gchar power[1024]; sprintf(power, "Effekt: %.2f W", getPower()); GtkWidget *lPower = gtk_label_new(power); gtk_container_add(GTK_CONTAINER(vbox), lPower); gchar totRes[1024]; sprintf(totRes, "Ersättningsresistans: %.2f ohm", getResistance()); GtkWidget *lRes = gtk_label_new(totRes); gtk_container_add(GTK_CONTAINER(vbox), lRes); gchar comp[1024]; sprintf(comp, "Ersättningsresistanser i E12-serien kopplade i serie: %s", getComponentStr()); GtkWidget *lComp = gtk_label_new(comp); gtk_container_add(GTK_CONTAINER(vbox), lComp); gtk_widget_show_all( GTK_WIDGET (GTK_DIALOG (dialog)->vbox ) ); return dialog; }
int termPower(bus_t bus) { if (1 == getPower(bus)) return setPower(bus, 0, "Device Termination"); return SRCP_OK; }
// Returns the e'th power, computing it as needed long DynamicPtxtPowers::getPower(long e) { // FIXME: Do we want to allow the vector to grow? If so then begin by // checking e<v.length() and resizing if not. Currently throws an exception. if (v.at(e-1)<0) { // Not computed yet, compute it now long k = 1L<<(NextPowerOfTwo(e)-1); // largest power of two smaller than e v[e-1] = getPower(e-k); // compute X^e = X^{e-k} * X^k v[e-1] = MulMod(v[e-1], getPower(k), p); dpth[e-1] = max(getDepth(k),getDepth(e-k)) +1; nMults++; } return v[e-1]; }
bool CCommand::Open() { // Device is initialized with 9600 bauds ??? conection int retry = 0; bool opened = false; // If device open failed retry three times while ((retry < 3) && (!opened)) { if (m_device->open()) { opened = true; qDebug() << "Connected"; break; } sleep(1); m_device->close(); sleep(1); retry++; } // If not opened cancel qDebug() << "Opened ? " << opened; if (opened == false) return false; // Try to power it on retry = 0; while (retry < 3) { // Try to power it on qDebug() << "setPower();"; setPower(true); // If powered end loop if (getPower()) { qDebug() << "Power on is OK"; qDebug() << "so change baudrate"; sleep(3); qDebug() << "change it on computer side too"; //m_device->setBaudRate("38400"); setBaudRate(CCommand::b38400); getPower(); sleep(10); // Baud rate is now 38400 return true; } sleep(3); retry++; } setPower(false); return false; }
void DYIRDaikin::setMode(uint8_t mode) { uint8_t trmode = vModeTable[mode]; if (mode>=0 && mode <=4) { daikin[13] = (trmode << 4) | getPower(); checksum(); } }
AObjGroup* AObjGroup::splitGroup(){ AObjGroup* group = new AObjGroup(); group->setBeacon(_beacon); while (group->getPower() < getPower()){ group->addUnit(this->getobjs().begin()->second); this->removeUnit(this->getobjs().begin()->second); } return group; }
std::string toString() const { std::ostringstream oss; oss << "ConstantLuminaire[" << std::endl << " name = \"" << m_name << "\"," << std::endl << " intensity = " << m_intensity.toString() << "," << std::endl << " power = " << getPower().toString() << std::endl << "]"; return oss.str(); }
// //////////////////////////////////////////////////////////////////////////// // give Power void giftPower(uint8_t from, uint8_t to, uint32_t amount, bool send) { if (send) { uint8_t giftType = POWER_GIFT; NETbeginEncode(NETgameQueue(selectedPlayer), GAME_GIFT); NETuint8_t(&giftType); NETuint8_t(&from); NETuint8_t(&to); NETuint32_t(&amount); NETend(); } else { int value = 0; if (from == ANYPLAYER && !NetPlay.bComms) { // basically cheating power, so we check that we are not in multiplayer addPower(to, amount); } else if (from == ANYPLAYER && NetPlay.bComms) { debug(LOG_WARNING, "Someone tried to cheat power in multiplayer - ignored!"); } else if (amount == 0) // the GUI option { value = getPower(from) / 3; usePower(from, value); addPower(to, value); } else // for scripts etc that can give precise amounts { value = MIN(getPower(from), amount); usePower(from, value); addPower(to, value); } if (from != ANYPLAYER && to == selectedPlayer) { CONPRINTF(ConsoleString, (ConsoleString, _("%s Gives You %d Power"), getPlayerName(from), value)); } } }
std::string toString() const { std::ostringstream oss; oss << "SkyLuminaire[" << std::endl << " sky sscale = " << m_skyScale << "," << std::endl << " power = " << getPower().toString() << "," << std::endl << " sun pos = theta: " << m_thetaS << ", phi: "<< m_phiS << "," << std::endl << " turbidity = " << m_turbidity << "," << std::endl << "]"; return oss.str(); }
int Character::RangeAttack() { if (getPower() >= 10) { this->_power -= 10; std::cout << getName() << " launches a stone" << std::endl; return (5 + this->_strength); } std::cout << getName() << " out of power" << std::endl; return (0); }
void ShootingWeapon::timerEvent(QTimerEvent *event) { static int proyDistAnt = 999999; int eventID = event->timerId(); if(eventID == timerID){ QPainterPath path; ShootingUnit *su = static_cast<ShootingUnit*>(getAgent()); if(unitToShoot != NULL && su){ Vector2D line(su->pos(), unitToShoot->pos()); line.setModulo(10); incProyectile += int(proyectileVelocity * double(timerInterval)/1000); QPointF startPoint = Vector2D(float(su->getRadius() + incProyectile), float(line.getAngle())).toPointF(); double dist = distanceBetweenPoints(su->mapToScene(startPoint + line.toPointF()), unitToShoot->pos()); // if(dist - proyDistAnt < 0){ if((dist > unitToShoot->getRadius()) && (dist - proyDistAnt < 0)){ path.moveTo(startPoint); path.lineTo(startPoint + line.toPointF()); proyDistAnt = dist; }else{ proyDistAnt = 999999; incProyectile = 0; secureKillTimer(timerID); //Decrementa la vitalidad unitToShoot->decrementHealth(getPower()); // emit enemyHitted(su, unitToShoot); } // }else{ // incProyectile = 0; // killTimer(timerID); // timerID = 0; // emit unitHitted(unitToShoot); // } }else{ secureKillTimer(timerID); } setShape(path); su->update(); } // else if(eventID == timerGarbageCollectorID){ // foreach(void* item, gcItems){ // delete item; // } //// delete gcItems; // killTimer(timerGarbageCollectorID); // timerGarbageCollectorID = 0; // } }
int Character::CloseAttack() { if (getPower() >= 10) { this->_power -= 10; std::cout << getName() << " strikes with a wood stick" << std::endl; return (10 + this->_strength); } std::cout << getName() << " out of power" << std::endl; return (0); }
std::string toString() const { std::ostringstream oss; oss << "CollimatedBeamLuminaire[" << std::endl << " name = \"" << m_name << "\"," << std::endl << " intensity = " << m_intensity.toString() << "," << std::endl << " power = " << getPower().toString() << "," << std::endl << " position = " << m_luminaireToWorld(Point(0, 0, 0)).toString() << "," << std::endl << " direction = " << m_direction.toString() << "," << std::endl << " radius = " << m_radius << std::endl << "]"; return oss.str(); }
std::string Photon::toString() const { std::ostringstream oss; oss << "Photon[" << endl << " pos = " << getPosition().toString() << "," << endl << " power = " << getPower().toString() << "," << endl << " direction = " << getDirection().toString() << "," << endl << " normal = " << getNormal().toString() << "," << endl << " axis = " << getAxis() << "," << endl << " depth = " << getDepth() << endl << "]"; return oss.str(); }
//announceDamage: announce to the player that he had injured void GamePlayer::announceDamage(GameObj* obj,GameManager* mgr) { if ( obj->ClassType() == typeGamePlayer ) { GamePlayer* otherPlayer = (GamePlayer*)obj; if (otherPlayer->getPower() == getPower()) { otherPlayer->HitByPlayer(Same,mgr); HitByPlayer(Same,mgr); } else if (otherPlayer->getPower() < getPower()) { otherPlayer->HitByPlayer(Higher,mgr); HitByPlayer(Lower,mgr); } else { otherPlayer->HitByPlayer(Lower,mgr); HitByPlayer(Higher,mgr); } } else if ( obj->ClassType() == typeGameArrow ) { m_power -= 500; HandleDeath(mgr); } }
void Extractor::update(float frameTime) { if(getActive()) { //i rewrite the building logic because i need to take into account minerals ActorWithHealthBar::update(frameTime); if(anythingNearby&&getPower()) { if(game->getIdlePop() > 0 && getStaff() < getCapacity()) { modifyStaff(1); game->removeIdlePop(1); } } else if(getStaff() > 0) { modifyStaff(-1); game->addIdlePop(1); } if(getPower()) { game->spawnParticleCloud(getCenter(),graphicsNS::GRAY,1); if(anythingNearby) { if(minerals==nullptr||!minerals->getActive()) minerals=game->findMineableMinerals(this); if(minerals==nullptr) anythingNearby = false; else { game->addMinerals(minerals->mine(ExtractorNS::DEFAULT_MINING_RATE*frameTime*getEffectiveness())); game->spawnParticleCloud(getCenter(),graphicsNS::CYAN,1); } } } } }
Permutation ThLeftNormalForm::getTransport( const ThLeftNormalForm& B , const Permutation& u ) const { // we assume that the braid is not a power of \Delta Permutation A1 = * theDecomposition.begin( ); Permutation B1 = *B.theDecomposition.begin( ); if( getPower()%2!=0 ) { A1 = A1.flip( ); B1 = B1.flip( ); } // return A1*u*-B1; return -A1*u*B1; }
void Poly::add(Poly& p) { auto i = this->terms.begin(); auto j = p.terms.begin(); while (i != this->terms.end() && j != p.terms.end()) { if (i->getPower() < j->getPower()) { i++; } else if (i->getPower() == j->getPower()) { i->setCoeff(i->getCoeff() + j->getCoeff()); i++; j++; } else { this->terms.insert(i, *j); j++; } } while (i == this->terms.end() && j != p.terms.end()) { this->terms.push_back(*j); j++; } }
float FloatArray::getVariance(){ float result; /// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a> #ifdef ARM_CORTEX arm_var_f32(data, size, &result); #else float sumOfSquares=getPower(); float sum=0; for(int n=0; n<size; n++){ sum+=data[n]; } result=(sumOfSquares - sum*sum/size) / (size - 1); #endif return result; }
// //////////////////////////////////////////////////////////////////////////// // INFORM others that a building has been completed. BOOL SendBuildFinished(STRUCTURE *psStruct) { uint32_t power = getPower( (uint32_t) psStruct->player); uint8_t player = psStruct->player; ASSERT( player < MAX_PLAYERS, "invalid player %u", player); NETbeginEncode(NET_BUILDFINISHED, NET_ALL_PLAYERS); NETuint32_t(&power); // send how much power we got. NETuint32_t(&psStruct->id); // ID of building // Along with enough info to build it (if needed) NETuint32_t(&psStruct->pStructureType->ref); NETPosition(&psStruct->pos); NETuint8_t(&player); return NETend(); }