Example #1
0
void loop(){ // run over and over again
	int i;  
	startMillis = millis();
  
	SelectFont(System5x7, BLACK);       // select fixed width system font
	while( millis() - startMillis < 1000){ 		// loop for one second
    DrawRect(0, 0, 64, 61, BLACK); 				// rectangle in left side of screen
    DrawRoundRect(68, 0, 58, 61, 5, BLACK);  	// rounded rectangle around text area   
    for(i=0; i < 62; i += 4)
      DrawLine(1,1,63,i, BLACK);  				// draw lines from upper left down right side of rectangle  
    DrawCircle(32,31,30,BLACK);   				// draw circle centered in the left side of screen  
    FillRect(92,40,16,16, WHITE); 				// clear previous spinner position  
    CursorTo(3,4);               				// locate curser for printing text
    GotoXY(29,40);								// use GotoXY for truetype fonts
    PrintNumber(++iter);         				// print current iteration at the current cursor position
  }

  SelectFont(Arial_Bold_14, BLACK); 	// select truetype font
//
  ClearScreenX();               		// clear the screen  
//
  GotoXY(75,24);						// use GotoXY for truetype fonts
  Puts("FPS= ");             			// print a text string  
  PrintNumber(iter);         			// print a number  
  iter = 0;
 }
Example #2
0
ObjectStruct* CreateObject(u16                          objectType, 
                           ObjectFunctionType           updateFunction, 
                           ObjectFunctionType           destroyFunction,
                           ObjectFunctionType           drawFunction,
                           ObjectCollisionFunctionType  collisionFunction)
{
    if (!CanCreateObject(objectType))
    {
        return 0;
    }

    // Tries to find a free slot in the object array. 
    // If there isn't, the object won't be created.

    ObjectCollection* objectCollection = objectCollections[objectType];

    u16 loop = 0;
    ObjectStruct* tempObjectList = objectCollection->objectList;
    u16 numAliveObjects = 0;
    u16 numDeadObjects = 0;
    for (; loop < objectCollection->maxActiveObjects; loop++)
    {
        ObjectStruct* object = tempObjectList;
        if (object->objectState == OBJECTSTATE_FREE)
        {
            totalActiveObjects++;
            object->updateFunction      = (ObjectFunctionTypePrototype)updateFunction;
            object->destroyFunction     = (ObjectFunctionTypePrototype)destroyFunction;
            object->drawFunction        = (ObjectFunctionTypePrototype)drawFunction;
            object->collisionFunction   = (ObjectCollisionFunctionPrototype)collisionFunction;
            object->objectState         = OBJECTSTATE_ACTIVE;
            object->objectType          = objectType;
            objectCollection->numActiveObjects++;

#ifdef DEBUG_OBJECT_MANAGEMENT
            KDebug_Alert("Created Object. Objects Total:");
            PrintNumber(totalActiveObjects);
#endif
            return object;
        }
        else if (object->objectState == OBJECTSTATE_ACTIVE)
        {
            numAliveObjects++;
        }
        else if (object->objectState == OBJECTSTATE_INACTIVE)
        {
            numDeadObjects++;
        }

        tempObjectList++;
    }
#ifdef DEBUG_OBJECT_MANAGEMENT
    KDebug_Alert("Could not add object. Too many created");
    PrintNumber(numAliveObjects);
    PrintNumber(numDeadObjects);
#endif
    PrintText("none avialable");
    return 0;
}
Example #3
0
void ProcessCollisions(ObjectCollection* firstObjectCollection, 
                       ObjectCollection* secondObjectCollection, 
                       CollisionFunction collisionFunction)
{
    if (firstObjectCollection->numVisibleObjects == 0)
        return;
    if (secondObjectCollection->numVisibleObjects == 0)
        return;

    ObjectStruct** tempFirstList = firstObjectCollection->objectVisibilityList;

    u16 firstListCounter = firstObjectCollection->numVisibleObjects;

    while (firstListCounter--)
    {
#ifdef DEBUG_COLLISIONS
        KDebug_Alert("firstObject");
        PrintNumber((*tempFirstList)->objectType);
#endif
        // no need to do anything if we're dead.
        if ((*tempFirstList)->healthPoints > 0 &&
            (*tempFirstList)->objectState == OBJECTSTATE_ACTIVE)
        {
            u16 secondListCounter = secondObjectCollection->numVisibleObjects;
            ObjectStruct** tempSecondList = secondObjectCollection->objectVisibilityList;

            while (secondListCounter--)
            {
#ifdef DEBUG_COLLISIONS
        KDebug_Alert("secondObject");
        PrintNumber((*tempSecondList)->objectType);
#endif
                // no need to do anything if we're dead.
                if ((*tempSecondList)->healthPoints > 0 &&
                    (*tempSecondList)->objectState == OBJECTSTATE_ACTIVE)
                {
                    if (!((*tempFirstList)->x + (*tempFirstList)->rectLeft   > (*tempSecondList)->x + (*tempSecondList)->rectRight ||
                          (*tempFirstList)->x + (*tempFirstList)->rectRight  < (*tempSecondList)->x + (*tempSecondList)->rectLeft ||
                          (*tempFirstList)->y + (*tempFirstList)->rectTop    > (*tempSecondList)->y + (*tempSecondList)->rectBottom ||
                          (*tempFirstList)->y + (*tempFirstList)->rectBottom < (*tempSecondList)->y + (*tempSecondList)->rectTop))
                    {
                        (*tempFirstList)->collisionFunction(*tempFirstList, *tempSecondList);
                        (*tempSecondList)->collisionFunction(*tempSecondList, *tempFirstList);
                    }
                }

                tempSecondList++;
            }
        }

        tempFirstList++;
    }
}
首先要考虑int数据类型够不够用,long long够不够用。最后发现最好用字符串来完成。

