Example #1
0
int main(void) {
  char byte;
  uint16_t timerValue;

  // -------- Inits --------- //

  initUSART();
  initTimer1();
  LED_DDR = 0xff;                               /* all LEDs for output */
  BUTTON_PORT |= (1 << BUTTON);             /* enable internal pull-up */

  printString("\r\nReaction Timer:\r\n");
  printString("---------------\r\n");
  printString("Press any key to start.\r\n");

  // ------ Event loop ------ //
  while (1) {

    byte = receiveByte();                             /* press any key */
    printString("\r\nGet ready...");
    randomDelay();

    printString("\r\nGo!\r\n");
    LED_PORT = 0xff;                                     /* light LEDs */
    TCNT1 = 0;                                        /* reset counter */

    if (bit_is_clear(BUTTON_PIN, BUTTON)) {
            /* Button pressed _exactly_ as LEDs light up.  Suspicious. */
      printString("You're only cheating yourself.\r\n");
    }
    else {
      // Wait until button pressed, save timer value.
      loop_until_bit_is_clear(BUTTON_PIN, BUTTON);
      timerValue = TCNT1 >> 4;
      /* each tick is approx 1/16 milliseconds, so we bit-shift divide */

      printMilliseconds(timerValue);
      printComments(timerValue);
    }

    // Clear LEDs and start again.
    LED_PORT = 0x00;
    printString("Press any key to try again.\r\n");

  }                                                  /* End event loop */
  return (0);                            /* This line is never reached */
}
Example #2
0
void SlideProperties::paintEvent(QPaintEvent*)
{
    QPainter p(this);

    QString str;
    PhotoInfoContainer photoInfo = d->info.photoInfo;
    QString            comment   = d->info.comment;
    QString            title     = d->info.title;
    QStringList tags             = d->info.tags;
    int offset                   = 0;

    // Display tag names.

    if (d->settings.printTags)
    {
        printTags(p, offset, tags);
    }

    // Display Titles.

    if (d->settings.printTitle)
    {
        str.clear();

        if (!title.isEmpty())
        {
            str += title;
            printInfoText(p, offset, str);
        }
    }

    // Display Captions if no Titles.

    if (d->settings.printCapIfNoTitle)
    {
        str.clear();

        if (title.isEmpty())
        {
            str += comment;
            printComments(p, offset, str);
        }
    }

    // Display Comments.

    if (d->settings.printComment)
    {
        str = comment;
        printComments(p, offset, str);
    }

    // Display Make and Model.

    if (d->settings.printMakeModel)
    {
        str.clear();

        if (!photoInfo.make.isEmpty())
        {
            ImagePropertiesTab::shortenedMakeInfo(photoInfo.make);
            str = photoInfo.make;
        }

        if (!photoInfo.model.isEmpty())
        {
            if (!photoInfo.make.isEmpty())
            {
                str += QString(" / ");
            }

            ImagePropertiesTab::shortenedModelInfo(photoInfo.model);
            str += photoInfo.model;
        }

        printInfoText(p, offset, str);
    }

    // Display Exposure and Sensitivity.

    if (d->settings.printExpoSensitivity)
    {
        str.clear();

        if (!photoInfo.exposureTime.isEmpty())
        {
            str = photoInfo.exposureTime;
        }

        if (!photoInfo.sensitivity.isEmpty())
        {
            if (!photoInfo.exposureTime.isEmpty())
            {
                str += QString(" / ");
            }

            str += i18n("%1 ISO", photoInfo.sensitivity);
        }

        printInfoText(p, offset, str);
    }

    // Display Aperture and Focal.

    if (d->settings.printApertureFocal)
    {
        str.clear();

        if (!photoInfo.aperture.isEmpty())
        {
            str = photoInfo.aperture;
        }

        if (photoInfo.focalLength35mm.isEmpty())
        {
            if (!photoInfo.focalLength.isEmpty())
            {
                if (!photoInfo.aperture.isEmpty())
                {
                    str += QString(" / ");
                }

                str += photoInfo.focalLength;
            }
        }
        else
        {
            if (!photoInfo.aperture.isEmpty())
            {
                str += QString(" / ");
            }

            if (!photoInfo.focalLength.isEmpty())
            {
                str += QString("%1 (%2)").arg(photoInfo.focalLength).arg(photoInfo.focalLength35mm);
            }
            else
            {
                str += QString("%1").arg(photoInfo.focalLength35mm);
            }
        }

        printInfoText(p, offset, str);
    }

    // Display Creation Date.

    if (d->settings.printDate)
    {
        if (photoInfo.dateTime.isValid())
        {
            str = KGlobal::locale()->formatDateTime(photoInfo.dateTime, KLocale::ShortDate, true);
            printInfoText(p, offset, str);
        }
    }

    // Display image File Name.

    if (d->settings.printName)
    {
        printInfoText(p, offset, d->url.fileName());
    }
}
Example #3
0
int
blogcomment_main()
{
	char userid[IDLEN + 1], tmpfile[80], who[32], by[120], *comment;
	char *ptr, *buffer;
	struct Blog blog;
	int fileTime;
	FILE *fp;

	// can't comment the bellow function, or will 500 error!
	printXBlogHeader();
	check_msg();
	strsncpy(userid, getparm2("U", "userid"), sizeof (userid));
	fileTime = atoi(getparm("T"));
	comment = getparm("comment");

	// add who by deli
	strsncpy(who, getparm("who"), sizeof (who));
	if ((ptr = strchr(who, '\n')))
		*ptr = 0;
	if ((ptr = strchr(who, '\r')))
		*ptr = 0;
	strcpy(who, strtrim(who));
	utf8cut(who, sizeof (who));
	// add end

	strsncpy(by, getparm("by"), sizeof (by));
	if ((ptr = strchr(by, '\n')))
		*ptr = 0;
	if ((ptr = strchr(by, '\r')))
		*ptr = 0;
	strcpy(by, strtrim(by));
	utf8cut(by, sizeof (by));
	if ((!loginok || isguest) && !strchr(by, '@')) {
		printf("填写的 Email 不正确。");
		printXBlogEnd();
		return 0;
	}
	if (openBlogW(&blog, userid) < 0) {
		printf("该用户尚未建立 blog。");
		printXBlogEnd();
		return 0;
	}

	sprintf(tmpfile, "bbstmpfs/tmp/%d.tmp", thispid);

	saveTidyHtml(tmpfile, comment, 1);
	buffer = readFile(tmpfile);
	unlink(tmpfile);
	if (!buffer) {
		closeBlog(&blog);
		printf("内存不足!");
		printXBlogEnd();
		return 0;
	}

	fp = fopen(tmpfile, "w");
	fprintf(fp, "F:%s\n", realfromhost);
	if (loginok && !isguest) {
		char idbuf[40];
		gb2utf8(idbuf, sizeof (idbuf), currentuser->userid);
		fprintf(fp, "B:%s %s\n", idbuf,
			urlencode(currentuser->userid));
	} else {
		fprintf(fp, "W:%s\n", who); // add by deli
		fprintf(fp, "B:%s\n", by);
	}
	if (*buffer != '\n')
		fprintf(fp, "\n");
	fputs(buffer, fp);
	fclose(fp);

	free(buffer);

	blogComment(&blog, fileTime, tmpfile);
	printComments(&blog, fileTime);

	closeBlog(&blog);
	printXBlogEnd();

	return 0;
}