Exemplo n.º 1
0
void polyEditable::keyPressed(ofKeyEventArgs& event)
{
	if( !bEnabled || !bUseKeyPress ) return;
	
	if( event.key == ' ')	nextMode();
		
	// Note:; may not work cross-platform, tab through points
	if(event.key == 9 )
	{
		if(  mode == POLY_EDIT_MODE_MOVE_PTS )
		{
			selectedPoint++;
			selectedPoint %= (int)(pts.size());
		} 
			
	}
	
	cout << "key " << event.key << " " << OF_KEY_BACKSPACE << endl;
	if( event.key == OF_KEY_BACKSPACE ) removePoint();

	
	if( event.key == OF_KEY_UP )
	{
		ofxVec2f mup = ofxVec2f(0,-moveBy);
		mup.rotate(-gRotation);
		if( mode == POLY_EDIT_MODE_MOVE_ALL )		moveAllPointsBy( ofPoint(mup.x,mup.y) );//ofPoint(0,-1) );
		else if( mode == POLY_EDIT_MODE_MOVE_PTS )	movePointBy( selectedPoint, ofPoint(mup.x,mup.y) );//ofPoint(0,-1) );
	}
	else if( event.key == OF_KEY_DOWN)
	{
		ofxVec2f mdwn = ofxVec2f(0,moveBy);
		mdwn.rotate(-gRotation);
		if( mode == POLY_EDIT_MODE_MOVE_ALL )		moveAllPointsBy( ofPoint(mdwn.x,mdwn.y) );
		else if( mode == POLY_EDIT_MODE_MOVE_PTS )	movePointBy( selectedPoint, ofPoint(mdwn.x,mdwn.y) );

	}
	else if( event.key == OF_KEY_LEFT )
	{
		ofxVec2f m = ofxVec2f(-moveBy,0);
		m.rotate(-gRotation);
		
		if( mode == POLY_EDIT_MODE_MOVE_ALL )		moveAllPointsBy( ofPoint(m.x,m.y) );
		else if( mode == POLY_EDIT_MODE_MOVE_PTS )	movePointBy( selectedPoint, ofPoint(m.x,m.y) );
		else if( mode == POLY_EDIT_MODE_ROTATE )	rotate(-.5);

	}
	else if( event.key == OF_KEY_RIGHT )
	{
		ofxVec2f m = ofxVec2f(moveBy,0);
		m.rotate(-gRotation);
		if( mode == POLY_EDIT_MODE_MOVE_ALL )		moveAllPointsBy( ofPoint(m.x,m.y) );
		else if( mode == POLY_EDIT_MODE_MOVE_PTS )	movePointBy( selectedPoint, ofPoint(m.x,m.y));
		else if( mode == POLY_EDIT_MODE_ROTATE )	rotate(.5);

	}
}
Exemplo n.º 2
0
/* the following function exists to remedy the fact that |look_up| does not
   record the path to the match it has found (supposing it did); its calling
   interface is already compicated as it is. So we ask our children which one
   knows the mode that was returned. The interrogation is repeated recursively
   down, but in practice very few modes exist at all, and this is very quick.
 */
