示例#1
0
int main()
{
    Bitmap bm;

    bm = bitmapCreate(10);
    if (!bm)
    {
        fprintf(stderr, "Failed to create bitmap.\n");
        return 1;
    }

    bitmapPrint(bm);

    bitmapSet(&bm, 3);
    bitmapSet(&bm, 0);
    bitmapSet(&bm, 8);

    bitmapPrint(bm);

    bitmapUnset(&bm, 3);

    bitmapPrint(bm);

    bitmapClear(&bm);
    
    bitmapPrint(bm);

    bitmapDestroy(&bm);

    printf("End\n");

    return 0;
}
示例#2
0
文件: main.c 项目: krajcovic/lua-tut
/*
 * Funkce volaná ze skriptu
 */
LUA_FUNC clearBitmap(lua_State* L)
{
    /* Kontrola počtu parametrů */
    NUMBER_OF_PARAMETERS(0);
    if (bmp == NULL)
    {
        LUA_ERROR("bitmap does not exist");
    }
    bitmapClear(bmp);
    return LUA_OK;
}
示例#3
0
/* make and return a full-height EAN-8 barcode */
static int makeEan8Full (struct state *st, Bitmap *dest, char *digits, int y)
{
    int baseWidth = 68;
    int baseHeight = 60;

    int height = baseHeight + y;
    int i;

    bitmapClear (dest);
    drawEan8Bars (dest, digits, 0, y, height - 10, height - 4);

    for (i = 0; i < 4; i++)
    {
        drawDigitChar (st, dest, 5 + i*7, height - 7, digits[i]);
        drawDigitChar (st, dest, 37 + i*7, height - 7, digits[i+4]);
    }

    return baseWidth;
}
示例#4
0
/* make and return a full-height EAN-13 barcode */
static int makeEan13Full (struct state *st, Bitmap *dest, char *digits, int y)
{
    int baseWidth = 102;
    int baseHeight = 60;

    int height = baseHeight + y;
    int i;

    bitmapClear (dest);
    drawEan13Bars (dest, digits, 6, y, height - 10, height - 4);

    drawDigitChar (st, dest, 0, height - 7, digits[0]);

    for (i = 0; i < 6; i++)
    {
        drawDigitChar (st, dest, 11 + i*7, height - 7, digits[i+1]);
        drawDigitChar (st, dest, 57 + i*7, height - 7, digits[i+7]);
    }

    return baseWidth;
}
示例#5
0
/* make and return a full-height UPC-E barcode */
static int makeUpcEFull (struct state *st, Bitmap *dest, char *digits, int y)
{
    int baseWidth = 64;
    int baseHeight = 60;

    int height = baseHeight + y;
    int i;

    bitmapClear (dest);
    drawUpcEBars (st, dest, digits, 6, y, height - 10, height - 4);

    drawDigitChar (st, dest, 0, height - 14, digits[0]);

    for (i = 0; i < 6; i++)
    {
        drawDigitChar (st, dest, 11 + i*7, height - 7, digits[i+1]);
    }

    drawDigitChar (st, dest, 59, height - 14, digits[7]);

    return baseWidth;
}
示例#6
0
/* make and return a full-height UPC-A barcode */
static int makeUpcAFull (struct state *st, Bitmap *dest, char *digits, int y)
{
    int baseWidth = 108;
    int baseHeight = 60;

    int height = baseHeight + y;
    int i;

    bitmapClear (dest);
    drawUpcABars (dest, digits, 6, y, height - 10, height - 4);

    drawDigitChar (st, dest, 0, height - 14, digits[0]);

    for (i = 0; i < 5; i++)
    {
        drawDigitChar (st, dest, 18 + i*7, height - 7, digits[i+1]);
        drawDigitChar (st, dest, 57 + i*7, height - 7, digits[i+6]);
    }

    drawDigitChar (st, dest, 103, height - 14, digits[11]);

    return baseWidth;
}
示例#7
0
/* update the model for one iteration.
   This one draws a clock.  By jwz.  */