/*
函数功能:依次打印从1到n位最大数
步骤:
1.对特殊输入的判断
2.定义一个字符数组用来存储要打印的数,并初始化
3.依次累加,并打印数
4.回收内存
*/
void Print1ToMaxOfNDigits(int n)
{
    //1.
    if(n<=0)
        return ;
    //2.
    char* number = new char[n+1];
    memset(number,'0',n);
    number[n]='\0';
    //3.
    while(!Increment(number))
    {
        PrintNumber(number);
    }
    //4.
    delete []number;
}
Example #5
0
static void PrintLines (const cc65_lineinfo* L)
/* Output a list of lines */
{
    unsigned I;
    const cc65_linedata* D;

    /* Lines */
    for (I = 0, D = L->data; I < L->count; ++I, ++D) {
        PrintId (D->line_id, 8);
        PrintId (D->source_id, 8);
        PrintNumber (D->source_line, 6, 9);
        PrintNumber (D->line_type, 4, 6);
        PrintNumber (D->count, 3, 0);
        NewLine ();
    }
}
Example #6
0
void MySevenSegment::Effect( byte mode, unsigned long Value )
{
    switch( mode )
    {
        case LED_NUM:
            //若數字相同則不做任何反應;//
            if( mCurrentNum == Value )
                return;
                
            //新數字比舊數字小,直接更改數字不顯示效果;//
            if( mCurrentNum > Value )
            {
                mCurrentNum = Value;
                PrintNumber( mCurrentNum, false );
                return;
            }

            //單位數滾動;//
            EffectPlusOne( Value );

            //閃動2次;//
            EffectFlicker(2);
            
            break;

        case LED_SERVER:
            //EffectServer();
            //EffectAround(1);            
            EffectAroundStep();
            break;
    }
}
int main(int argc, const char * argv[])
{
    FriendFunction func(4);
    
    PrintNumber(func);
    
    return 0;
}
Example #8
0
static void PrintSpans (const cc65_spaninfo* S)
/* Output a list of spans */
{
    unsigned I;
    const cc65_spandata* D;

    /* Segments */
    for (I = 0, D = S->data; I < S->count; ++I, ++D) {
        PrintId (D->span_id, 7);
        PrintAddr (D->span_start, 8);
        PrintAddr (D->span_end, 9);
        PrintId (D->segment_id, 7);
        PrintId (D->type_id, 6);
        PrintNumber (D->line_count, 6, 7);
        PrintNumber (D->scope_count, 7, 0);
        NewLine ();
    }
}
Example #9
0
static void PrintCSymbols (const cc65_csyminfo* S)
/* Output a list of C symbols */
{
    unsigned I;
    const cc65_csymdata* D;

    /* Segments */
    for (I = 0, D = S->data; I < S->count; ++I, ++D) {
        PrintId (D->csym_id, 6);
        Print ("%-28s", D->csym_name);
        PrintId (D->type_id, 6);
        PrintNumber (D->csym_kind, 4, 6);
        PrintNumber (D->csym_sc, 4, 6);
        PrintNumber (D->csym_offs, 4, 8);
        PrintId (D->symbol_id, 6);
        PrintId (D->scope_id, 0);
        NewLine ();
    }
}
Example #10
0
void MySevenSegment::EffectFlicker( int Times )
{
    for( int i=0; i<Times; i++ )
    {
        delay( 500 );
        mLed.clearDisplay(0);
        delay( 500 );
        PrintNumber( mCurrentNum, false );
    }
}
Example #11
0
int main()
{
    int *pNumber=NULL;
    pNumber=(int *)malloc(sizeof(int) * NUMBER);
    printf("please input %d numbers:\n",NUMBER);
    for(int i=0;i<NUMBER;++i)
    {
        printf("number %d:",i);
        scanf("%d",pNumber+i);
    }
    int nRet=SmallToBig(pNumber);
    printf("order from small to big\n");
    PrintNumber(pNumber);
    nRet=BigToSmall(pNumber);
    printf("order form big to small\n");
    PrintNumber(pNumber);
    free(pNumber);
    return 1;
}
void Print1ToMaxOfNDigitsRecursively(char* number, int length, int index)
{
    if(index == length - 1) {
        PrintNumber(number);
        return;
    }
    for(int i = 0; i < 10; ++i) {
        number[index + 1] = i + '0';
        Print1ToMaxOfNDigitsRecursively(number, length, index + 1);
    }
}
void loop(){ // run over and over again
int i;
  startMillis = millis();
  while( millis() - startMillis < 1000){ // loop for one second
    DrawRect(0, 0, 64, 61, BLACK); // rectangle in left side of screen
    DrawRoundRect(68, 0, 58, 61, 5, BLACK);  // rounded rectangle around text area   
    for(i=0; i < 62; i += 4)
      DrawLine(1,1,63,i, BLACK);  // draw lines from upper left down right side of rectangle  
    DrawCircle(32,31,30,BLACK);   // draw circle centered in the left side of screen  
    FillRect(92,40,16,16, WHITE); // clear previous spinner position  
    CursorTo(5,5);               // locate curser for printing text
    PrintNumber(++iter);         // print current iteration at the current cursor position 
  } 
//
  ClearScreenX();               // clear the screen  
  CursorTo(13,2);              // positon cursor  
  Puts("FPS= ");               // print a text string  
  PrintNumber(iter);           // print a number 
  iter=0;
 }
