Example #1
0
void updateDisplay() {
  int elapsed = 0;
  int countdown = 0;
  elapsed = s_currentTimer/2;
  countdown = s_selectedDuration - elapsed;
  
  if(s_currentTimer%2 == 0) {
    static char bUp[10];
    static char bDown[4];
    //static char bDuration[10];
    //static char bDuration[5];
    //static int elapsed = 0;
    //static int countdown = 0;
    
    //elapsed = s_currentTimer/2;
    //countdown = s_selectedDuration - elapsed;
    if(countdown > 0) {
      //printInt(s_countup, elapsed, bUp);
      printInt(s_countdown, countdown, bDown);
      //printInt(s_duration, s_selectedDuration, bDuration);
      
      snprintf(bUp, 10, "%d / %d", elapsed, s_selectedDuration);
      text_layer_set_text(s_countup, bUp);
    } else {
      printInt(s_countup, elapsed - s_selectedDuration, bUp);
      //text_layer_set_text(s_duration, "");
    }
    
     if(countdown == 10) {
      vibes_double_pulse();
    } else if(countdown == 3) {
      vibes_long_pulse();
    } else if(countdown == 2 || countdown == 1) {
      vibes_short_pulse();
    } else if(countdown == 0) {
      window_set_background_color(s_window, GColorWhite);
      vibes_long_pulse();
      s_timerActive = false;
      updateMenu(s_selectedDuration);
      text_layer_set_text(s_countdown, "");
      text_layer_set_text(s_countup, "");
      updateSets();
    }
  }
  
  if(s_timerActive) {
    if(countdown <= 10) {
       window_set_background_color(s_window, GColorRed);
    } else if (s_currentTimer < s_selectedDuration) {
      window_set_background_color(s_window, GColorGreen);
    } else {
      window_set_background_color(s_window, GColorOrange);
      if(s_currentTimer == s_selectedDuration) { // halfway point
        vibes_double_pulse();
      } 
    }
  }
}
void example_1()
{
	int a = 111; // as we know a is a Lvalue.

	printInt(a); // so here, the printInt(int&) will be called.

	printInt(a + 2); // but here, the Rvalue version ( printInt(int&&) ) will be called.

}
Example #3
0
/* printOutput takes the arrays of integers and argv and prints them to
 * 	stdout. It makes calls to printInt to accomplis this.
 * 
 * Parameters:
 *   int array[]: Array of hex values converted to integers
 *   char *copyofArgv[]: the stdin arguments passed to the program
 *   int numOfInts: size of array[]
 */
