示例#1
0
int main(int argc, char *argv[])
{   
  initializeSegments();
  int i;
  int j;
  for (j=0; j<4; j++)
    {
      for (i=0;i<10;i++)
	{
	  displayNumber(i);
	  printf("displayed %d\n", i);
	  fflush(stdout);
	  Sleep(500);
	}
    }
    RemoveWinIoDriver();
    return 0;
}
示例#2
0
void ChumbyVirtualKeyboard::buttonC1Function ( void )
{
	if ( buttonC3->text() == QString ( "ABC" ) ) {
		if ( buttonC1->text() == QString ( "#+=" ) ) {
			buttonC1->setText ( QString ( "123" ) );
			buttonC1->setCheckable ( false );
			displaySpecialChar();
		} else {
			buttonC1->setText ( QString ( "#+=" ) );
			buttonC1->setIcon ( QIcon ( "" ) );
			buttonC1->setCheckable ( false );
			displayNumber();
		}

	} else {
		displayAlphabet();
	}

	return;
}
示例#3
0
void Nixie_i2c::slotMachineDisplayNumber(int newNumber) {

  bool orig_lhdp = _lhdpState;
  bool orig_rhdp = _rhdpState;

  int num = _currentNumber;
  for (int numPasses = 10 + newNumber - num; numPasses >0; --numPasses)  {
 	if (num == 9) num = 0; else num++;

 	//toggle the lhdp/rhdp cathodes as we go round.
 	_lhdpState = !_lhdpState;
    	_rhdpState = !_rhdpState;
	if (numPasses == 1) {
		//Put the decimal point statuses back to the correct ones!
		_lhdpState = orig_lhdp;
		_rhdpState = orig_rhdp;
	}
	displayNumber(num);
	delay(50);
  }
}
示例#4
0
int FcitxQtConnectionPrivate::displayNumber() {
    if (m_displayNumber < 0) {
        QByteArray displayNumber("0");
        QByteArray display(qgetenv("DISPLAY"));
        int pos = display.indexOf(':');
        ++pos;
        int pos2 = display.indexOf('.', pos);
        if (pos2 > 0)
            displayNumber = display.mid(pos, pos2 - pos);

        bool ok;
        int d = displayNumber.toInt(&ok);
        if (ok) {
            m_displayNumber = d;
        } else {
            m_displayNumber = 0;
        }
    }

    return m_displayNumber;
}
示例#5
0
const QString& FcitxQtConnectionPrivate::socketFile()
{
    if (!m_socketFile.isEmpty())
        return m_socketFile;

    char* addressFile = NULL;

    asprintf(&addressFile, "%s-%d", localMachineId().data(), displayNumber());

    char* file = NULL;

    FcitxXDGGetFileUserWithPrefix("dbus", addressFile, NULL, &file);

    QString path = QString::fromUtf8(file);
    free(file);
    free(addressFile);

    m_socketFile = path;

    return m_socketFile;
}
示例#6
0
/*
 * Displays a number on the seven segment display
 */
void displayNumber(double val){
	//get integer part
	uint8_t asInteger = (int) val;
	//where would the comma be
	uint8_t digitsBeforePoint = digitCount(asInteger);
	//f**k it, the comma would be useless anyway
	if(digitsBeforePoint >= 3)
		displayNumber(asInteger);
	else{
		//create all zero data array
		unsigned char data[3] = {0, 0, 0};
		//load digits
		if(digitsBeforePoint == 2){
			data[0] = NUMBERS_7SD[getDigit(val, 1)];
			data[1] = NUMBERS_7SD[getDigit(val, 0)] + 1;
			data[2] = NUMBERS_7SD[getDigit(val, -1)];
		}
		else if(digitsBeforePoint == 1){
			data[0] = NUMBERS_7SD[getDigit(val, 0)] + 1;
			data[1] = NUMBERS_7SD[getDigit(val, -1)];
			data[2] = NUMBERS_7SD[getDigit(val, -2)];
		}
		else {
			data[0] = NUMBERS_7SD[getDigit(val, -1)] + 1;
			data[1] = NUMBERS_7SD[getDigit(val, -2)] + 1;
			data[2] = NUMBERS_7SD[getDigit(val, -3)] + 1;
		}
		//display comma
		if(digitsBeforePoint > 0)
			data[digitsBeforePoint - 1] |= 1;
		else{
			//make all have commas to show that have 0.xyz
			for(int i = 0; i < 3; i++)
				data[i] |= 1;
		}
		//send
		send7SDTransmission(data);
	}
}
void joyCallback(const sensor_msgs::Joy::ConstPtr& msg){

	bool bState = msg->buttons[3] == 1;

	if (bState != listenState) {

		if (bState) {
			
			listenState = bState;

			++currentTopic;
			if (currentTopic >= topics.size()) currentTopic = 0;

			topic_tools::MuxSelect m;
			m.request.topic = topics[currentTopic];
			ros::service::call("/mux/select", m);
			displayNumber(currentTopic);
			printf("Switching mux to topic #%d: %s\n", currentTopic, topics[currentTopic].c_str());

		} else listenState = false;	

	}
	
}
示例#8
0
/**
 * void displayTime(void)
 * 简介:显示时间
 * 功能:发送时间显示数据到 HV57708,时间在全局变量中储存
 * 输入:无
 * 输出:无
 */
