/** * This function allocates and initializes a aa vout method. */ static int Open(vlc_object_t *object) { vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys; #ifndef _WIN32 if (!vlc_xlib_init (object)) return VLC_EGENERIC; #endif /* Allocate structure */ vd->sys = sys = calloc(1, sizeof(*sys)); if (!sys) return VLC_ENOMEM; /* Don't parse any options, but take $AAOPTS into account */ aa_parseoptions(NULL, NULL, NULL, NULL); /* */ sys->aa_context = aa_autoinit(&aa_defparams); if (!sys->aa_context) { msg_Err(vd, "cannot initialize aalib"); goto error; } vout_display_DeleteWindow(vd, NULL); aa_autoinitkbd(sys->aa_context, 0); aa_autoinitmouse(sys->aa_context, AA_MOUSEALLMASK); /* */ video_format_t fmt = vd->fmt; fmt.i_chroma = VLC_CODEC_RGB8; fmt.i_width = aa_imgwidth(sys->aa_context); fmt.i_height = aa_imgheight(sys->aa_context); fmt.i_visible_width = fmt.i_width; fmt.i_visible_height = fmt.i_height; /* Setup vout_display now that everything is fine */ vd->fmt = fmt; vd->info.has_pictures_invalid = true; vd->info.needs_event_thread = true; vd->pool = Pool; vd->prepare = Prepare; vd->display = PictureDisplay; vd->control = Control; vd->manage = Manage; /* Inspect initial configuration and send correction events * FIXME how to handle aspect ratio with aa ? */ vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height); return VLC_SUCCESS; error: if (sys && sys->aa_context) aa_close(sys->aa_context); free(sys); return VLC_EGENERIC; }
/***************************************************************************** * Destroy: destroy aa video thread output method ***************************************************************************** * Terminate an output method created by AaCreateOutputMethod *****************************************************************************/ static void Destroy( vlc_object_t *p_this ) { vout_thread_t *p_vout = (vout_thread_t *)p_this; aa_close( p_vout->p_sys->aa_context ); free( p_vout->p_sys ); }
AaScreen::~AaScreen() { func("%s", __PRETTY_FUNCTION__); if(ascii_context) aa_close(ascii_context); if(screen_buffer) free(screen_buffer); }
int bbinit(int argc, char **argv) { aa_defparams.supported|= AA_NORMAL_MASK | AA_BOLD_MASK | AA_DIM_MASK; aa_parseoptions(NULL, NULL, &argc, argv); if (argc != 1 && (argc != 2 || ((argv[1][0] <= '0' || argv[1][0] > '8') && strcmp(argv[1], "-loop")))) { printf("Usage: bb [aaoptions] [number]\n\n"); printf("Options:\n" " -loop play demo in infinite loop\n\n" "AAlib options:\n%s\n", aa_help); exit(1); } context = aa_autoinit(&aa_defparams); if (!context) { printf("Failed to initialize aalib\n"); exit(2); } if (!aa_autoinitkbd(context, 0)) { aa_close(context); printf("Failed to initialize keyboard\n"); exit(3); } if (argc == 2 && !strcmp(argv[1], "-loop")) loopmode = 1; else if (argc == 2) stage = atol(argv[1]); aa_hidecursor(context); return 1; }
static gboolean gst_aasink_close (GstAASink * aasink) { aa_close (aasink->context); aasink->context = NULL; return TRUE; }
//========================================================================= // MAIN PROGRAM //========================================================================= int main (int argc, char *argv[]) { Aardvark handle; int port = 0; int bitrate = 100; int res = 0; FILE *logfile = 0; if (argc < 2) { printf("usage: aalights PORT\n"); return 1; } port = atoi(argv[1]); // Open the device handle = aa_open(port); if (handle <= 0) { printf("Unable to open Aardvark device on port %d\n", port); printf("Error code = %d\n", handle); return 1; } // Enable logging logfile = fopen("log.txt", "at"); if (logfile != 0) { aa_log(handle, 3, fileno(logfile)); } // Ensure that the I2C subsystem is enabled aa_configure(handle, AA_CONFIG_SPI_I2C); // Enable the I2C bus pullup resistors (2.2k resistors). // This command is only effective on v2.0 hardware or greater. // The pullup resistors on the v1.02 hardware are enabled by default. aa_i2c_pullup(handle, AA_I2C_PULLUP_BOTH); // Power the board using the Aardvark adapter's power supply. // This command is only effective on v2.0 hardware or greater. // The power pins on the v1.02 hardware are not enabled by default. aa_target_power(handle, AA_TARGET_POWER_BOTH); // Set the bitrate bitrate = aa_i2c_bitrate(handle, I2C_BITRATE); printf("Bitrate set to %d kHz\n", bitrate); res = flash_lights(handle); if (res < 0) printf("error: %s\n", aa_status_string(res)); // Close the device and exit aa_close(handle); // Close the logging file fclose(logfile); return 0; }
/** * Close a aa video output method */ static void Close(vlc_object_t *object) { vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys = vd->sys; if (sys->pool) picture_pool_Release(sys->pool); aa_close(sys->aa_context); free(sys); }
//========================================================================= // MAIN PROGRAM //========================================================================= int main (int argc, char *argv[]) { Aardvark handle; int port = 0; u08 addr = 0; char *filename; int bitrate; if (argc < 4) { printf("usage: aai2c_file PORT SLAVE_ADDR filename\n"); printf(" SLAVE_ADDR is the target slave address\n"); printf("\n"); printf(" 'filename' should contain data to be sent\n"); printf(" to the downstream i2c device\n"); return 1; } port = atoi(argv[1]); addr = (u08)strtol(argv[2], 0, 0); filename = argv[3]; // Open the device handle = aa_open(port); if (handle <= 0) { printf("Unable to open Aardvark device on port %d\n", port); printf("Error code = %d\n", handle); return 1; } // Ensure that the I2C subsystem is enabled aa_configure(handle, AA_CONFIG_SPI_I2C); // Enable the I2C bus pullup resistors (2.2k resistors). // This command is only effective on v2.0 hardware or greater. // The pullup resistors on the v1.02 hardware are enabled by default. aa_i2c_pullup(handle, AA_I2C_PULLUP_BOTH); // Enable the Aardvark adapter's power pins. // This command is only effective on v2.0 hardware or greater. // The power pins on the v1.02 hardware are not enabled by default. aa_target_power(handle, AA_TARGET_POWER_BOTH); // Setup the bitrate bitrate = aa_i2c_bitrate(handle, I2C_BITRATE); printf("Bitrate set to %d kHz\n", bitrate); blast_bytes(handle, addr, filename); // Close the device aa_close(handle); return 0; }
SKYETEK_STATUS SPIDevice_Open(LPSKYETEK_DEVICE device) { LPSPI_INFO info; if( device == NULL || device->user == NULL ) return SKYETEK_INVALID_PARAMETER; if( device->readFD != 0 && device->writeFD != 0 ) return SKYETEK_SUCCESS; info = (LPSPI_INFO)device->user; info->spiHandle = aa_open(info->port_number); if( info->spiHandle < 1 ) { device->readFD = device->writeFD = 0; return SKYETEK_FAILURE; } if( info->type == AA_FEATURE_I2C ) { if( 0 > aa_configure(info->spiHandle, AA_CONFIG_GPIO_I2C) ) goto failure; aa_i2c_pullup(info->spiHandle, AA_I2C_PULLUP_BOTH); aa_i2c_bitrate(info->spiHandle, 400); } else { /* Set communication parameters */ if( 0 > aa_configure(info->spiHandle, AA_CONFIG_SPI_GPIO) ) goto failure; if( AA_OK != aa_spi_configure(info->spiHandle,AA_SPI_POL_FALLING_RISING,AA_SPI_PHASE_SETUP_SAMPLE,AA_SPI_BITORDER_MSB) ) goto failure; if( 0 > aa_spi_bitrate(info->spiHandle, 400) ) /* 400 kHz */ goto failure; if( AA_OK != aa_spi_master_ss_polarity(info->spiHandle, AA_SPI_SS_ACTIVE_LOW) ) goto failure; if( AA_OK != aa_gpio_direction(info->spiHandle, 0x00) ) goto failure; if( 0 > aa_gpio_pullup(info->spiHandle, 0x02) ) goto failure; } device->readFD = (SKYETEK_DEVICE_FILE)1; device->writeFD = (SKYETEK_DEVICE_FILE)1; return SKYETEK_SUCCESS; failure: aa_close(info->spiHandle); return SKYETEK_FAILURE; }
SKYETEK_STATUS SPIDevice_Close(LPSKYETEK_DEVICE device) { LPSPI_INFO info; if(device == NULL || device->user == NULL) return SKYETEK_INVALID_PARAMETER; info = (LPSPI_INFO)device->user; if( info->spiHandle < 1 ) return SKYETEK_INVALID_PARAMETER; aa_close(info->spiHandle); device->readFD = device->writeFD = 0; return SKYETEK_SUCCESS; }
int SPIDevice_Free(LPSKYETEK_DEVICE device) { LPSPI_INFO info; if( device == NULL || device->user == NULL ) return 0; info = (LPSPI_INFO)device->user; aa_close(info->spiHandle); MUTEX_DESTROY(&info->lock); free(info); device->user = NULL; return 1; }
int main() { context = aa_autoinit(&aa_defparams); if(context == NULL) { fprintf(stderr,"Cannot initialize AA-lib. Sorry\n"); return 1; } while(true) { aa_puts(context, 0, 10, AA_BOLDFONT, "Azerty is cooler dan qwerty"); aa_putpixel(context,50,50, ); aa_render(context, 50, 50, 100, 100); aa_flush(context); } aa_close(context); return 0; }
static void uninit(void) { /* * THE END */ if (strstr(c->driver->name,"Curses") || strstr(c->driver->name,"Linux")){ freopen("/dev/tty", "w", stderr); } if(vo_font_save) { free(vo_font->pic_a[0]->bmp); free(vo_font->pic_a[0]); free(vo_font->pic_b[0]->bmp); free(vo_font->pic_b[0]); free(vo_font); vo_font = vo_font_save; vo_font_save = NULL; } aa_close(c); }
/* Note: If we are terminated, this could be called in the middle of another SDL video routine -- notably UpdateRects. */ void AA_VideoQuit(_THIS) { int i; aa_uninitkbd(AA_context); aa_uninitmouse(AA_context); /* Free video mode lists */ for ( i=0; i<SDL_NUMMODES; ++i ) { if ( SDL_modelist[i] != NULL ) { SDL_free(SDL_modelist[i]); SDL_modelist[i] = NULL; } } aa_close(AA_context); SDL_DestroyMutex(AA_mutex); this->screen->pixels = NULL; }
int main(int argc, char* argv[]) { if (argc < 3) { fprintf(stderr, "Usage: %s IN_FILE OUT_FILE", argv[0]); exit(1); } MagickWand* m_wand; // Initialize MagickWandGenesis(); m_wand = NewMagickWand(); // read image if (MagickReadImage(m_wand, argv[1]) == MagickFalse) { fprintf(stderr, "Cannot read image: %s\n", argv[1]); exit(1); } // resize MagickResizeImage(m_wand, WIDTH, HEIGHT, LanczosFilter, 1.0); // ready for using AAlib aa_context* c; aa_savedata save_data = { argv[2], &aa_text_format, NULL }; // Initialize AAlib c = aa_init(&save_d, &aa_defparams, (const void*) &save_data); if (c == NULL) { fprintf(stderr, "Cannot initialize AA-lib\n"); exit(1); } // record image data to AAlib image buffer PixelIterator* iter = NewPixelIterator(m_wand); PixelWand** pix; unsigned long num_wands; double h, s, l; int x, y; y = 0; while ((pix = PixelGetNextIteratorRow(iter, &num_wands)) != NULL) { for (x = 0; x < num_wands; ++x) { PixelGetHSL(pix[x], &h, &s, &l); aa_putpixel(c, x, y, 256*l); } y++; } // rendering ascii and print file aa_fastrender(c, 0, 0, aa_scrwidth(c), aa_scrheight(c)); aa_flush(c); // terminate aa_close(c); // finalize to finish if (m_wand) { m_wand = DestroyMagickWand(m_wand); } MagickWandTerminus(); return 0; }
static void uninitialize (void) { aa_close (context); exit (0); }
int main(int argc, char **argv) { int help_flag = 0; int aahelp_flag = 0; int justoutput_flag = 0; int loadavg_flag = 0; int ipc_flag = 0; int port_num = DEFPORT; int max_iterations = 0; int delay = 0; int normal_load; int socket_fd = -1; float randomizestyletime = 0; float randomizesitetime = 0; char *endptr; setlocale(LC_ALL, ""); bindtextdomain("aajm", LOCALEDIR); textdomain("aajm"); char options[] = "aljhip:n:d:m:t:s:T:S:"; static struct option long_options[] = { {"help", no_argument, &help_flag, 1}, {"aahelp", no_argument, &aahelp_flag, 1}, {"justoutput", no_argument, &justoutput_flag, 1}, {"ipc", no_argument, &ipc_flag, 1}, {"loadavg", no_argument, &loadavg_flag, 1}, {"maxiterations", required_argument, 0, 'm'}, {"port", required_argument, 0, 'p'}, {"normalload", required_argument, 0, 'n'}, {"delay", required_argument, 0, 'd'}, {"siteswap", required_argument, 0, 's'}, {"style", required_argument, 0, 't'}, {"rstyle", required_argument, 0, 'S'}, {"rsiteswap", required_argument, 0, 'T'}, {0,0,0,0} }; normal_load = (int)(DEFLOAD * 100); char optch; int option_index = 0; //jmlib = new JMLib(errorCB); jmlib = JMLib::alloc(); jmlib->setPatternDefault(); jmlib->setStyleDefault(); jmlib->startJuggle(); aa_parseoptions(NULL, NULL, &argc, argv); while( (optch = getopt_long(argc,argv,options, long_options,&option_index)) != -1) switch(optch) { case 's': jmlib->setPattern("Something",optarg, HR_DEF, DR_DEF); break; case 't': jmlib->setStyle(optarg); break; case 'S': randomizesitetime = strtod(optarg, &endptr); if (endptr==optarg || *endptr != 0) { randomizesitetime = DEFRANDOMSITETIME; } break; case 'T': randomizestyletime = strtod(optarg, &endptr); if (endptr==optarg || *endptr != 0) { randomizestyletime = DEFRANDOMSTYLETIME; } break; case 'h': help_flag=1; break; case 'a': aahelp_flag=1; break; case 'j': justoutput_flag=1; break; case 'm': max_iterations = atoi(optarg); break; case 'd': delay = atoi(optarg); break; case 'l': loadavg_flag=1; break; case 'n': normal_load = (int)(100*atof(optarg)); break; case 'i': ipc_flag=1; break; case 'p': port_num=atoi(optarg); break; } if(aahelp_flag || help_flag) { printf(gettext("AAJM, An ASCII Art Juggling program\n")); printf(gettext("Usage: %s [OPTIONS]\n"),argv[0]); } if(help_flag) { printf(gettext("Jugglemaster Options:\n")); printf(gettext(" -s, --siteswap=XX show siteswap XX (3)\n")); printf(gettext(" -t, --style=XX use style XX (\"Normal\")\n")); printf(gettext(" -S, --rsiteswap=XX Randomize siteswap every XX seconds (%f)\n"), DEFRANDOMSITETIME); printf(gettext(" -T, --rstyle=XX Randomize style every XX seconds (%f)\n"), DEFRANDOMSTYLETIME); printf(gettext(" -d, --delay=XX delay XX ms between frames (%i)\n"), (int)DEFSPEED/1000); printf(gettext(" -m, --maxiterations=XX do at most XX iterations\n")); printf(gettext(" -j, --justoutput only output [don't init kb or mouse]\n")); printf(gettext(" -i, --ipc enable IPC\n")); printf(gettext(" -p, --port=XX use port XX for IPC (%i)\n"),DEFPORT); printf(gettext(" -l, --loadavg change speed based on load average\n")); printf(gettext(" -n, --normalload=XX a normal load average for your machine (%2.2f)\n"),DEFLOAD); printf(gettext(" -h, --help get help [this screen]\n")); printf(gettext(" -a, --aahelp get help on AA options\n\n")); } if(aahelp_flag) { printf(gettext("AALib Options:\n%s\n\n"),aa_help); } if(aahelp_flag || help_flag) { return 0; } context = aa_autoinit(&aa_defparams); if (context == NULL) { printf(gettext("Failed to initialize aalib\n")); exit(1); } if(!justoutput_flag) { aa_autoinitkbd(context, 0); aa_hidecursor(context); } params = aa_getrenderparams(); jmlib->setWindowSize(aa_imgwidth(context),aa_imgheight(context)); jmlib->startJuggle(); aa_resizehandler(context, resizehandler); if(loadavg_flag) { /* If we're doing that thing where we care, then this can go down to as-low-as-possible priority */ nice(19); } if(ipc_flag) { socket_fd = startlistening(port_num); } main_loop(max_iterations,delay,loadavg_flag,normal_load, socket_fd, randomizestyletime, randomizesitetime); if(socket_fd > 0) { stoplistening(socket_fd); } aa_close(context); delete jmlib; return 1; }
int bb(void) { aa_gotoxy(context, 0, 0); introscreen(); params = aa_getrenderparams(); aa_render(context, params, 0, 0, 1, 1); font = uncompressfont( /*context->params.font */ &aa_font16); scenetimer = tl_create_timer(); srand(time(NULL)); if (stage != 1) finish_stuff = 1; do switch (stage) { default: case 1: load_song("bb.s3m"); bbupdate(); starttime = endtime = TIME; scene1(); scene3(); if (quitnow) goto quit; vezen(&fk1, &fk2, &fk3, &fk4); messager("FILIP KUPSA known as FK, Tingle Notions, Dawn Music\n" "birth: June 22 1979, Tabor, Czech Republic, sex: male\n" "\n" "1992 - Changed his piano for 386/mp.com/pc-speaker music\n" "1993 - Got his first Sound Blaster\n" "1995 - Changed his SB for a new GUS technology\n" "1996 - Composed his first great hits\n" "1996 - FAT recomposition made by Windows 95\n" "1997 - Released his musac in BB\n" "\n" "1998 - Got retired\n" "\n" "Contact address: via KT"); devezen2(); scene4(); scene2(); if (quitnow) goto quit; vezen(&ms1, &ms2, &ms3, &ms4); messager("MOJMIR SVOBODA known as MS, TiTania, MSS, Bill\n" "birth: ??, Tabor, Czech Republic, sex: ? male ?\n" "\n" "1993 - Installed Linux on his 386sx/25 + 40MB HDD\n" "1994 - Removed Linux to make space for Doom\n" "1995 - Reinstalled Linux on his 486Dx4/120 + 850MB\n" "1996 - Removed Linux to make space for Windows 95\n" "\n" "1997 - Removed Windows 95 to make space for aalib\n" "\n" "Contact address: [email protected]"); devezen3(); scene8(); scene6(); case 2: if (quitnow) goto quit; vezen(&kt1, &kt2, &kt3, &kt4); messager("KAMIL TOMAN known as KT, Kato, Whale, Bart\n" "birth: May 19 1979, Tabor, Czech Republic, sex: male\n" "\n" "1993 - Became a linux extremist\n" "1993 - Successful attempt to establish a secret organization\n" " Commandline Brotherhood\n" "1995 - Action 'koules' - a secret project to train brotherhood\n" " members - covered under a game design\n" "\n" "1998 - Heading a new wave of command line revolution\n" "\n" "Contact address: [email protected]"); bbupdate(); starttime = endtime = TIME; devezen1(); if (quitnow) goto quit; scene7(); if (quitnow) goto quit; scene5(); if (quitnow) goto quit; scene10(); vezen(&hh1, &hh2, &hh3, &hh4); messager("JAN HUBICKA known as HH, Jahusoft, HuJaSoft, JHS, UNIX, Honza\n" "birth: Apr 1 1978, Tabor, Czech Republic, sex: male\n" "\n" "1991 - Installed underground hackers OS Linux\n" "1995 - Headed Action 'koules'\n" "1996 - Famous troan XaoS to convert all windows instalations\n" " into Linux\n" "\n" "1998 - Secret plan to make `Text Windows` system to confuse users\n" "2001 - Planning an assassination of dictator Bill G.\n" "\n" "Contact address: [email protected]"); devezen4(); if (quitnow) goto quit; credits(); if (quitnow) goto quit; case 3: if (loopmode) break; credits2(); } while (loopmode); quit:; aa_close(context); return (0); }
status_t AalibTranslator::DerivedTranslate(BPositionIO *source, const translator_info *info, BMessage *ioExtension, uint32 outType, BPositionIO *target, int32 baseType) { if(baseType == 1 && outType == AALIB_TEXT_FORMAT) { BBitmap *originalbmp, *greyscalebmp; BRect bounds; int imgWidth; int imgHeight; int imgHalfWidth; int imgHalfHeight; aa_context *context; aa_renderparams *params; aa_palette palette; struct aa_hardware_params hwparams; // get the image originalbmp = BTranslationUtils::GetBitmap(source); if(originalbmp == NULL) { return B_ERROR; } // get the image size bounds = originalbmp->Bounds(); imgWidth = bounds.IntegerWidth()+1; imgHeight = bounds.IntegerHeight()+1; // convert the bitmap to greyscale greyscalebmp = new BBitmap(bounds, B_GRAY8); if(greyscalebmp->ImportBits(originalbmp) != B_OK) { return B_ERROR; } // get half the height and width, rounded up // aalib outputs half the height and width of the original if(imgWidth%2 == 1) imgHalfWidth = (imgWidth+1)/2; else imgHalfWidth = imgWidth/2; if(imgHeight%2 == 1) imgHalfHeight = (imgHeight+1)/2; else imgHalfHeight = imgHeight/2; // use some custom settings memcpy(&hwparams, &aa_defparams, sizeof(struct aa_hardware_params)); hwparams.font = NULL; // default font // output is half of original width and height hwparams.width = imgHalfWidth; hwparams.height = imgHalfHeight; // new aalib context // use mem_d (memory drive) as we will get the output ourselves context = aa_init(&mem_d, &hwparams, NULL); if(context == NULL) return B_ERROR; // we can't use memcpy, as the image width // might not be equal to the bytes per row /*memcpy(context->imagebuffer, greyscalebmp->Bits(), imgWidth*imgHeight);*/ // get the location of the bitmap bits, and the bytes per row unsigned char *bitsLocation = (unsigned char*)greyscalebmp->Bits(); int bytesPerRow = greyscalebmp->BytesPerRow(); for(int y=0; y<imgHeight; y++) { // for each row and column for(int x=0; x<imgWidth; x++) { // set the pixel // 255- is to invert the greyscale image aa_putpixel(context, x, y, 255-(bitsLocation[y*bytesPerRow+x])); } } // render the image params = aa_getrenderparams(); aa_render(context, params, 0, 0, imgWidth, imgHeight); for(int i=0; i<imgHalfHeight; i++) { // for each row if(i != 0) { // after first line, write newline target->Write("\n",1); } // output that line target->Write(context->textbuffer+i*imgHalfWidth,imgHalfWidth); } aa_close(context); free(originalbmp); delete greyscalebmp; delete originalbmp; return B_OK; } return B_NO_TRANSLATOR; }
static void aarenderer_close() { aa_close(context); }
int main(int argc, char **argv) { aa_context *c; int i, y; char s[256]; aa_renderparams *p; strcpy(s, "line editor."); if (!aa_parseoptions(NULL, NULL, &argc, argv) || argc != 1) { printf("%s\n", aa_help); exit(1); } c = aa_autoinit(&aa_defparams); if (c == NULL) { printf("Can not intialize aalib\n"); exit(2); } if (!aa_autoinitkbd(c, 0)) { printf("Can not intialize keyboard\n"); aa_close(c); exit(3); } for (i = 0; i < aa_imgwidth(c); i++) for (y = 0; y < aa_imgheight(c); y++) aa_putpixel(c, i, y, i + y < 80 ? i : ((i + y) < 100 ? (i + y == 89 ? 150 : 0) : y * 8)); aa_hidecursor(c); aa_fastrender(c, 0, 0, aa_scrwidth(c), aa_scrheight(c)); aa_printf(c, 0, 0, AA_SPECIAL, "Fast rendering routine %i",1); aa_flush(c); aa_getkey(c, 1); aa_edit(c, 0, 1, 20, s, 256); aa_puts(c, 0, 0, AA_SPECIAL, "Key lookup test "); aa_flush(c); int ch; while ((ch = aa_getevent(c, 1)) != ' ') { char s[80]; sprintf(s, "Key event test-space to exit. c:%i", ch); aa_puts(c, 0, 0, AA_SPECIAL, s); aa_flush(c); } if (aa_autoinitmouse(c, AA_MOUSEALLMASK)) { int co = 0; sprintf(s, "Mouse test-space to exit"); aa_puts(c, 0, 0, AA_SPECIAL, s); aa_flush(c); while (aa_getevent(c, 1) != ' ') { int x, y, b; char s[80]; co++; aa_getmouse(c, &x, &y, &b); sprintf(s, "Mouse test-space to exit. x:%i y:%i b:%i event #%i ", x, y, b, co); aa_puts(c, 0, 0, AA_SPECIAL, s); aa_flush(c); } aa_hidemouse(c); while (aa_getevent(c, 1) != ' ') { int x, y, b; char s[80]; co++; aa_getmouse(c, &x, &y, &b); sprintf(s, "Hidden mouse test-space to exit. x:%i y:%i b:%i event #%i ", x, y, b, co); aa_puts(c, 0, 0, AA_SPECIAL, s); aa_flush(c); } aa_uninitmouse(c); } p = aa_getrenderparams(); for (i = 0; i < AA_DITHERTYPES; i++) { p->dither = i; aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c)); aa_puts(c, 0, 0, AA_SPECIAL, aa_dithernames[i]); aa_flush(c); aa_getkey(c, 1); } for (i = 0; i < 255; i += 32) { p->bright = i; aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c)); aa_puts(c, 0, 0, AA_SPECIAL, "Normal rendering - bright changes"); aa_flush(c); aa_getkey(c, 1); } p->bright = 0; for (i = 0; i < 128; i += 16) { p->contrast = i; aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c)); aa_puts(c, 0, 0, AA_SPECIAL, "Normal rendering - contrast changes"); aa_flush(c); aa_getkey(c, 1); } p->contrast = 0; for (i = 0; i < 255; i += 32) { p->gamma = 1 + i / 32.0; aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c)); aa_puts(c, 0, 0, AA_SPECIAL, "Normal rendering - gamma changes"); aa_flush(c); aa_getkey(c, 1); } p->gamma = 1.0; for (i = 0; i < 255; i += 32) { p->randomval = i; aa_render(c, p, 0, 0, aa_scrwidth(c), aa_scrheight(c)); aa_puts(c, 0, 0, AA_SPECIAL, "Normal rendering - randomval changes"); aa_flush(c); aa_getkey(c, 1); } aa_close(c); return 0; }
//========================================================================= // MAIN PROGRAM //========================================================================= int main (int argc, char *argv[]) { Aardvark handle; int port = 0; u08 addr = 0; int timeout_ms = 0; u08 slave_resp[SLAVE_RESP_SIZE]; int i; /* if (argc < 4) { printf("usage: aai2c_slave PORT SLAVE_ADDR TIMEOUT_MS\n"); printf(" SLAVE_ADDR is the slave address for this device\n"); printf("\n"); printf(" The timeout value specifies the time to\n"); printf(" block until the first packet is received.\n"); printf(" If the timeout is -1, the program will\n"); printf(" block indefinitely.\n"); return 1; } */ /* port = atoi(argv[1]); addr = (u08)strtol(argv[2], 0, 0); timeout_ms = atoi(argv[3]); */ port = 0; //atoi(argv[1]); addr = 0x08; //(u08)strtol(argv[5], 0, 0); timeout_ms = 1*1000; //atoi(argv[6]); // Open the device handle = aa_open(port); if (handle <= 0) { printf("Unable to open Aardvark device on port %d\n", port); printf("Error code = %d\n", handle); return 1; } // Ensure that the I2C subsystem is enabled aa_configure(handle, AA_CONFIG_SPI_I2C); // Disable the Aardvark adapter's power pins. // This command is only effective on v2.0 hardware or greater. // The power pins on the v1.02 hardware are not enabled by default. aa_target_power(handle, AA_TARGET_POWER_NONE); // Set the slave response; this won't be used unless the master // reads bytes from the slave. for (i=0; i<SLAVE_RESP_SIZE; ++i) slave_resp[i] = 'A' + i; //No response: aa_i2c_slave_set_response(handle, SLAVE_RESP_SIZE, slave_resp); aa_i2c_slave_set_response(handle, 0, NULL); // Enable the slave aa_i2c_slave_enable(handle, addr, 0, 0); // Watch the I2C port printf("Press 'q' to exit the program!!! \n"); do { dump(handle, timeout_ms); } while(getch_noblock() != 'q' ); // Disable the slave and close the device aa_i2c_slave_disable(handle); aa_close(handle); return 0; }
//========================================================================= // MAIN PROGRAM //========================================================================= int main (int argc, char *argv[]) { Aardvark handle; int port = 0; int bitrate = 100; u08 device; u08 addr; u16 length; int bus_timeout; const char *command; if (argc < 7) { printf("usage: aai2c_eeprom PORT BITRATE read SLAVE_ADDR OFFSET LENGTH\n"); printf("usage: aai2c_eeprom PORT BITRATE write SLAVE_ADDR OFFSET LENGTH\n"); printf("usage: aai2c_eeprom PORT BITRATE zero SLAVE_ADDR OFFSET LENGTH\n"); return 1; } port = atoi(argv[1]); bitrate = atoi(argv[2]); command = argv[3]; device = (u08)strtol(argv[4], 0, 0); addr = (u08)strtol(argv[5], 0, 0); length = atoi(argv[6]); // Open the device handle = aa_open(port); if (handle <= 0) { printf("Unable to open Aardvark device on port %d\n", port); printf("Error code = %d\n", handle); return 1; } // Ensure that the I2C subsystem is enabled aa_configure(handle, AA_CONFIG_SPI_I2C); // Enable the I2C bus pullup resistors (2.2k resistors). // This command is only effective on v2.0 hardware or greater. // The pullup resistors on the v1.02 hardware are enabled by default. aa_i2c_pullup(handle, AA_I2C_PULLUP_BOTH); // Power the EEPROM using the Aardvark adapter's power supply. // This command is only effective on v2.0 hardware or greater. // The power pins on the v1.02 hardware are not enabled by default. aa_target_power(handle, AA_TARGET_POWER_BOTH); // Set the bitrate bitrate = aa_i2c_bitrate(handle, bitrate); printf("Bitrate set to %d kHz\n", bitrate); // Set the bus lock timeout bus_timeout = aa_i2c_bus_timeout(handle, BUS_TIMEOUT); printf("Bus lock timeout set to %d ms\n", bus_timeout); // Perform the operation if (strcmp(command, "write") == 0) { _writeMemory(handle, device, addr, length, 0); printf("Wrote to EEPROM\n"); } else if (strcmp(command, "read") == 0) { _readMemory(handle, device, addr, length); } else if (strcmp(command, "zero") == 0) { _writeMemory(handle, device, addr, length, 1); printf("Zeroed EEPROM\n"); } else { printf("unknown command: %s\n", command); } // Close the device and exit aa_close(handle); return 0; }