Пример #1
0
boolean _Esplora::readJoystickButton() {
 if (readChannel(CH_JOYSTICK_SW) == 1023) {
  return HIGH;
 } else if (readChannel(CH_JOYSTICK_SW) == 0) {
  return LOW;
 }
}
Пример #2
0
std::string hp83711bDevice::execute(int argc, char** argv)
{
	//command structure:  >analogIn readChannel 1
	//returns the value as a string

	if(argc < 3)
		return "Error: Invalid argument list. Expecting 'channel'.";

	int channel;
	bool channelSuccess = stringToValue(argv[2], channel);

	if(channelSuccess && channel >=0 && channel <= 1)
	{
		MixedData data;
		bool success = readChannel(channel, 0, data);

		if(success)
		{
			cerr << "Result to transfer = " << data.getDouble() << endl;
			return valueToString( data.getDouble() );
		}
		else
			return "Error: Failed when attempting to read.";
	}

	return "Error";
}
Пример #3
0
/*!
    Regardless of the current read channel, this function returns all
    data available from the standard error of the process as a
    QByteArray.

    \sa readyReadStandardError(), readAllStandardOutput(), readChannel(), setReadChannel()
*/
QByteArray QProcess::readAllStandardError()
{
    ProcessChannel tmp = readChannel();
    setReadChannel(StandardError);
    QByteArray data = readAll();
    setReadChannel(tmp);
    return data;
}
int AnalogMultiplexerPin::read(const uint8_t _pin_index, const uint8_t noise)
{
    int value = readChannel(_pin_index);
    if (noise == 0 || ((value - _prevValue[_pin_index]) & 0x7FFF) > noise)
    {
        _prevValue[_pin_index] = value;
    }
    return _prevValue[_pin_index];
}
Пример #5
0
int MSAConnection::send(const MSA &v_)
{
  if (isSet(MSProtocolConnection<MSA>::Reset)==MSTrue) return MSFalse;
  if (readChannel()==0) return 0; 
  MSBuffer *b=exportAObject( v_);
  if (b==NULL) return MSFalse; 
  sendTheBuffer(b);
  if (isSet(MSProtocolConnection<MSA>::WritePause)==MSFalse) writeChannel()->enable();
  // attempt to immediately write buffer
  return doWrite(MSFalse);
}
Пример #6
0
bool FlushedProcess::waitForReadyRead(int msecs) {
    if (!isRunning()) {
        process.setErrorString(tr(PROCESS_NOT_STARTED));
        return false;
    }
    EventLoop pause;
    if (msecs >= 0) QTimer::singleShot(msecs,&pause,SLOT(cancel()));
    connect(this,(readChannel() == UnixProcess::StandardError)?
                 SIGNAL(readyReadStandardError()):
                 SIGNAL(readyReadStandardOutput()),&pause,SLOT(quit()));
    return (pause.exec() == 0);
}
Пример #7
0
int MSRawConnection::send(const MSString& aString_)
{
  if (isSet(MSProtocolConnection<MSString>::Reset)==MSTrue) return MSFalse;
  if (readChannel()==0) return MSFalse; 

  MSBuffer *pBuffer=new MSBuffer;
  pBuffer->stuff(aString_.string(),aString_.length());
  sendTheBuffer(pBuffer);
  if (isSet(MSProtocolConnection<MSString>::WritePause)==MSFalse) writeChannel()->enable();
  // attempt to immediately write the buffer
  return doWrite(MSFalse);
}
Пример #8
0
int _Esplora::readTemperature(const byte scale) {
  long rawT = readChannel(CH_TEMPERATURE);
  if (scale == DEGREES_C) {
    return (int)((rawT * 500 / 1024) - 50);
  }
  else if (scale == DEGREES_F) {
    return (int)((rawT * 450 / 512 ) - 58);
  }
  else {
    return readTemperature(DEGREES_C);
  }
}
Пример #9
0
void snet::snetImpl::readNetworkDataFromFile(string filename, iBlob *store)
{
    vector<channel *>  *channelList = readChannel("networkdata");
    vector<junction *> *junctionList = readJunction("junctiondata");
    Path channel = t.createPath("snet.vchannel", store);
    channel.print();

    for(unsigned int i =0; i < channelList->size(); i++)
    {
        if(i%100==0)
            cout<<"Doing channel Number "<<i<<endl;
        string channelIndex = "[" + itoa(i) + "]";
        Path thisChannel = channel + channelIndex;
        Path thisChannelID = thisChannel+"id_attr";
        Path thisChannelName = thisChannel+"name";
        Path thisChannelLength = thisChannel+"length";
        Path thisChannelSegment = thisChannel+"vSegment";
        Path thisChannelJunction = thisChannel + "vJunctionPtr";

        ::channel* chnl = (*(channelList))[i];


        thisChannelID.set(chnl->channelID);
        char name[100];
        strcpy(name, chnl->channelName.c_str());
        thisChannelName.set(name, chnl->channelName.length()+1);
        thisChannelLength.set(chnl->channelLength);

        for(int segIdx = 0; segIdx<chnl->segments->size(); segIdx++)
        {
            string segmentIndex = "[" + itoa(segIdx) + "]";
            Path thisSegment = thisChannelSegment + segmentIndex;
            Path startPt = thisSegment+"startPt";
            Path startPtLat = startPt + "lat";
            Path startPtLong = startPt + "long";

            Path endPt = thisSegment + "endPt";
            Path endPtLat = endPt + "lat";
            Path endPtLong = endPt + "long";

            segment *s = (*(chnl->segments))[segIdx];
            startPtLat.set(s->left.latitude);
            startPtLong.set(s->left.longitude);

            endPtLat.set(s->right.latitude);
            endPtLong.set(s->right.longitude);
        }
    }
    cout<<"No of channels = " <<channel.count()<<endl;
    cout<<"Done inserting ! "<<endl;
}
Пример #10
0
A pString_Connection::syncReadCover(A aTimeout)
{
  struct timeval gameover, *tvp;
  A dataobj;
  ipcWarn(wrnlvl(),"%t pString_Connection::SyncRead\n");

  tvp = atotv(aTimeout, &gameover);
  if(readChannel()==0) return syncErrorResult("nochan","channel is null");

  /* while loop on select() until timeout or complete message received */
  dataobj=syncReadLoop(tvp);
  if (dataobj) return gvi(Et,3,gsym("OK"),dataobj,aplus_nl);
  else return syncErrorResult(errorSymbol, errorMessage);
}
Пример #11
0
int pString_Connection::send(const A &msg_)
{
  ipcWarn(wrnlvl(),"%t pString_Connection::send\n");
  if(isInReset()||readChannel()==0) return -1;
  if(Ct!=msg_->t) return -1;

  MSBuffer *sb=new MSBuffer(msg_->n+sizeof(int));
  if(NULL==sb) return -1;
  int msgLen=htonl((int)msg_->n);
  sb->stuff((char *)(&msgLen),sizeof(int));
  sb->stuff((const char *)msg_->p, msg_->n);
  sendTheBuffer(sb);
  if (MSFalse==isWritePause()) writeChannel()->enable();
  return doWrite(MSFalse);
}
Пример #12
0
boolean _Controlduino::readButton(byte ch){
	switch(ch) {
	case JOYSTICK_RIGHT:
		return joyLowHalf(CH_LeftJoystickX);
	case JOYSTICK_LEFT:
		return joyHighHalf(CH_LeftJoystickX);
	case JOYSTICK_UP:
		return joyLowHalf(CH_LeftJoystickY);
	case JOYSTICK_DOWN:
		return joyHighHalf(CH_LeftJoystickY);
	}

	unsigned int val = readChannel(ch);
	return (val > 512) ? HIGH : LOW;
}
double          QxrdAcquisitionExtraInputsChannel::sumChannel()
{
  QVector<double> res = readChannel();

  double sum=0;

  int i0 = startIndex();
  int i1 = endIndex();

  for(int i=i0; i<i1; i++) {
    sum += res[i];
  }

  return sum;
}
Пример #14
0
Файл: main.c Проект: hem1/EMPR
void stage3()
{
	int data = 0;
	while(1)
	{
		data = 0;
		data = readChannel(1);

		if (data)
		{	
			//serialPrintWithInt("\n\rVoltage: %\n\r", data);
			DAC_output((int)(0x3ff*(data*1.0)/0xfff));
		}
		//delayMS(1000);
	}
}
Пример #15
0
Файл: main.c Проект: hem1/EMPR
void stage1()
{
	while(1)
	{
		int data = 0;
		data = readChannel(1);
		if (data)
		{
		char dataString[20];
		sprintf(dataString, "\n\rVoltage: %lf v\n\r", 3.3*data/4095.0);
		
		serialPrint(dataString);
		//serialPrintWithInt("\n\rVoltage: %\n\r", data);
		break;}
	}
}
Пример #16
0
int pSimple_Connection::send(const A &msg_)
{
  ipcWarn(wrnlvl(),"%t pSimple_Connection::send\n");
  if(isInReset()||readChannel()==0) return -1;
  if(Et<=msg_->t) return -1;

  long len=AH+Tt(msg_->t,msg_->n)+((Ct==msg_->t)?1:0);
  MSBuffer *sb=new MSBuffer(len+sizeof(long));
  if(NULL==sb) return -1;
  long msgLen=htonl(len);
  sb->stuff((char *)(&msgLen),sizeof(long));
  sb->stuff((const char *)msg_, len);
  sendTheBuffer(sb);
  if (MSFalse==isWritePause()) writeChannel()->enable();
  return doWrite(MSFalse);
}
double          QxrdAcquisitionExtraInputsChannel::averageChannel()
{
  QVector<double> res = readChannel();

  double n=0;
  double sum=0;

  int i0 = startIndex();
  int i1 = endIndex();

  for(int i=i0; i<i1; i++) {
    sum += res[i];
    n   += 1;
  }

  return (n>0 ? sum/n : 0);
}
Пример #18
0
boolean _Esplora::readButton(byte ch) {
  if (ch >= SWITCH_1 && ch <= SWITCH_4) {
    ch--;
  }
  
  switch(ch) {
  case JOYSTICK_RIGHT:
    return joyLowHalf(CH_JOYSTICK_X);
  case JOYSTICK_LEFT:
    return joyHighHalf(CH_JOYSTICK_X);
  case JOYSTICK_UP:
    return joyLowHalf(CH_JOYSTICK_Y);
  case JOYSTICK_DOWN:
    return joyHighHalf(CH_JOYSTICK_Y);
  }
    
  unsigned int val = readChannel(ch);
  return (val > 512) ? HIGH : LOW;
}
Пример #19
0
WP::err Mailbox::readMailDatabase()
{
    fThreadList.clear();

    QStringList messageChannels = getChannelUids();
    foreach (const QString & channelPath, messageChannels) {
        MessageChannel* channel = readChannel(channelPath);
        if (channel == NULL) {
            delete channel;
            continue;
        }
        MessageThread *thread = new MessageThread(channel);
        fThreadList.addChannel(thread);
        WP::err error = readThreadContent(channelPath, thread);
        if (error != WP::kOk) {
            fThreadList.removeChannel(thread);
            delete thread;
        }

    }
bool QxrdAcquisitionExtraInputsChannel::evalTrig(int polarity, bool edgeTrig)
{
  double level = get_TriggerLevel();
  double hyst  = get_TriggerHysteresis();
  bool tres;

  QVector<double> res = readChannel();

  int nlow=0, nhigh=0;
  double tlevel = level*polarity;
  double lowlevel = tlevel-fabs(hyst);
  double highlevel = tlevel+fabs(hyst);

  int i0 = startIndex();
  int i1 = endIndex();

  for(int i=i0; i<i1; i++) {
    double v=res[i]*polarity;

    if (v < lowlevel)  nlow  += 1;

    if (edgeTrig) {
      if (nlow && (v > highlevel)) nhigh += 1;
    } else {
      if (v > highlevel) nhigh += 1;
    }
  }

  set_NLow(nlow);
  set_NHigh(nhigh);

  if (edgeTrig) {
    tres = ((nlow > 0) && (nhigh > 0));
  } else {
    tres = (nhigh > 0);
  }

  return tres;
}
double          QxrdAcquisitionExtraInputsChannel::minimumChannel()
{
  QVector<double> res = readChannel();

  double min=0;

  int i0 = startIndex();
  int i1 = endIndex();

  for(int i=i0; i<i1; i++) {
    double v=res[i];

    if (i == i0) {
      min = v;
    } else {
      if (v < min) {
        min = v;
      }
    }
  }

  return min;
}
Пример #22
0
bool geometryCacheFile::readChannelGroup( MStatus& groupStatus )
///////////////////////////////////////////////////////////////////////////////
//
// Description : ( private method )
//		Read the channel group MYCH.
//		The channel group can consist of these following tags
//
//		MYCH	( time group )
//		TIME	( time in ticks )
//		CHNM	( channel name )
//		SIZE 	( size )
//		DVCA	( geometry point data )
//
///////////////////////////////////////////////////////////////////////////////
{
	MIffTag mychTag;
	MIffTag tmpTag;
	unsigned int byteCount;

	groupStatus = iffFilePtr->beginReadGroup(tmpTag, mychTag);
	if( groupStatus == MS::kSuccess ) {
		if( mychTag == MIffTag('M', 'Y', 'C', 'H')) {
			// Store the "MYCH" group in the blockList
			//
			storeCacheBlock( "MYCH" );

			// Get the next tag
			//
			MStatus stat = iffFilePtr->beginGet(tmpTag, (unsigned *)&byteCount);
			if (!stat) return false;

			// If the tag is TIME, then this is a single file cache file
			// Read the time chunk before the channel name chunk
			//
			if( tmpTag == MIffTag('T', 'I', 'M', 'E') )
			{
				// Read channel time
				//
				readStatus = readChannelTime();
				if ( !readStatus ) return false;

				// End Get
				//
				stat = iffFilePtr->endGet();
				if (!stat) return false;
			}

			// Read Channel
			//
			MStatus channelStatus = MS::kSuccess;
			do {
				// Read channel name, size and data
				//
				readStatus = readChannel( channelStatus );
				if( !readStatus ) return false;

			} while ( channelStatus == MS::kSuccess );

			// Store the ending "/MYCH" in the blockList
			//
			storeCacheBlock( "/MYCH" );
		}
	} 
	iffFilePtr->endReadGroup();
	return readStatus;
}
Пример #23
0
boolean _Esplora::joyHighHalf(byte joyCh) {
  return (readChannel(joyCh) > 512 + JOYSTICK_DEAD_ZONE)
    ? LOW : HIGH;
}
Пример #24
0
boolean _Esplora::joyLowHalf(byte joyCh) {
  return (readChannel(joyCh) < 512 - JOYSTICK_DEAD_ZONE)
    ? LOW : HIGH;
}
Пример #25
0
A pString_Connection::syncReadLoop(struct timeval *pgameover)
{
  A result=(A)0, dataobj;
  int rc;
  struct timeval timeleft, *tvp;
  
  ipcWarn(wrnlvl(), "%t pString_Connection::syncReadLoop\n");
  /* make arguments for select() */
  Syncfds.fdszero(Syncfds.r());
  Syncfds.fdszero(Syncfds.ra());
  LOCALCHANENBL(Syncfds.r(),readChannel());
  
  if (pgameover != (struct timeval *)0) 
  {
    tvp=&timeleft;
    tvdiff(pgameover,tod(),tvp);
    if (0>tvp->tv_sec) tvp->tv_sec=tvp->tv_usec=0;
  } else tvp=NULL;
  
  for(;;) 
  {
    Syncfds.fdscopy(Syncfds.r(),Syncfds.ra());

    if (((rc = select(Syncfds.size(), Syncfds.ra(), NULL, NULL, tvp)) < 0)) 
    {
      if (EINTR==errno)
	syncFillError("interrupt","select() received an interrupt");
      else
	syncFillError("select", 
		      "select() returned error code %d.  errno=%d",
		      rc, errno);
      break;
    }
    
    if (rc) 
    {
      if (Syncfds.fdsisset(Syncfds.ra(), fd()))
      {
	rc=syncDoRead(&dataobj);
	if (0<rc) result=dataobj;
	if (rc) break;
      }
      else {
	syncFillError("fdsisset","unexpected event broke select()");
	break;
      }
    }
    
    /* check for timeout and reset timeleft */
    if (NULL != tvp) 
    {
      tvdiff(pgameover,tod(),tvp);
      if (0>tvp->tv_sec) tvp->tv_sec=tvp->tv_usec=0;
      if (0==tvp->tv_sec && 0==tvp->tv_usec) 
      {
	syncFillError("timeout","Syncread loop timed out");
	break;
      }
    }
    
  } /* end for(;;) loop */
  
  return result;
}  
Пример #26
0
boolean _Controlduino::joyLowHalf(byte joyCh) {
  return (readChannel(joyCh) < 512 - JOYSTICK_DEAD_ZONE)
    ? LOW : HIGH;
}
Пример #27
0
boolean _Controlduino::joyHighHalf(byte joyCh) {
  return (readChannel(joyCh) > 512 + JOYSTICK_DEAD_ZONE)
    ? LOW : HIGH;
}
void AnalogMultiplexerPin::setInitialValue(uint8_t _pin_index)
{
    _prevValue[_pin_index] = readChannel(_pin_index);
}
Пример #29
0
QIODevice * FlushedProcess::readingIODevice() const {
    FlushedProcess * p_this = (FlushedProcess *)this;
    return (readChannel() == UnixProcess::StandardError)?p_this->err_socket:p_this->out_socket;
}