bool CommandTree::has_descendant (const CommandTree* mode) const
{
  if (mode==this)
    return true; // that was easy
  for (unsigned int i=0; i<n_desc(); ++i)
    if (nextMode(i).has_descendant(mode))
      return true;

  return false;
}
Exemplo n.º 3
0
/*
  add to |e| the set of command names in mode and its descendants,
  that begin with |name|.
*/
void CommandTree::extensions(std::set<const char*,StrCmp>& e,
			     const char* name) const
{
  for (const_iterator it = find_prefix(name); it != end(); ++it)
    if (isInitial(name,it->first))
      e.insert(it->first);
    else
      break; // any element not starting with |name| ends search

  for (size_t j = 0; j < n_desc(); ++j)
  {
    const CommandTree& mode = nextMode(j);
    mode.extensions(e,name);
  }
}
Exemplo n.º 4
0
CommandNode::const_iterator CommandTree::look_up
 (const char* name, CheckResult& status, CommandTree const* & where) const
{
  CommandNode::const_iterator result; // might remain undefined
  CommandNode::const_iterator it = find_prefix(name); // in our |mode| only
  if (it != end() and isInitial(name,it->first)) // anything found here?
  {
    if (isEqual(name,it->first)) // got exact match here
      return status=Found, where=this, it;

    // record partial match, then scan ahead for any further partial matches
    if (status!=NotFound) // we found a partial match, and had at least one
      status = Ambiguous;
    else
    {
      status=PartialMatch; where=this; result=it;
      if (++it != end() and isInitial(name,it->first))
	status = Ambiguous;
    }
  }

  bool not_found_before = status==NotFound;
  // now look in descendant modes; if any has exact match, return that
  for (unsigned int i=0; i<n_desc(); ++i)
  {
    it = nextMode(i).look_up(name,status,where);
    if (status==Found) // found exact match, |where| has been set
      return it; // |where| has been set by recursive |lookup|
    if (not_found_before and status!=NotFound) // got a first partial match
    {
      not_found_before = false; // only one can be the first
      result=it; // export result from first successful recursive |look_up|
    }
  }

  // now |status| can be anything except |Found|
  return result; // value should not be used if |status==NotFound|
}
Exemplo n.º 5
0
void SamplerSMARTS::queue(uint32_t insn, uint64_t pc, uint64_t addr, FlowID fid, char op, uint64_t icount, void *env)
  /* main qemu/gpu/tracer/... entry point {{{1 */
{

  I(fid < emul->getNumEmuls());
  if(likely(!execute(fid, icount)))
    return; // QEMU can still send a few additional instructions (emul should stop soon)
  I(mode!=EmuInit);

  I(insn);

  // process the current sample mode
  if (getNextSwitch()>totalnInst) {

    if (mode == EmuRabbit || mode == EmuInit)
      return;

    if (mode == EmuDetail || mode == EmuTiming) {
      emul->queueInstruction(insn,pc,addr, (op&0xc0) /* thumb */ ,fid, env, getStatsFlag());
      return;
    }

    I(mode == EmuWarmup);
		doWarmupOpAddr(op, addr);
    return;
  }


  // Look for the new mode
  I(getNextSwitch() <= totalnInst);

 // I(mode != next_mode);
  pthread_mutex_lock (&mode_lock);
  //

  if (getNextSwitch() > totalnInst){//another thread just changed the mode
    pthread_mutex_unlock (&mode_lock);
    return;
  }

  lastMode = mode;
  nextMode(ROTATE, fid);
  if (lastMode == EmuTiming) { // timing is going to be over
    if (getTime()>=maxnsTime || totalnInst>=nInstMax) {
      markDone();
      pthread_mutex_unlock (&mode_lock);
      return;
    }
    if (doPower) {
      uint64_t mytime = getTime();
      int64_t ti = mytime - lastTime;
      I(ti > 0);
      ti = (static_cast<int64_t>(freq)*ti)/1e9;

      BootLoader::getPowerModelPtr()->setSamplingRatio(getSamplingRatio()); 
      BootLoader::getPowerModelPtr()->calcStats(ti, !(lastMode == EmuTiming), fid); 
      lastTime = mytime;
      updateCPI(fid); 
      if (doTherm) {
        BootLoader::getPowerModelPtr()->updateSescTherm(ti);  
      }
    }
  }
  pthread_mutex_unlock (&mode_lock);

}
Exemplo n.º 6
0
  void SetTimeMenu::configureTime() {
    Serial.println(F("Entering configureTime()..."));
    nextMode();
    tmElements_t tm;
#if TEENSYDUINO
    breakTime(now(), tm);
#else
    if (!RTC.read(tm)) {
      app->debug(0, "Can't ¨read current time", true);
      delay(3000);
      return;
    }
#endif
    switch (app->mode) {
      case SetTime::Hour:
        blinkColor(ColorNames::red);
        app->debug(0, "====== Setup =======", true);
        instructions();
        what = (char *) "Hours";
        h = tm.Hour;
        if (h == 0) {
          h = 24;
        }
        selectNumber(&h, 1, 24);
        if (app->mode == SetTime::Default) break;
        /* no break */

      case SetTime::Minute:
        blinkColor(ColorNames::yellow);
        what = (char *) "Minutes";
        m = tm.Minute;
        selectNumber(&m, 0, 59);
        if (app->mode == SetTime::Default) break;
        /* no break */

      case SetTime::Save:
        blinkColor(ColorNames::red);
        if (h == 24) {
          h = 0;
        }
        tm.Hour = h;
        tm.Minute = m;
        tm.Second = 0;
        sprintf(buffer, "New Time: %2d:%02d", h, m);
        Serial.print("Setting Time to: ");
        Serial.println(buffer);
  #if DEBUG
        app->debug(0, "Saving New Time...", true);
        app->debug(1, buffer, false);
        app->debug(3, "Success! :)", false);
  #endif
        app->helper.setTimeTo(tm, 0);
        nextMode();
        /* no break */

      case SetTime::Last:
        app->mode = SetTime::Default;
        /* no break */
      case SetTime::Default:
        return;
    };
  }
