Example #1
0
COLOUR GScreenDC::Colour(COLOUR c, int Bits)
{
	COLOUR Prev = Colour();

	if (Bits < 1) Bits = GetBits();
	c = CBit(24, c, Bits);
	
	rgb_color Rgb;
	Rgb.red = R24(c);
	Rgb.green = G24(c);
	Rgb.blue = B24(c);
	d->View->SetHighColor(Rgb);
	
	return Prev;
}
Example #2
0
int main(int argc, char *argv[]) {
	int debug = 0;
	int ret;

	{{{ // parse arguments
		struct option long_options[] = {
			{ "help", 0, 0, 0},
			{ 0, 0, 0, 0 }
		};

		while (1) {
			int opt_index=0;
			int c = getopt_long(argc, argv, "d", long_options, &opt_index);

			if (c == -1)
				break;

			switch (c) {
				case 0:
					if (opt_index==2) {
						usage(argv[0]);
					}
					break;
				case 'd':
					debug = 1;
					break;
				case '?':
					exit(EXIT_FAILURE);
				default:
					printf("??? getopt returned character code 0x%x ???\n", c);
			}
		}
	}}}

	// no output buffering please
	setbuf(stdout,0);

	printf("LED Display: clock program with game-of-life simulation\n");

	// initialise device
	if (ldisplay_init() != SUCCESS) {
		fprintf(stderr, "\033[1;31mDevice failed to initialise!\033[0m\n");
		return 1;
	}

	struct sigaction sigact = {
		.sa_handler = sighandler
	};

	// prepare for signals
	sigaction(SIGHUP, &sigact, NULL);
	sigaction(SIGINT, &sigact, NULL);

	// reset it to a known initial state
	if ((ret = ldisplay_reset())) {
		fprintf(stderr, "\033[1;31mDevice failed to reset: %d\033[0m\n", ret);
		ldisplay_cleanup();
		return 1;
	}

	ldisplay_setBrightness(LDISPLAY_DIM);

	int oldtime_int=0;
	time_t oldtime_t=0;

	uint32_t buffer[7] = {0};
	bool matrix[21][7];

	while (1) {
		time_t t = time(NULL);
		struct tm *curTime = localtime(&t);
		int time = (100*curTime->tm_hour) + curTime->tm_min;
		int i;
		uint32_t j;

		if (oldtime_int != time){
			/* Every minute, on the minute, set the time to the display */
			oldtime_t = t+1;
			oldtime_int = time;
			for (i=0; i<7; i++){
				buffer[i] = B24(00000, 00000000, 00000000);
			}
			_overlay(time_font_colon, buffer, 0, 0);
			_overlay(time_segment_font_digits[(time     )%10], buffer,   0, 0);
			_overlay(time_segment_font_digits[(time/10  )%10], buffer, - 5, 0);
			_overlay(time_segment_font_digits[(time/100 )%10], buffer, -12, 0);
			_overlay(time_segment_font_digits[(time/1000)%10], buffer, -17, 0);
		} else
		if ((buffer[0] | buffer[1] | buffer[2] | buffer[3] | buffer[4] | buffer[5] | buffer[6]) == 0){
			/* oops, display is empty. Add a lonely glider */
			buffer[0] = B24(00000, 00000000, 00000000);
			buffer[1] = B24(00000, 00000000, 00000000);
			buffer[2] = B24(00000, 00010000, 00000000);
			buffer[3] = B24(00000, 00001000, 00000000);
			buffer[4] = B24(00000, 00111000, 00000000);
			buffer[5] = B24(00000, 00000000, 00000000);
			buffer[6] = B24(00000, 00000000, 00000000);
		}
		ldisplay_setDisplay(buffer);

		if (debug == 1){
			printf("");
		}
		for(i=0; i<7; i++){
			uint32_t val;
			char s[22];
			sprintf(s, "                     ");
			j=0;
			val=buffer[i];
			while (val > 0){
				if (val & 1){
					s[21-j] = 'O';
					matrix[j][i] = true;
				} else {
					s[21-j] = ' ';
					matrix[j][i] = false;
				}
				j++;
				val = val >> 1;
			}
			if (debug == 1){
				printf("%s\n", s);
			}
		}

		usleep(100000);
		if (oldtime_t < t){
			oldtime_t = t;
		// Conways game of life
		bool newmatrix[21][7];
		for (i = 0; i<7; i++){
			for (j=0; j<21; j++){
				newmatrix[j][i] = matrix[j][i];
			}
		}

		for (i = 0; i<7; i++){
			buffer[i] = B24(00000, 00000000, 00000000);
			for (j=0; j<21; j++){
				int neighbors = 0;
				int l, r, t, b;
				if (i == 0){ t = 6; }
				else { t = i - 1; }
				if (i == 6){ b = 0; }
				else { b = i + 1; }
				if (j == 0){ l = 20; }
				else { l = j - 1; }
				if (j == 20){ r = 0; }
				else { r = j + 1; }
				if (matrix[l][t]) neighbors++;
				if (matrix[l][i]) neighbors++;
				if (matrix[l][b]) neighbors++;
				if (matrix[j][t]) neighbors++;
				//if (matrix[j][i]) neighbors++; // not counting ourself
				if (matrix[j][b]) neighbors++;
				if (matrix[r][t]) neighbors++;
				if (matrix[r][i]) neighbors++;
				if (matrix[r][b]) neighbors++;
				if (!(matrix[j][i])){
					if (neighbors == 3){
						newmatrix[j][i] = true;
					} else {
						newmatrix[j][i] = false;
					}
				} else {
					if (neighbors < 2){
						newmatrix[j][i] = false;
					} else if (neighbors <= 3){
						newmatrix[j][i] = true;
					} else {
						newmatrix[j][i] = false;
					}
				}
				// different ruleset
				/*
				if (neighbors % 2 == 0){
					matrix[i][j] = false;
				} else {
					matrix[i][j] = true;
				}
				*/
				buffer[i] |= (newmatrix[j][i] ? 1 << j : 0);
			}
		}
		for (i = 0; i<7; i++){
			for (j=0; j<21; j++){
				matrix[j][i] = newmatrix[j][i];
			}
		}
		}
	}

	ldisplay_reset();
	ldisplay_cleanup();
	return 0;
}
Example #3
0
int main(int argc, char *argv[]) {
  // no output buffering please
	setbuf(stdout,0);

  // no output if we are just performing an action
  canprint=(argc<2);

  rprintf("libleddisplay: LED Display Linux Showcase program\n");
  rprintf("Written by Dave Ingram\n");
  rprintf("---------------------------------------------------\n");
  rprintf("  http://www.dmi.me.uk/code/linux/leddisplay/      \n\n");

  // initialise device
	if (ldisplay_init() != SUCCESS) {
    fprintf(stderr, "\033[1;31mDevice failed to initialise!\033[0m\n");
    return 1;
  }

  rprintf("Connected to the display\n");
  rprintf("Resetting...\n");

  // only delay if required
  if (canprint)
    usleep(10000);

  // reset it to a known initial state
  ldisplay_reset();

  if (argc<2) {
    int32_t i;

#if 0
    uint32_t frame[10][7] = {
      {
        B24(10010, 01001001, 00100100),
        B24(00100, 10010010, 01001001),
        B24(01001, 00100100, 10010010),
        B24(10010, 01001001, 00100100),
        B24(00100, 10010010, 01001001),
        B24(01001, 00100100, 10010010),
        B24(10010, 01001001, 00100100)
      },

      {
        B24(01001, 00100100, 10010010),
        B24(10010, 01001001, 00100100),
        B24(00100, 10010010, 01001001),
        B24(01001, 00100100, 10010010),
        B24(10010, 01001001, 00100100),
        B24(00100, 10010010, 01001001),
        B24(01001, 00100100, 10010010)
      },

      {
        B24(00100, 10010010, 01001001),
        B24(01001, 00100100, 10010010),
        B24(10010, 01001001, 00100100),
        B24(00100, 10010010, 01001001),
        B24(01001, 00100100, 10010010),
        B24(10010, 01001001, 00100100),
        B24(00100, 10010010, 01001001)
      },

      {
        B24(10010, 01001001, 00100100),
        B24(00100, 10010010, 01001001),
        B24(01001, 00100100, 10010010),
        B24(10010, 01001001, 00100100),
        B24(00100, 10010010, 01001001),
        B24(01001, 00100100, 10010010),
        B24(10010, 01001001, 00100100)
      },

      {
        B24(01001, 00100100, 10010010),
        B24(10010, 01001001, 00100100),
        B24(00100, 10010010, 01001001),
        B24(01001, 00100100, 10010010),
        B24(10010, 01001001, 00100100),
        B24(00100, 10010010, 01001001),
        B24(01001, 00100100, 10010010)
      },

      {
        B24(00100, 10010010, 01001001),
        B24(01001, 00100100, 10010010),
        B24(10010, 01001001, 00100100),
        B24(00100, 10010010, 01001001),
        B24(01001, 00100100, 10010010),
        B24(10010, 01001001, 00100100),
        B24(00100, 10010010, 01001001)
      },

      {
        B24(10010, 01001001, 00100100),
        B24(00100, 10010010, 01001001),
        B24(01001, 00100100, 10010010),
        B24(10010, 01001001, 00100100),
        B24(00100, 10010010, 01001001),
        B24(01001, 00100100, 10010010),
        B24(10010, 01001001, 00100100)
      }

    };
#endif

    /*
    printf("All on...\n");
    for (i=0; i<5; i++) {
      setAll(1);
      usleep(400000);
    }
    */

    if (0) {
      //ldisplay__test__overlay();
    }

    if (1) {
      char *message[] = {
        "     ",
        "    I",
        "   In",
        "  Ini",
        " Init",
        "Initi",
        "nitia",
        "itial",
        "tiali",
        "ialis",
        "alisi",
        "lisin",
        "ising",
        "sing.",
        "ing..",
        "ng...",
        "g... ",
        "...  ",
        "..   ",
        ".    ",
        "    #",
        "   #@",
        "  #@$",
        " #@$%",
        "#@$%&",
        "@$%&=",
        "$%&= ",
        "%&=  ",
        "&=   ",
        "=    ",
        "     "
      };

      int m=0;
      for (m=0; m<31; m++) {
        ldisplay_showChars(message[m],  6); usleep(100000);
        ldisplay_showChars(message[m],  5); usleep(100000);
        ldisplay_showChars(message[m],  4); usleep(100000);
        ldisplay_showChars(message[m],  3); usleep(100000);
        ldisplay_showChars(message[m],  2); usleep(100000);
      }
    }

#if 0
    ldisplay_setBrightness(LDISPLAY_BRIGHT);
    for (i=10; i>=0; --i) {
      ldisplay_showTime(i, (i/10)%2);
      usleep(400000);
      ldisplay_showTime(i, (i/10)%2);
      usleep(400000);
    }

    int j=2;

    ldisplay_setBrightness(LDISPLAY_MEDIUM);
    printf("Animate...\n");
    while (j) {
      for (i=0; i<6; i++) {
        ldisplay_setDisplay(frame[i]);
        usleep(150000);
        /*
        setDisplay(frame[i]);
        usleep(400000);
        */
      }
      --j;
    }
#endif

    if (0) {
      ldisplay_setBrightness(LDISPLAY_DIM);
      printf("Current time (dim)\n");
      int oldtime_int=0;
      while (1) {
        time_t t = time(NULL);
        struct tm *curTime = localtime(&t);
        int curtime_int = (100*curTime->tm_hour) + curTime->tm_min;
        // check time again every few seconds
        for (i=0; i<5; ++i) {
          if (oldtime_int!=curtime_int)
            ldisplay_setBrightness(LDISPLAY_BRIGHT);
          ldisplay_showTime(curtime_int, 0);
          usleep(100000);
          if (oldtime_int!=curtime_int) {
            oldtime_int = curtime_int;
            ldisplay_setBrightness(LDISPLAY_DIM);
          }
          ldisplay_showTime(curtime_int, 0);
          usleep(300000);
        }
      }
    }

    usleep(500000);

    ldisplay_reset();

  } else {
    /*
    if        (strcmp(argv[1], "up")==0) {
      up();
    } else if (strcmp(argv[1], "down")==0) {
      down();
    } else if (strcmp(argv[1], "left")==0) {
      left();
    } else if (strcmp(argv[1], "right")==0) {
      right();
    } else if (strcmp(argv[1], "prime")==0) {
      prime();
    } else if (strcmp(argv[1], "fire")==0) {
      fire();
    } else {
      reset();
    }
    */
  }

  rprintf("Cleaning up...\n");

	ldisplay_cleanup();

  rprintf("Done.\n");

	return 0;
}
Example #4
0
int
main(int argc, char** argv)
{
  (void)argc;
  (void)argv;

  assert(32 == util_floor2(42));

  assert(B8(1) == 1);
  assert(B8(10) == 2);
  assert(B8(100) == 4);
  assert(B8(1000) == 8);
  assert(B8(10000) == 16);
  assert(B8(100000) == 32);
  assert(B8(1000000) == 64);

  assert(3 == util_cardinality(42));
  assert(3 == util_cardinality(41));
  assert(3 == util_cardinality(37));
  assert(3 == util_cardinality(35));

  for (unsigned v = 0; v < 256; ++v) {
    assert(morton_encode(v << 0 * CHAR_BIT) == morton_expand(v) << 0);
    assert(morton_encode(v << 1 * CHAR_BIT) == morton_expand(v) << 1);
    assert(morton_encode(v << 2 * CHAR_BIT) == morton_expand(v) << 2);
  }

  assert(0x249249 == util_part3(0xff));

  for (unsigned v = 0; v < 0x1000000; ++v) {
    assert(morton_decode(morton_encode(v)) == v);
  }

  assert(B24(00000000, 00000000, 00000000) ==
         morton_encode(B24(00000000, 00000000, 00000000)));
  assert(B24(00000000, 00000010, 01001001) ==
         morton_encode(B24(00000000, 00000000, 00001111)));
  assert(B24(00100100, 10010000, 00000000) ==
         morton_encode(B24(00000000, 00000000, 11110000)));
  assert(B24(00100100, 10010010, 01001001) ==
         morton_encode(B24(00000000, 00000000, 11111111)));

  assert(B24(00000000, 00000100, 10010010) ==
         morton_encode(B24(00000000, 00001111, 00000000)));
  assert(B24(00000000, 00000110, 11011011) ==
         morton_encode(B24(00000000, 00001111, 00001111)));
  assert(B24(00100100, 10010100, 10010010) ==
         morton_encode(B24(00000000, 00001111, 11110000)));
  assert(B24(00100100, 10010110, 11011011) ==
         morton_encode(B24(00000000, 00001111, 11111111)));

  assert(B24(01001001, 00100100, 10010010) ==
         morton_encode(B24(00000000, 11111111, 00000000)));
  assert(B24(01101101, 10110110, 11011011) ==
         morton_encode(B24(00000000, 11111111, 11111111)));

  assert(B24(10010010, 01001001, 00100100) ==
         morton_encode(B24(11111111, 00000000, 00000000)));
  assert(B24(10110110, 11011011, 01101101) ==
         morton_encode(B24(11111111, 00000000, 11111111)));
  assert(B24(11011011, 01101101, 10110110) ==
         morton_encode(B24(11111111, 11111111, 00000000)));

  assert(B24(11111111, 11111111, 11111111) ==
         morton_encode(B24(11111111, 11111111, 11111111)));

  return EXIT_SUCCESS;
}