static void updateClock (struct state *st)
{
  Barcode *b = &st->barcodes[0];
  int BW = 76 /* BARCODE_WIDTH  */;
  int BH = BARCODE_HEIGHT;
  int mag_x, mag_y;
  int i;
  time_t now = time ((time_t *) 0);
  struct tm *tm = localtime (&now);
  XWindowAttributes xgwa;
  int ow = st->windowWidth;
  int oh = st->windowHeight;

  XGetWindowAttributes (st->dpy, st->window, &xgwa);
  st->windowWidth = xgwa.width;
  st->windowHeight = xgwa.height;

  mag_x  = st->windowWidth  / BW;
  mag_y  = st->windowHeight / BH;

  st->barcode_count = 1;

  b->mag = (mag_x < mag_y ? mag_x : mag_y);

  if (b->mag > MAX_MAG) b->mag = MAX_MAG;
  if (b->mag < 1) b->mag = 1;

  b->x = (st->windowWidth  - (b->mag * BW      )) / 2;
  b->y = (st->windowHeight - (b->mag * (BH + 9))) / 2;
  b->pixel = st->fg_pixel;

  if (!st->button_down_p)
    sprintf (b->code, "0%02d%02d%02d?:",
             (st->mode == BC_CLOCK24
              ? tm->tm_hour
              : (tm->tm_hour > 12
                 ? tm->tm_hour - 12
                 : (tm->tm_hour == 0
                    ? 12
                    : tm->tm_hour))),
             tm->tm_min,
             tm->tm_sec);
  else
    sprintf (b->code, "0%02d%02d%02d?:",
             tm->tm_year % 100, tm->tm_mon+1, tm->tm_mday);

  {
    int vstart = 9;
    int hh = BH + vstart;
    char expandedDigits[13];

    expandedDigits[0] = '\0';

    expandToUpcADigits (b->code, expandedDigits);
    if (expandedDigits[0] != '\0')
      b->code[7] = expandedDigits[11];

    bitmapClear (st->theBitmap);
    drawUpcEBars (st, st->theBitmap, b->code, 6, 9, 59, 65);
    for (i = 0; i < 6; i++)
      {
        int off = (i < 2 ? 0 :
                   i < 4 ? 4 :
                   8);
        drawDigitChar (st, st->theBitmap, 11 + i*7 + off, hh - 16, b->code[i+1]);
      }

    if (!st->button_down_p)
      {
#if 0
        char *days[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
        char *s = days[tm->tm_wday];
        bitmapDrawString5x8 (st->theBitmap, (BW - strlen (s)*5) / 2, 0, s);
#endif
        drawDigitChar (st, st->theBitmap,  0, hh - 23, (tm->tm_hour < 12 ? 'A' : 'P'));
        drawDigitChar (st, st->theBitmap, 68, hh - 23, 'M');
      }
    else
      {
        char s[20];
        sprintf (s, "%03d", tm->tm_yday);
        bitmapDrawString5x8 (st->theBitmap, (BW - strlen (s)*5) / 2, 0, s);
      }
  }

  bitmapScale (b->bitmap, st->theBitmap, b->mag);

  if (ow != st->windowWidth || oh != st->windowHeight)
    XClearWindow (st->dpy, st->window);
}
unsigned char init(void)
{
	//init CPU clock
	//OSCCON = 0b01111010; //PLL off, 16MHz HF, system clocked by HFINTOSC block
	OSCCON = 0b11110000; //PLL on, 8MHz HF, system clocked by HFINTOSC block
	while(!OSCSTATbits.PLLR); //wait for PLL to be ready
	
	//init RTC
	T1CON = 0b10001100; //T1OSC selected, 1:1 prescale, T1OSC on, timer1 off
	while(!OSCSTATbits.T1OSCR); //wait for timer1 oscillator to be ready
	TMR1 = 0;
	TMR1IF = 0; //clear interrupt flag
	TMR1IE = 1;	//enable interrupt on TMR0 overflow
	__delay_ms(1); //wait for timer1 oscillator to stabilize
	T1CONbits.TMR1ON = 1; //timer1 on
	PEIE = 1; //enable peripheral interrupts
	
	hours = START_H;
	minutes = START_M;
	seconds = START_S;
	ampm = START_AP;
	
	newSecond = tickCounter = 0;
	
	//init display
	////gpio
	ANSELA = ANSELE = ANSELF = ANSELG = 0; //analog gpio as digital inputs
	
	MATRIX_LAT_COLOR_RED = ~0x00; //gpio high (columns off) by default (these are RED column current sinks)
	MATRIX_LAT_COLOR_GRN = ~0x00; //gpio high (columns off) by default (these are GREEN column current sinks)
	MATRIX_LAT_COLOR_BLU = ~0x00; //gpio high (columns off) by default (these are BLUE column current sinks)
	MATRIX_TRIS_COLOR_RED = 0x00; //gpio as output
	MATRIX_TRIS_COLOR_GRN = 0x00; //gpio as output
	MATRIX_TRIS_COLOR_BLU = 0x00; //gpio as output
	
	MATRIX_LAT_ROW_1 = 0; //gpio low (rows off) by default (this is row current driver 1)
	MATRIX_LAT_ROW_2 = 0; //gpio low (rows off) by default (this is row current driver 2)
	MATRIX_LAT_ROW_3 = 0; //gpio low (rows off) by default (this is row current driver 3)
	MATRIX_LAT_ROW_4 = 0; //gpio low (rows off) by default (this is row current driver 4)
	MATRIX_LAT_ROW_5 = 0; //gpio low (rows off) by default (this is row current driver 5)
	MATRIX_LAT_ROW_6 = 0; //gpio low (rows off) by default (this is row current driver 6)
	MATRIX_LAT_ROW_7 = 0; //gpio low (rows off) by default (this is row current driver 7)
	MATRIX_LAT_ROW_8 = 0; //gpio low (rows off) by default (this is row current driver 8)
	MATRIX_TRIS_ROW_1 = 0; //gpio as output
	MATRIX_TRIS_ROW_2 = 0; //gpio as output
	MATRIX_TRIS_ROW_3 = 0; //gpio as output
	MATRIX_TRIS_ROW_4 = 0; //gpio as output
	MATRIX_TRIS_ROW_5 = 0; //gpio as output
	MATRIX_TRIS_ROW_6 = 0; //gpio as output
	MATRIX_TRIS_ROW_7 = 0; //gpio as output
	MATRIX_TRIS_ROW_8 = 0; //gpio as output

	////matrix scan variables
	currentRefreshingColor = currentRefreshingRow = \
	currentRefreshingRowIndex = currentRefreshingPwmSweep = 0;
	
	bitmapClear();
	updateDisplayRequest = 0;
	
	////matrix scan timer
	//TODO: consider using timer2/4/6 with auto-clear and period register
	OPTION_REG = 0b00001010; //WPU individual, falling edge, fosc/4, 1:8 prescale
	TMR0 = MATRIX_SCAN_TIMER_PRELOAD;
	TMR0IF = 0; //clear interrupt flag
	TMR0IE = 1;	//enable interrupt on TMR0 overflow
	
	//init accelerometer
	InitBma150();
	
	//init serial flash
	
	//init battery charging
	BATT_STAT1_TRIS = 1; //battery status line as input
	WPUB |= 0b00000010; //battery status line pulled up (BATT_STAT1 is open collector on charger)
	IOCBP |= 0b00000010; //RB1 enabled as positive-edge interrupt-on-change pin
	IOCBN |= 0b00000010; //RB1 enabled as negative-edge interrupt-on-change pin
	
	//init battery level sensing
	BATT_VSENSE_TRIS = 1; //battery voltage sense as input
	BATT_VSENSE_GND_TRIS = 1; //battery voltage divider bottom as Hi-Z
	BATT_VSENSE_GND = 0; //preload battery voltage divider bottom to sink current
	
	FVRCON = 0b00000010; //disable FVR, comparator/DAC not fed, ADC fed with 2.048v.
	ADCON1 = 0b00000011; //left justified, FOSC/2, Vref- = Vss, Vref+ = FVR.
	ADCON0 = 0b00110000; //AN12, ADC OFF
	
	//init user interface
	//WPUB = 0b00011100; //enable internal pullups for all IOC pins (pulled up by resistors on Rev A board)
	SW1_TRIS = 1;
	SW2_TRIS = 1;
	SW3_TRIS = 1;
	IOCBN = 0b00011100; //RB4-RB2 enabled as negative-edge interrupt-on-change pins
	IOCBF = 0; //clear all pin-change interrupt flags
	IOCIF = 0; //clear the interrupt flag
	IOCIE = 1; //enable interrupt-on-change
	
	////generic 1ms tick timer
	T2CON = 0b00000011; //1:1, OFF, 1:64
	PR2 = 125; //makes for interval of 1ms
	TMR2IF = 0; //clear interrupt flag
	TMR2IE = 1; //enable timer2 interrupt
	
	//init state machine
	currentState = state_setTime;
	
	return 0;
}