Exemplo n.º 7
0
void SamplerPeriodic::syncTimeAndFinishWaitingForOthers(FlowID fid) {
      nextMode(SET_MODE, fid, next2EmuTiming);
}
Exemplo n.º 8
0
void SamplerPeriodic::syncTimeAndContinue(FlowID fid) {
      nextMode(ROTATE, fid);
      updateCPI();
}
Exemplo n.º 9
0
void SamplerPeriodic::syncTimeAndWaitForOthers(FlowID fid) {
      nextMode(SET_MODE, fid, EmuDetail);
      updateCPI();
      dsync->inc();
}
Exemplo n.º 10
0
uint64_t SamplerSMARTS::queue(uint64_t pc, uint64_t addr, FlowID fid, char op, int src1, int src2, int dest, int dest2)
  /* main qemu/gpu/tracer/... entry point {{{1 */
{
  I(fid < emul->getNumEmuls());
  if(likely(!execute(fid, 1)))
    return 0; // QEMU can still send a few additional instructions (emul should stop soon)
  I(mode!=EmuInit);

  // process the current sample mode
  if (getNextSwitch()>totalnInst) {

    if (mode == EmuRabbit || mode == EmuInit) {
      uint64_t rabbitInst = getNextSwitch() - totalnInst;
      execute(fid,rabbitInst);
      // Qemu is not going to return untill it has executed these many instructions
      // Or untill it hits a syscall that causes it to exit
      // Untill then, you are on your own. Sit back and relax!
      return rabbitInst; 
    }

    if (mode == EmuDetail || mode == EmuTiming) {
      emul->queueInstruction(pc,addr, fid, op, src1, src2, dest, dest2, getStatsFlag());
      return 0;
    }

    I(mode == EmuWarmup);
#if 1
    if ( op == iLALU_LD || op == iSALU_ST)
      // cache warmup fake inst, do not need SRC deps (faster)
      emul->queueInstruction(0,addr, fid, op, LREG_R0, LREG_R0, LREG_InvalidOutput, LREG_InvalidOutput, false);
#else
		//doWarmupOpAddr(static_cast<InstOpcode>(op), addr);
#endif
    return 0;
  }

  // Look for the new mode
  I(getNextSwitch() <= totalnInst);

 // I(mode != next_mode);
  pthread_mutex_lock (&mode_lock);
  //

  if (getNextSwitch() > totalnInst){//another thread just changed the mode
    pthread_mutex_unlock (&mode_lock);
    return 0;
  }

  lastMode = mode;
  nextMode(ROTATE, fid);
  if (lastMode == EmuTiming) { // timing is going to be over

#if 0
		static double last_timing         = 0;
		static long long last_globalClock = 0;

		MSG("%f %lld"
				,iusage[EmuTiming]->getDouble()
				,globalClock-last_globalClock);

		last_timing      = iusage[EmuTiming]->getDouble();
		last_globalClock = globalClock;
#endif

    BootLoader::reportSample();
    
    if (getTime()>=maxnsTime || totalnInst>=nInstMax) {
      markDone();
      pthread_mutex_unlock (&mode_lock);
      return 0;
    }
    if (doPower) {
      uint64_t mytime = getTime();
      int64_t ti = mytime - lastTime;
      I(ti > 0);
      ti = (static_cast<int64_t>(freq)*ti)/1e9;

      BootLoader::getPowerModelPtr()->setSamplingRatio(getSamplingRatio()); 
      BootLoader::getPowerModelPtr()->calcStats(ti, !(lastMode == EmuTiming), fid); 
      lastTime = mytime;
      updateCPI(fid); 
      if (doTherm) {
        BootLoader::getPowerModelPtr()->updateSescTherm(ti);  
      }
    }
  }
  pthread_mutex_unlock (&mode_lock);

  return 0;
}