void printOutput(int array[], char *copyOfArgv[], int numOfInts) {
  int i;
  for ( i = 1; i < numOfInts; i++ ) {
    printf("%s\n", copyOfArgv[i]);
    printf("Decimal: ");
    printInt(array[i - 1], 10);
    printf("Binary: ");
    printInt(array[i - 1], 2);
  }
}
Example #4
0
// This task is used to print the instantaneous distances to the OLED display.
// Only want to print to the OLED display once autonomous/manual mode is initiated
void vPrintDistance(void *vParameters) {
  while(1) {
    if (state == 6 || state == 5 || state == 9) { // autonomous/manual mode states
      printInt(LookupDistanceTable(dist0), 70, 24);
      printInt(LookupDistanceTable(dist1), 70, 34);
      printInt(LookupDistanceTable(dist2), 70, 44);
      printInt(LookupDistanceTable(dist3), 70, 54);
    }
    vTaskDelay(50); // delay of about 20 ms
  }
}
Example #5
0
void shake_detect_update() {
	// if (shakeDetected == 0) SHAKE_DETECT_TIMER_COUNTER = 0;	// reset timer when no shake was detected

	const int32_t totalG = ACCEL_getTotalVectorSquared();

	if (shakeDetected == 1 && minShakeTimeExceeded == 0
	 && SHAKE_DETECT_TIMER_COUNTER >= minShakeTimeCounterVal)  // it was shaken long enough
	{	
		minShakeTimeExceeded = 1;
		// DIGIWRITE_H(PORTB, PB1);
	}

	if (shakeLevel > 0) {	// when a shake level is given, 
		shakeLevel--;	// calm down again
#ifdef DEBUG
		softuart_putchar('l');
		softuart_putchar('=');
		printInt(shakeLevel);PRINT_NL;
#endif
	}

	// check if we can end the shake event
	if (shakeLevel < SHAKE_DETECT_THRESH && shakeDetected != 0 && minShakeTimeExceeded != 0) {
#ifdef DEBUG
		softuart_putchar('s');PRINT_NL;
#endif
		shakeDetected = 0;
		// DIGIWRITE_L(PORTB, PB1);
		minShakeTimeExceeded = 0;
		(*shakeDetectEndCallback)();
	} else if (totalG > SHAKE_DETECT_SHOCK_THRESH
	        && shakeLevel + SHAKE_DETECT_SHOCK_LEVEL_INCREASE < SHAKE_DETECT_MAX_LEVEL)
	{
        shakeLevel += SHAKE_DETECT_SHOCK_LEVEL_INCREASE;	// get more excited

#ifdef DEBUG
		// printUInt(totalG);PRINT_NL;
		softuart_putchar('l');
		softuart_putchar('=');
		printInt(shakeLevel);PRINT_NL;
#endif

		// check if we can start the shake event
		if (shakeLevel >= SHAKE_DETECT_THRESH && shakeDetected == 0) {
#ifdef DEBUG
			softuart_putchar('S');PRINT_NL;
#endif
			shakeDetected = 1;
			SHAKE_DETECT_TIMER_COUNTER = 0;	// reset the timer
			(*shakeDetectBeginCallback)();
		}
	}
}
// Core 0
// consume & check data
int core0()
{
	printStr("Benchmark mc_produce_consume\n");

	// start counting instructions and cycles
	int cycles, insts;
	cycles = getCycle();
	insts = getInsts();

    // check data found in the common fifo
    uint32_t data = 0;
    int new_head_index = 0;
    for(int i = 0; i < DATA_SIZE; i++) {
		new_head_index = *head_index;
        while( new_head_index == *tail_index ); // wait for data to be produced
        data = fifo_data[new_head_index];
        new_head_index++;
        if( new_head_index == FIFO_SIZE ) {
            new_head_index = 0;
        }
        *head_index = new_head_index;
        if( data != input_data[i] ) {
			printStr("At index "); printInt(i);
			printStr(", receive data = ");
			printInt(data);
			printStr(", but expected data = ");
			printInt(input_data[i]);
			printStr(", mismatch!\n");
			printStr("Return "); printInt(i+1); printChar('\n');
			return (i+1);
        }
    }

	// stop counting instructions and cycles
	cycles = getCycle() - cycles;
	insts = getInsts() - insts;

	// wait for core 1 to complete
	while(main1_done == 0);

	// print the cycles and inst count
	printStr("Cycles (core 0) = "); printInt(cycles); printChar('\n');
	printStr("Insts  (core 0) = "); printInt(insts); printChar('\n');
	printStr("Cycles (core 1) = "); printInt(main1_cycles); printChar('\n');
	printStr("Insts  (core 1) = "); printInt(main1_insts); printChar('\n');
	cycles = (cycles > main1_cycles) ? cycles : main1_cycles;
	insts = insts + main1_insts;
	printStr("Cycles  (total) = "); printInt(cycles); printChar('\n');
	printStr("Insts   (total) = "); printInt(insts); printChar('\n');

	printStr("Return 0\n");
	return 0;
}
Example #7
0
File: main.c Project: sunneo/libs
int main ( int argc, char *argv[] )
{
   List* list = list_create ( sizeof ( int ),EqualInt );
   int t;
   ListNode* n;
   int i;
   for ( i=0; i<10; ++i )
      list_push_back ( list,createInt ( &t,rand() ) );
   /*list_foreach(list,printInt);*/
   ListIter iter = list_get_iter ( list );
   while ( list_iter_hasNext ( iter ) )
   {
      printInt ( list_iter_next ( iter ) );
   }
   printf ( "\n" );
   list_pop_back ( list );
   list_foreach ( list,incInt );
   list_foreach ( list,printInt );
   printf ( "\n" );
   n = list_find_first_node ( list,createInt ( &t,846930887 ) );
   list_erase_node ( list,n );
   list_foreach ( list,printInt );
   list_delete ( list );
   return 0;
}
void warnCol(int i,int j,int k,int val) {
    int p,r;
    int square;
    int value;

    for(p=0; p<n; p++)
        if(p*n!=i)   //if it's not the allineation
        {
            square=p*n + j/n;   //position of this square in array q

            for(r=0; r<n; r++)
                if(m[p*n+r][j+k] & mask)
                {
                    if(DEBUG2) printf("subC: (%d,%d)=%d >>>>%d \n",p*n+r,j+k,m[p*n+r][j+k],m[p*n+r][j+k] & (m[p*n+r][j+k] ^ val));
                    m[p*n+r][j+k]=m[p*n+r][j+k] & (m[p*n+r][j+k] ^ val);

                    if(m[p*n+r][j+k]!=mask)
                    {
                        value=checkOneValue(p*n+r,j+k);
                        if(value>0)
                            setNum(p*n+r,j+k,value);
                    } else {
                        printInt("column error, value=",val);
                        //printf("column error: %d,%d+%d, =%d \n",i,j,k,val);
                    }
                }
        }
}
Example #9
0
int printString(char* in)
{
	int size = (int)strlen(in);
	printInt(size+1);
	fwrite(in, sizeof(char), size+1, output);
	return 0;
}
void warnRow(int i,int j,int k,int val) {
    int p,r;
    int square;
    int value;

    for(p=0; p<n; p++)
        if(p*n!=j)   //if it's not the allineation
        {
            square=i + p;   //position of this square in array q

            for(r=0; r<n; r++)
                if(m[i+k][p*n+r] & mask)
                {
                    if(DEBUG2) printf("subR: (%d,%d)=%d >>>>%d \n",i+k,p*n+r,m[i+k][p*n+r],m[i+k][p*n+r] & (m[i+k][p*n+r] ^ val));
                    m[i+k][p*n+r]=m[i+k][p*n+r] & (m[i+k][p*n+r] ^ val);

                    if(m[i+k][p*n+r]!=mask)
                    {
                        value=checkOneValue(i+k,p*n+r);
                        if(value>0)
                            setNum(i+k,p*n+r,value);
                    } else {
                        printInt("row error, value=",val);
                        //printf("row error: %d+%d,%d, =%d \n",i,k,j,val);
                    }
                }
        }
}
Example #11
0
void main ( )
{
		int a,b,c,d,e,f,x;
		
		if ( x != 0 )
		{
			a = 4;
			c = 5 - d;
		}
		else
		{
			a = 6 + b;
			b = 3 - c;
		}

		if ( x < 2 )
		{
			b = 5 + c;
		}
		else
		{
			d = 6 + b;
		}

		f = a + 2;
		a = b + c;
		c = e + d;
		b = f + 1;
		e = a - 3;

		x = a + b + c + d + e + f;
		printInt(x);
}
Example #12
0
// Render a value to text.
char*
aJsonClass::printValue(aJsonObject *item)
{
  char *out = NULL;
  if (!item)
    return NULL;
  switch (item->type)
    {
  case aJson_NULL:
    out = strdup("null");
    break;
  case aJson_False:
    out = strdup("false");
    break;
  case aJson_True:
    out = strdup("true");
    break;
  case aJson_Int:
    out = printInt(item);
    break;
  case aJson_Float:
    out = printFloat(item);
    break;
  case aJson_String:
    out = printString(item);
    break;
  case aJson_Array:
    out = printArray(item);
    break;
  case aJson_Object:
    out = printObject(item);
    break;
    }
  return out;
}
void Environment::addDefaultFunctions() {
  // void printInt(int);
  FunType::PtrType printInt(new FunType("printInt"));
  printInt->args.push_back(AbsPtrType(new IntType()));
  printInt->ret_type = AbsPtrType(new VoidType());
  insertFunction(printInt);

  // void printString(string);
  FunType::PtrType printString(new FunType("printString"));
  printString->args.push_back(AbsPtrType(new StringType()));
  printString->ret_type = AbsPtrType(new VoidType());
  insertFunction(printString);

  // void error();
  FunType::PtrType error(new FunType("error"));
  error->ret_type = AbsPtrType(new VoidType());
  insertFunction(error);

  // int readInt();
  FunType::PtrType readInt(new FunType("readInt"));
  readInt->ret_type = AbsPtrType(new IntType());
  insertFunction(readInt);

  // string readString();
  FunType::PtrType readString(new FunType("readString"));
  readString->ret_type = AbsPtrType(new StringType());
  insertFunction(readString);
};
Example #14
0
void main ( ) 
{
   int c;
   printStr("Result should be: 8 10");
   printLn();

   c = a[0];
   a[1] = 4;
   a[2] = 5;
   a[0] = foo( a[1] );
   printInt(a[0]);
   printStr(" ");
   a[0] = foo( a[2] );
   printInt(a[0]);
   printLn();
}
Example #15
0
void main()
{
  int i, j=0, value=0, str_len, sum=0;
  int numbers[10];
  char buffer[100];
  
  printStr("enter seperated values: \n");
  readStr(buffer, 100);
  
  str_len=0;
  while (buffer[str_len] != 0)
    str_len++;
    
  for (i=0; i<str_len; i++)
  {
    if (buffer[i] == ',' || buffer[i] == ' ')
      continue; 
      
    if (!(buffer[i] >= '0' && buffer[i] <= '9'))
    {
      printStr("ERROR: numbers only allowed.\n");
      break;
    }
    
    while (buffer[i] >= '0' && buffer[i] <= '9')
    {
      int digit = buffer[i] - 48;
      value = value * 10 + digit;
      i++;
    }
    
    numbers[j] = value;
    value = 0;
    j++;
  }
  
  for (i=0; i<j; i++)
  {
    sum = sum + numbers[i];
    
    printInt(numbers[i]);
    printChar(' ');
  }
  
  printStr("\n\n Median(numbers) = ");
  printInt(sum / j);
}
Example #16
0
/* 在文件系统中加载文件,文件大小写入size所指变量,返回bool值表示是否成功 */
bool loadFile(const char *path, uint32_t partitionFirstSector, uint32_t *size) {
    printString("    ");

    firstSector = partitionFirstSector;
    loadSector(firstSector + 2, superBlockBuffer);
    blockSize = (uint32_t) (1024 << superBlock->logBlockSize);
    sectorsPerBlock = blockSize / SECTOR_SIZE_512;

    if (superBlock->magic != EXT2_MAGIC_NUM) {
        printLine("incorrect ext2 magic number");
        return false;
    }
    if (superBlock->revLevel < EXT2_DYNAMIC_REV) {
        printLine("reversion of this ext2 filesystem is too old");
        return false;
    }
    if (blockSize > 0x10000) {
        printLine("block size is too large");
        return false;
    }

    uint32_t targetInode = EXT2_INODE_ROOT;

    for (const char *nameEnd = path; *nameEnd != '\0';) {
        for (path = nameEnd; *path == '/'; ++path);
        for (nameEnd = path; *nameEnd != '/' && *nameEnd != '\0'; ++nameEnd);
        if (nameEnd == path) {
            break;
        }
        targetInode = findChild(targetInode, path, nameEnd - path);
        if (targetInode == EXT2_INODE_NULL) {
            printLine("can't find such file");
            return false;
        }
    };

    Ext2Inode inode = loadInode(targetInode);
    if ((inode.mode & EXT2_MODE_FT_MASK) != EXT2_MODE_FT_REG_FILE) {
        printLine("not a regular file");
        return false;
    } else {
        printString("file found, size: ");
        printInt(inode.size);
        printString(" bytes (");
        printStorageSize(inode.size);
        printLine(")");
    }

    uint32_t blkCnt = inode.size / blockSize + (inode.size % blockSize != 0);
    for (uint32_t blockOffset = 0; blockOffset < blkCnt; ++blockOffset) {
        uint32_t block = getBlockIndex(&inode, blockOffset);
        if (!readFileSectorsToBuffer(lbaOfBlock(block), sectorsPerBlock)) {
            return false;
        }
    }

    *size = inode.size;
    return true;
}
int main()
{
	int n;
	printf("Enter an integer: ");
	scanf("%d", &n);//get the integer
	printInt(n); //function call to the library
	return 0;
}
Example #18
0
int main(void) {
  char cr[2];

  cr[0]='\n';
  cr[1]=0;

  printString(cr);
  printInt(42);

  printString(cr);
  printInt(35+7);

  printString(cr);
  printInt(6*7);

  printString(cr);
  printInt(3*4+5*6);

  printString(cr);
  printInt(7*8-3*4-2);

  printString(cr);
  printInt((-6)*(-7));

  printString(cr);

  printInt( ((9 + 9 + 9) 
	     * ((9 + 9) / 9) 
	     * (9 * 9 - (9 + 9)) 
	     + (9 + 9)*(9+9+9)) 
	    / (9 * 9+9) 
	    - 9 / 9);

  printString(cr);
}
int main0( )
{

  printStr("Benchmark mc_median\n");

  // start counting instructions and cycles
  int cycles, insts;
  cycles = getCycle();
  insts = getInsts();

  // do the median filter
  median_first_half( DATA_SIZE, input_data, results_data );

  // stop counting instructions and cycles
  cycles = getCycle() - cycles;
  insts = getInsts() - insts;

  // wait for main1 to finish
  while( main1_done == 0 );

  // print the cycles and inst count
  printStr("Cycles (core 0) = "); printInt(cycles); printChar('\n');
  printStr("Insts  (core 0) = "); printInt(insts); printChar('\n');
  printStr("Cycles (core 1) = "); printInt(main1_cycles); printChar('\n');
  printStr("Insts  (core 1) = "); printInt(main1_insts); printChar('\n');
  cycles = (cycles > main1_cycles) ? cycles : main1_cycles;
  insts = insts + main1_insts;
  printStr("Cycles  (total) = "); printInt(cycles); printChar('\n');
  printStr("Insts   (total) = "); printInt(insts); printChar('\n');

  // Check the results
  int ret = verify( DATA_SIZE, results_data, verify_data );
	printStr("Return "); printInt(ret); printChar('\n');
	return ret;
}
Example #20
0
void incrTest() {
	int j = 0;
	int i[2];
	i[0] = 1;
	i[1] = 2;
	incr(&(j));
	incr(&(i[0]));
	incr(&(i[1]));
	
	printInt(j);
	printString("\n");
	
	printInt(i[0]);
	printString("\n");
	
	printInt(i[1]);
	printString("\n");
}
Example #21
0
int main( int argc, char* argv[] )
{
  int results_data[DATA_SIZE];

  // Do the filter
  int cycles, insts;
  cycles = getTime();
  insts = getInsts();
  median( DATA_SIZE, input_data, results_data );
  cycles = getTime() - cycles;
  insts = getInsts() - insts;
  printStr("Cycles = "); printInt(cycles); printChar('\n');
  printStr("Insts  = "); printInt(insts); printChar('\n');

  // Check the results
  return !(verify( DATA_SIZE, results_data, verify_data ));

}
Example #22
0
static void updateMenu(int time) {
  s_duration1 = time;
  s_duration2 = time + 15; 
  s_duration3 = time + 30; 
  if(s_duration3<100) {
    layer_set_frame((Layer *)s_menubar, GRect(120, 0, 24, 168));
  } else {
    layer_set_frame((Layer *)s_menubar, GRect(112, 0, 32, 168));
  }
  static char b1[4];
  static char b2[4];
  static char b3[4];
  printInt(s_restart1, s_duration1, b1);
  printInt(s_restart2, s_duration2, b2);
  printInt(s_restart3, s_duration3, b3);
  
  setHiddenRestarts(false);
}
Example #23
0
void func1() {
	int x=0;
	while(1) {
		timer_wait(6);
		//putch('A');
		putch('\n');
		printInt(x++);
	}
}
Example #24
0
File: p3.c Project: ptrodrigues/AC2
void test_7seg()
{
	printStr("Testing low display\n0x");
	LATB = set_SSD_Hex(LATB,CHECK,false);	 // enable low display
	printInt(LATB,(4<<16)+16);
	putChar('\n');
	delay(1000);
	//while(readCoreTimer() < (FREQ/2));	// period = 1s
	//resetCoreTimer();
	printStr("Testing high display\n0x");
	LATB = set_SSD_Hex(LATB,CHECK,true);	// enable high display
	printInt(LATB,(4<<16)+16);
	putChar('\n');
	delay(1000);
	//while(readCoreTimer() < (FREQ/2)); 	// period = 1s
	//resetCoreTimer();
	LATB &= 0xFC00;				// turn off both displays
}
Example #25
0
void probeOS()
{
    uint8_t maj, min;
    
    //OpenServo os(0x10);
    
    i2c.Init();

    if (os.GetVersion(&maj, &min) != 0) {    
        com.puts("\nCould not read version\n");
        return;
    }
    com.puts("\nOpenServo version:");
    printInt(maj);
    com.putchar('.');
    printInt(min);
    com.puts("\n");
}
Example #26
0
int main(void) {
  int a;
  int b;
  int c;
  
  char zero[4];
  char one[4];

  zero[0] = '\n';
  zero[1] = '0';
  zero[2] = ' ';
  zero[3] = 0;

  one[0] = '\n';
  one[1] = '1';
  one[2] = ' ';
  one[3] = 0;

  a=0;
  b=0;
  c=0;

  printString(zero);
  printInt(a || !b && c);

  a = 0; b = 0; c = 1;
  printString(one);
  printInt(a || !b && c);

  a = 0; b = 1; c = 0;
  printString(zero);
  printInt(a || !b && c);

  a = 0; b = 1; c = 1;
  printString(zero);
  printInt(a || !b && c);

  a = 1; b = 0; c = 0;
  printString(one);
  printInt(a || !b && c);

  a = 1; b = 0; c = 1;
  printString(one);
  printInt(a || !b && c);

  a = 1; b = 1; c = 0;
  printString(one);
  printInt(a || !b && c);

  a = 1; b = 1; c = 1;
  printString(one);
  printInt(a || !b && c);

}
Example #27
0
void printList(TCBptr list)
{
	TCBptr current;
	char * priority;
	char * delay;
	current = list;
	
	priority = "\tpriority = ";
	delay = " delay = ";
	while(current != NULL)
	{
		printString(priority);
		printInt(current->priority);
		printString(delay);
		printInt(current->delay);
		printNewLine();
		current = current->next;
	}
}
Example #28
0
void displayNum(unsigned int num){
  if(num > 18){
    print("Illegal Access:");
    printInt(num);
    print("\n");
    displayClear();
  } else {
    DDRC = segment_table[num];
  }
}
void testArr(int *arr, size_t count, bSortfPtr func)
{
    func(arr, count, sizeof(int), comparator);
    if(greaterInt(arr, count) < 0) {
        printf("Error sorting with array:\n");
        printInt(arr, count);
    } else {
        printf("Sort ok.\n");
    }
}
Example #30
0
int main(void)
{
	while(1)
	{
		resetCoreTimer();
		delay(1);
		printInt(readCoreTimer(), 10 + (10 << 16));
		printStr("\r\n");
	}
}