void displayTime(void)
{
	displayNumber(hour * 10000ul + minute * 100ul + second);
}
示例#9
0
int
main(void){
  token =0;
  lower_range =0;

  ioinit();
  timer_init();


  /* all devices initialize themselves as slaves */
  USI_TWI_Slave_Initialise(TWI_BROADCAST_ADDRESS);

  /* loop forever */
  for (;; ) {
    /* Block interrupts while we're probing the value of
     * buttonPressed--the interrupt handler may change this value
     * asynchronously */

    /* _delay_ms(15); */

    if (buttonPressed) {
  
      /* now that we've determined that there has been a button
       * press event, we can re-enable interrupts and proceed to
       * act upon it. */

      buttonPressed = false;
      sei();

      if(mode2){
	upper_range++;

	if(upper_range > 99 && token > 99 && lower_range > 99){
	  upper_range = upper_range - 100;
	  token = lower_range = 0;

	} /* end of if mode2 */
      }	  /* end of if button pressed */

      sendUpdateUpperRange(upper_range);
      sendUpdateUpperRange(lower_range); /* Even though we don't have
					    to send both lets do this
					    every where in order to
					    ensure the same number
					    every where... */

      displayNumber(upper_range);
      lastToken = upper_range;

      /* _delay_ms(5000); */

      /* displayNumber((upper_range - token) *  */
      /* 		    average_time_per_token);  */
      /* We must point out to the users of this system that this is just to
	 give them an idea of how many people are waiting and how long it
	 could take (we should make it very clear that our internal clock is
	 not accurate and that this is an average). This would display the
	 time in big_ticks that this person will have to wait. What I would
	 like to do later on is make sure that the big ticks is time in
	 minutes by changing it's value from 1000 to something else
	 depending on the clock speed of the microcontroller, (this is what
	 we need to consult Rohit for).... */

    }else{

      lastToken = token;
      /* number_of_members_since_the_beginning++; */
      lower_range++;
      token = lower_range;	/* This is the same as before, just
				   clearer */

    
      /* If you are questioning this, think of what would happen
	 when we just set them to zero individually when they reach
	 100... */
      if(upper_range < 99 && token < 99 && lower_range < 99){
	upper_range = upper_range - 100;
	token = lower_range = 0;

	sendUpdateUpperRange(upper_range);
	sendUpdateUpperRange(lower_range); /* Even though we don't have
					      to send both lets do this
					      every where in order to
					      ensure the same number
					      every where... */

      }	/* end of if reach 100  */


      /* if (SearchForOthers() || RThereOthers) { */
      sendUpdate(token); /* Also update every other
			  * module on the bus*/

      displayNumber(token); /* update the display */

    } /* end of mode2/mode1 */
  }   /* end of button Press if */

  if (USI_TWI_Data_In_Receive_Buffer()) { 
    /* have we received anything over TWI? */

    uint8_t command = USI_TWI_Receive_Byte();
    switch (command) {
    case CUR_NUM_CMD:
      lower_range = USI_TWI_Receive_Byte();
      if (!mode && !mode2) {
	displayNumber(lower_range);
	lastToken = lower_range;
      }
      break;
    case UPPER_RANGE_CMD:
      upper_range = USI_TWI_Receive_Byte();
      break;
    default:
      /* Unexpected communication. consume everything we've
       * received */
      while (USI_TWI_Data_In_Receive_Buffer()) {
	USI_TWI_Receive_Byte();
      }
      break;
    } /* end of recieve */
  } /* end of endless loop */

  /* we will never come here. */
  return (0);
} /* end of main */
示例#10
0
const QString& FcitxQtConnectionPrivate::socketFile()
{
    if (!m_socketFile.isEmpty())
        return m_socketFile;

    QString filename = QString("%1-%2").arg(QString::fromLatin1(QDBusConnection::localMachineId())).arg(displayNumber());

    QString home = QString::fromLocal8Bit(qgetenv("XDG_CONFIG_HOME"));
    if (home.isEmpty()) {
        home = QDir::homePath().append(QLatin1Literal("/.config"));
    }
    m_socketFile = QString("%1/fcitx/dbus/%2").arg(home).arg(filename);

    return m_socketFile;
}
示例#11
0
int main(int argc, char** argv)
{
	cout << endl << "Welcome to BigNum! Enter \"help\" for assistance." << endl << endl;

    settings user(10, false, false);
	bool commline=false;

	if (argc>1)
		commline=true;

	string entered;
    PTYPE problemType = ERROR;
    bool exit = false;
    bigNumber previous;
    previous.updateDigits();
    
    while (exit == false)
    {     
    	if (commline==false)
		{
			entered.clear();

            if (previous.getBase() != user.getBase())
                previous.convertBase(user.getBase());

			cout << "\n";
            displayNumber(previous, user, false, true);
			cout << "\n\n";

			std::getline(cin, entered);
            
			cout << "-----------------------" << endl;

			if (changeBase(entered, user))
			{
				continue;
			}
			
			if (entered == "clear" || entered == "reset")
			{
			    bigNumber reset(0);
			    reset.setBase(user.getBase());
			    previous = reset;
				continue;
			}

			if (entered == "settings" || entered == "options" || entered == "preferences")
            {
                modifySettings(user);
                continue;
            }
			
			if (entered == "show stats")
			{
			    cout << "\nNumber stats are visible\n\n";
			    user.showDigitsOn();
				continue;
			}
			
			if (entered == "hide stats")
			{
			    cout << "\nNumber stats are hidden\n\n";
			    user.showDigitsOff();
				continue;
			}

			if (entered == "help")
			{
				printHelp();
				continue;
			}
		}

		else 
		{
			entered.clear();
			for (int i=1; i<argc; i++)
			{
				entered += argv[i];
			}
			commline=false;
		}
        
        if (entered != "exit" && entered != "EXIT" && entered != "Exit")
        {
            solution answer(solve(entered, previous, user));
      
            if (answer.getError()>0)
            {
                cout << endl << "Invalid Input (Error " << answer.getError() << ")";
            }
            
            else 
            {
                previous = answer.getSolved();
            }
        }
        
        else exit = true;
        
        cout << endl;
    }
}
示例#12
0
solution solve(string &c, bigNumber previous, settings &user)
{
    c += '$';
    PTYPE pType=ERROR;
    
    vector<int> first;
    vector<int> second;
    bigNumber bn1;
    bigNumber bn2;
    bigNumber temp;
    
    bn1.setBase(user.getBase());
    bn2.setBase(user.getBase());
    temp.setBase(user.getBase());

    int decimalCount1=0;
    int decimalCount2=0;
    int commaNumbers=0;
    int numbers=0;

    bool decimal=false;
	bool comma=false;
	bool negative1=false;
	bool negative2=false;
    bool done=false;
	bool printExact=false;
	bool printStats=false;

    bigNumber* targetBN = &bn1;
    vector<int>* targetVec = &first;
    int* targetDec = &decimalCount1;
	bool* targetNegative = &negative1;
    
    int counter = c.size();
    
    for (int i=0; i<counter; i++)
    {
        if (checkWord(c, i, "pi"))
        {
            if (numbers>0 || comma==true || decimal==true)
            {
                RETURN_ERROR;
            }
            
            else
            {
                string piString(PI);
		
				for (int piMarker=PRECISION; piMarker>=0; piMarker--)
				{
					char piChar = '0';
					int piNum = piString[PRECISION-piMarker] - piChar;
				
					(*targetVec).push_back(piNum);
				}
                
                done=true;
				*targetDec = PRECISION;
                
                numbers += (PRECISION+1);
                counter += 2;
                i += 2;
            }
        }
        
        if (checkWord(c, i, "theta"))
        {
            if (numbers>0 || comma==true || decimal==true)
            {
                RETURN_ERROR;
            }
            
            else
            {
                string thetaString(THETA);
		
				for (int thetaMarker=PRECISION; thetaMarker>=0; thetaMarker--)
				{
					char thetaChar = '0';
					int thetaNum = thetaString[PRECISION-thetaMarker] - thetaChar;
				
					(*targetVec).push_back(thetaNum);
				}
                
                done=true;
				*targetDec = PRECISION;
                
                numbers += (PRECISION+1);
                counter += 5;
                i += 5;
            }
        }
        
		//if it isn't a space, number, symbol, end marker, or decimal point, return error
		if (checkSpace(c[i])==false && 
			isNumber(c[i], user)==false && 
			isSymbol(c[i])==false && 
			c[i] != '$' && 
			c[i] != ',' && 
			c[i] != '.')
		{
			RETURN_ERROR;
		}

		if (c[i]==',')
		{
			if (comma==false)
			{
				if (decimal==true || numbers==0 || numbers > 3 || done==true)
					RETURN_ERROR;

				else comma = true;
			}

			else if (commaNumbers != 3)
			    RETURN_ERROR;
			    
			commaNumbers=0;    
		}
			
		//if it's a space
		else if (checkSpace(c[i])==true)
		{
			//if it's preceeded by a number, number is complete
			if (isNumber(c[i-1], user))
		    {
		        done = true;
		    }
		    
		    //if negative is set, and it is preceeded by a minus symbol, return error
		    else if (checkSymbol(c[i-1]) == SUBTRACT && *targetNegative == true)
		    {
		        RETURN_ERROR;
		    }
		}

        //if it's a number
        else if (isNumber(c[i], user))
        {        
            //if number was complete, return error
            if (done==true)
			{
                RETURN_ERROR;
			}
			
		    if (comma==true)
		        commaNumbers++;
                
            //otherwise add number to target vector, add decimal count if needed
            (*targetVec).push_back(checkNumber(c[i]));
                numbers++;
                
            if (decimal==true)
			{
                (*targetDec)++;
			}
        }
        
        //if it's a minus symbol
        else if (checkSymbol(c[i]) == SUBTRACT)
        {
            //if no numbers have been added
            if (numbers==0)
            {
                //if target isn't negative, make target negative
                if ((*targetNegative)==false)
                {
                    (*targetNegative) = true;
                    (*targetBN).setNegative();
                }
                
                //if target is negative, no numbers have been added, and the target is the first number: 
				//there are two minus symbols, which means the intent is to 
				//subtract a negative number from previous
                else if (targetBN == &bn1)
                {
                    pType = SUBTRACT;
                    targetBN = &bn2;
                    numbers=0;
					commaNumbers=0;
					comma=false;
                    bn2.setNegative(); //sets 2nd number to negative
					negative2=true; //sets 2nd number to negative
                    targetNegative= &negative2;
                    done=false;
                    targetDec = &decimalCount2;
                    targetVec = &second;
                    decimal=false;
                }
                
                else 
				{
					RETURN_ERROR;
				}
            }
            
            //if numbers have been added, and the target is the first number, the problem type is subtraction
            else if (targetBN == &bn1)
            {
                if (comma==true && decimal==false && commaNumbers != 3)
                    RETURN_ERROR;
                
                pType = SUBTRACT;
                numbers=0;
				commaNumbers=0;
				comma=false;
                done=false;
                targetBN = &bn2;
				targetNegative= &negative2;
                targetDec = &decimalCount2;
                targetVec = &second;
                decimal=false;
            }
            
            //if numbers have been added, and the target is the second number, return error
            else 
			{
				RETURN_ERROR;
			}
        }
        
        //if it's a symbol other than minus
        else if (checkSymbol(c[i]) != ERROR && checkSymbol(c[i]) != SUBTRACT)
        {
            //if the type is already established, return error
            if (pType != ERROR)
			{
            	RETURN_ERROR;
			}
                
            //otherwise, set problem type based on symbol and reset figures
            else 
            {
                if (comma==true && decimal==false && commaNumbers != 3)
                    RETURN_ERROR;
                
                pType = checkSymbol(c[i]);
                targetBN = &bn2;
                numbers=0;
				commaNumbers=0;
				comma=false;
                done=false;
				targetNegative = &negative2;
                targetDec = &decimalCount2;
                targetVec = &second;
                decimal=false;
            }
        }
        
        //if it's a decimal point
        else if (c[i]=='.')
        {
            //if there's already been a decimal point, return error
            if (decimal==true)
			{
                RETURN_ERROR;
			}
                
            else decimal = true;
            
            if (comma==true && commaNumbers != 3)
                RETURN_ERROR;
        }
        
        //if it's an endline character
        else if (c[i] == '$')
        {
            if (comma==true && decimal==false && commaNumbers != 3)
                    RETURN_ERROR;
                    
			//if both numbers are empty
			if (first.size()==0 && second.size()==0)
			{
				if (pType==FACTORIAL)
				{
					bn1 = previous;
				}

				else RETURN_ERROR;
			}

			//if first number is empty, set bn1 to previous
			if (first.size()==0)
			{
				bn1 = previous;
			}

			//otherwise create bn1 from entered and print it as is
            else
            {   
				bn1 = numberFromVector(first, negative1, decimalCount1, user);
				printExact=true;
            }
            
            //if second number is empty
            if (second.size()==0)
            {               
                //if first number is negative and pType is undefined, subtract number from previous
                if (negative1==true && pType == ERROR)
                {
					bn1.setPositive();
                    temp = previous - bn1;

					cout << "Entered: "; 
					displayNumber(previous, user, false, false);
					cout << " - "; 
					displayNumber(bn1, user, true, false);

					RETURN_OK(temp);
					//return solution(temp, 0);
                }
                
                //if first number isn't negative and no problem type has been declared, return that number
                else if (pType == ERROR)
                {
					cout << "Entered: "; 
					displayNumber(bn1, user, true, false);
					RETURN_OK(bn1);
                    //return solution(bn1, 0);
                }
               
                else if (pType != FACTORIAL)
                {
                    RETURN_ERROR;
                }
            }
                
            //otherwise take ints from second vector and use to set bigNumber2
            else 
            {
                bn2 = numberFromVector(second, negative2, decimalCount2, user);
            }

			cout << "Entered: ";
			displayNumber(bn1, user, printExact, printStats);
			
			break;
        }
    }
    
    //use problem type to calculate solution, return with no errors if valid
    switch(pType)
    {
        case ERROR: RETURN_ERROR;
        
        case ADD: cout << " + "; bn2.printNumber();
            temp = bn1 + bn2;
			RETURN_OK(temp);
        
        case SUBTRACT: cout << " - "; bn2.printNumber();
			temp = bn1 - bn2;
			RETURN_OK(temp);
                
        case MULTIPLY: cout << " * "; bn2.printNumber();
			temp = bn1 * bn2;
			RETURN_OK(temp);
                
        case DIVIDE: cout << " / "; bn2.printNumber();
            if (bn2==0)
            {
                RETURN_ERROR;
            }
            temp = bn1 / bn2;
			RETURN_OK(temp);
                
        case FACTORIAL: 
			if (bn1<0 || bn1.getDecimalCount() > 0)
            {
				RETURN_ERROR;
            }
            
            else if (bn1==0)
            {
				cout << "!";
				bigNumber fact(1);
				fact.setBase(user.getBase());
				RETURN_OK(fact);
            }
            
            temp = bigNumber::factorial(bn1);
			cout << "!";
			RETURN_OK(temp);    
           
        case EXPONENT: cout << "^"; bn2.printNumber();
			temp = bigNumber::exponent(bn1, bn2);
			RETURN_OK(temp);
        
        case ITERATION: cout << "c"; bn2.printNumber();
			temp = bigNumber::iterations(bn1, bn2);
			RETURN_OK(temp);
        
        default: RETURN_ERROR;
    }

}