Example #14
0
static void PrintSymbols (const cc65_symbolinfo* S)
/* Output a list of symbols */
{
    unsigned I;
    const cc65_symboldata* D;

    /* Segments */
    for (I = 0, D = S->data; I < S->count; ++I, ++D) {
        PrintId (D->symbol_id, 6);
        Print ("%-24s", D->symbol_name);
        PrintNumber (D->symbol_type, 4, 6);
        PrintNumber (D->symbol_size, 4, 6);
        PrintNumber (D->symbol_value, 5, 7);
        PrintId (D->export_id, 7);
        PrintId (D->segment_id, 6);
        PrintId (D->scope_id, 6);
        PrintId (D->parent_id, 0);
        NewLine ();
    }
}
//=============================== Solution 1 =======================================
void Print1ToMaxOfNDigits_1(int n)
{
	if (n <= 0)
		return;

	char *number = new char[n + 1];
	memset(number, '0', n);
	number[n] = '\0';

	while (!Increment(number))
		PrintNumber(number);

	delete[] number;
}
Example #16
0
static void PrintSources (const cc65_sourceinfo* S)
/* Output a list of sources */
{
    unsigned I;
    const cc65_sourcedata* D;

    /* Segments */
    for (I = 0, D = S->data; I < S->count; ++I, ++D) {
        PrintId (D->source_id, 8);
        Print ("%-30s", D->source_name);
        PrintNumber (D->source_size, 7, 9);
        PrintTime (D->source_mtime, 0);
        NewLine ();
    }
}
void PrintOneToMaxNDigits(int n)
{
	if(n <= 0) {
	    printf("Invalid Input!");
	}
	
	char* number = (char*)malloc(sizeof(char) * (n + 1));
	number[n] = '\0';
	memset(number, '0', n);
	
	while(!InCrement(number, n))
	{
	    PrintNumber(number, n);
	}
	
	free(number);
}
Example #18
0
/* Recursively print a parse tree as code */
void PrintParseTree(VyParseTree* tree){
	int treeType = tree->type;

	/* If it is a list, then print a parenthesized list */
	if(treeType == TREE_LIST){
		PrintListGeneric(tree, '(', ')');
	}

	/* Print a reference separated by a colon */
	else if(treeType == TREE_REF){
		PrintParseTree(GetObj(tree));
		/* Delete the previous space before adding the colon */
		printf("\b:");
		PrintParseTree(GetRef(tree));
	}

	/* If it is a number or identifier, just print the string */
	else if(treeType == TREE_IDENT)  {
		printf("%s ", GetStrData(tree));
	}
	else if(treeType == TREE_NUM){
		PrintNumber(GetNumberData(tree));

		/* Print a space so that the backspace doesn't delete part of the number */
		printf(" ");
	}
	/* Print strings enclosed in quotes */
	else if(treeType == TREE_STR){
		printf("\"");
		printf("%s", GetStrData(tree));
		printf("\"");
		printf("\"");
	}

	/* If it is an error, print the error */
	else if(treeType == TREE_ERROR){
		printf("\n---------------------------------\n");
		printf("Error: %s", tree->data->error.message);
		printf("\n---------------------------------\n");
	}

	else{
		printf("\n\n\nWarning: Incorrect parse tree node type: %d! \n\n\n", treeType);		
	}

}
Example #19
0
static void PrintScopes (const cc65_scopeinfo* S)
/* Output a list of scopes */
{
    unsigned I;
    const cc65_scopedata* D;

    /* Segments */
    for (I = 0, D = S->data; I < S->count; ++I, ++D) {
        PrintId (D->scope_id, 8);
        Print ("%-24s", D->scope_name);
        PrintNumber (D->scope_type, 4, 8);     /* ## */
        PrintSize (D->scope_size, 8);
        PrintId (D->parent_id, 8);
        PrintId (D->symbol_id, 8);
        PrintId (D->module_id, 0);
        NewLine ();
    }
}
int main()
{
  int i;
  int configParam;

  PrintOut("===TestStartUserProgram===\n", 27);
  
  configParam = GetConfigArg();
  PrintOut("Will Exec teststartuserprogramsub ", 34);
  PrintNumber(configParam);
  PrintOut(" times\n", 7);
  
  for(i=0; i < configParam; i++)
  {
    Exec("../test/teststartuserprogramsub");  
  }

  PrintOut("===TestStartUserProgram Completed===\n", 37);
  Exit(0);
}
Example #21
0
void serial::initialize(unsigned int base_port, int line_control, int fifo, unsigned int speed, int modem_control, int enable_ints)
{	//TODO: read initial states for the com port and figure out why input is being disabled

	unsigned int stat1, stat2, stat3, stat4, stat5, stat6, stat7;
	stat1 = inportb(base_port + LINE_CONTROL);
	if ((stat1 & 0x80) == 0x80)
	{
		outportb(stat1 & 0x7F, base_port + LINE_CONTROL);
	}
	stat2 = inportb(base_port + INT_ENABLE);
	stat3 = inportb(base_port + INT_ID);
	stat4 = inportb(base_port + LINE_CONTROL);
	stat5 = inportb(base_port + MODEM_CONTROL);
	stat6 = inportb(base_port + LINE_STATUS);
	stat7 = inportb(base_port + MODEM_STATUS);
	//3, 0, c1, 3, b, 0, b0
	display("\nSerial port status:\n");
	PrintNumber(stat1);
	display(", ");
	PrintNumber(stat2);
	display(", ");
	PrintNumber(stat3);
	display(", ");
	PrintNumber(stat4);
	display(", ");
	PrintNumber(stat5);
	display(", ");
	PrintNumber(stat6);
	display(", ");
	PrintNumber(stat7);
	display("\n");

	outportb(0x00, base_port + INT_ENABLE);	//disable all com port interrupts
	outportb(line_control | LCR_DIVISOR_LATCH, base_port + LINE_CONTROL);	
		//setup data length, parity, stop bits, 
		//also set the divisor latch so the data speed can be set
	outportb(fifo | FCR_CLEAR_RECEIVE | FCR_CLEAR_SEND, base_port + FIFO_CONTROL);
	outportb(speed & 0xFF, base_port + DIVISOR_LATCH_LOW_BYTE);
	outportb(speed>>8, base_port + DIVISOR_LATCH_HI_BYTE);
	outportb(line_control, base_port + LINE_CONTROL);
	outportb(modem_control | MCR_AUX2 | MCR_RTS | MCR_DTR, base_port + MODEM_CONTROL);
	outportb(enable_ints, base_port + INT_ENABLE);	//enable interrupts requested
	
}
//-----------------------------------------------------------------------------
// Render a value to text. 
char* JSON::PrintValue(int depth, bool fmt)
{
	char *out=0;

    switch (Type)
	{
        case JSON_Null:	    out = JSON_strdup("null");	break;
        case JSON_Bool:
            if ((int)dValue == 0)
                out = JSON_strdup("false");
            else
                out = JSON_strdup("true");
            break;
        case JSON_Number:	out = PrintNumber(dValue); break;
        case JSON_String:	out = PrintString(Value); break;
        case JSON_Array:	out = PrintArray(depth, fmt); break;
        case JSON_Object:	out = PrintObject(depth, fmt); break;
        case JSON_None: OVR_ASSERT_LOG(false, ("Bad JSON type.")); break;
	}
	return out;
}
Example #23
0
/** main() - where all the setup happens. */
int main(){
    int RXbypass;       // Bypass rx?
    unsigned char input, checksum;
    serialInit(115200); // Startup serial port
    // setup variables
    count = 0;
    servoSetPosition(PIN_SERVO, -80);

    // setup sensors
    gp2longInit(PIN_PAN_IR);
    gp2d12Init(PIN_LEFT_IR);
    gp2d12Init(PIN_RIGHT_IR);    
    gp2d12Init(PIN_L_REAR_IR);
    gp2d12Init(PIN_R_REAR_IR);
    servoInit(PIN_SERVO,-15,1);

    // RX bypass enabled?
    digitalSetDirection(PIN_NO_RX, AVRRA_INPUT);
    digitalSetData(PIN_NO_RX, AVRRA_HIGH);
    if(digitalGetData(PIN_NO_RX) == AVRRA_LOW){
        // bypass RX;
        RXbypass = TRUE;
        TXgo = TRUE;        
        startFrame();
        delayms(5000);
    }else{        
        RXbypass = FALSE;
        Print("MechDAR V1.0 Alive\n");
        TXgo = FALSE;
    }

    // setup a 60Hz clock on Timer/Counter 2
    TCNT2 = 0;
	OCR2A = 240;			// this defines 60 Hz Clock
	TCCR2A = 0x03;          // no A|B compare, mode7 fast pwm
	TCCR2B = 0x0F;          // clock/1024
	TIMSK2 |= 0x01; 		// interrupt on overflow

    // start clock
    sei();
    while(1){   
        if((RXbypass == FALSE) && (serialAvailable() > 0)){
            // process incoming
            if(serialRead() == -1){ // 0xFF
                while(serialAvailable() == 0);
                input = (unsigned char) serialRead();
                while(serialAvailable() == 0);
                checksum = (unsigned char) serialRead();
                PrintNumber(input);
                PrintNumber(checksum);
                // if a valid packet...
                if((255 - ((input + checksum)%256)) == 0){
                    // process the data
                    switch(input){
                        case REG_LEFT_IR:
                            PrintNumber(gp2d12GetData(PIN_LEFT_IR));
                            Print("\n");
                            break;
                        case REG_RIGHT_IR:
                            PrintNumber(gp2d12GetData(PIN_LEFT_IR));
                            Print("\n");
                            break;
                        case REG_L_REAR_IR:
                            PrintNumber(gp2d12GetData(PIN_LEFT_IR));
                            Print("\n");
                            break;
                        case REG_R_REAR_IR:
                            PrintNumber(gp2d12GetData(PIN_LEFT_IR));
                            Print("\n");
                            break;
                        case REG_STOP:
                            TXgo = FALSE;
                            break;
                        case REG_GO:
                            TXgo = TRUE;
                            startFrame();
                            break;
                        default:
                            // Send a reading from the data frame                            
                            PrintNumber(data[(input-REG_PAN_BASE)%10]); 
                            Print("\n");
                            break;
                    }
                }                
            }                    
        }
        asm("nop");
    }
    return 0;
};
void loop(){ // run over and over again	
	char x, y;	
	uchar tempC;
	
	if (counter>9){		
		counter = 0;
		sec++;
	}
	
//
	sensor = analogRead(SENSOR);
	
	if (sec>59){
		sec = 0;
		min++;
	}
	
	if (min>59){
		min = 0;
		hour++;
	}
	
	if (hour>23){
		hour = 0;
	}
	
	SelectFont(VerdanaNumbers, BLACK);
	GotoXY(3,0);
	
	if (hour < 10)
		PutChar('0');
	PrintNumber(hour);
	
	PutChar(':');
	if (min < 10)
		PutChar('0');
	PrintNumber(min);
	
	PutChar(':');
	if (sec < 10)
		PutChar('0');
	PrintNumber(sec);
		
//
	if(!(digitalread(HOUR))){
		hour++;
	}
	if(!(digitalread(MIN))){
		min++;
	}
				
//
	DrawCircle(21,43,18,BLACK);
//
	x = (int) RSEC * sinf(sec*0.10472);
	y = (int) RSEC * cosf(sec*0.10472);
	DrawLine(21,43,21+x,43-y, BLACK);
//
	x = (int) RMIN * sinf(min*0.10472);
	y = (int) RMIN * cosf(min*0.10472);
	DrawLine(21,43,21+x,43-y, BLACK);
//
	x = (int) RHOUR * sinf((hour>12?hour-12:hour)*0.5236);
	y = (int) RHOUR * cosf((hour>12?hour-12:hour)*0.5236);
	DrawLine(21,43,21+x,43-y, BLACK);
	
	DrawRoundRect(63, 28, 50, 30, 10, BLACK); 
//
//
//
	
	tempC  = (int)(0.48876 * sensor);
//
	
	SelectFont(VerdanaNumbers, BLACK);
	GotoXY(70,32);
	PrintNumber(tempC);
//
	Puts(";");

//
	Delayms(25); //just a fine tune to get 100ms with this!
	
	if(!counter)
		ClearScreenX();         // clear the screen
	
	counter++;
 }
Example #25
0
void Text::PrintNumber(int number, Position position) {
  PrintNumber(number, position, Color(1,1,1));
}
Example #26
0
void Text::PrintNumber(int number, Position position, Color color) {
  PrintNumber(number, position, color, Size(0.02, 0.03));
}