Beispiel #1
0
inline static void _draw_char(int c, uint32_t x, uint32_t y, uint16_t fore, uint16_t back) {
	uint32_t i, j;
	uint8_t line;
	unsigned char *p = (unsigned char *) cp437_font + (c * (int) FONT_CHAR_H);

	uint16_t buffer[FONT_CHAR_H * FONT_CHAR_W];
	uint16_t *q = buffer;

	for (i = 0; i < FONT_CHAR_H; i++) {
		line = (uint8_t) *p++;
		for (j = 0; j < FONT_CHAR_W; j++) {
			if ((line & 0x1) != 0) {
				*q = __builtin_bswap16(fore);
			} else {
				*q = __builtin_bswap16(back);
			}
			line >>= 1;
			q++;
		}
	}

	write_command(0x2A);
	write_data_word(x);
	write_data_word(x + FONT_CHAR_H - 1);
	write_command(0x2B);
	write_data_word(y);
	write_data_word(y + FONT_CHAR_W - 1);
	write_command(0x2C);

	bcm2835_spi_writenb((char *) buffer, 2 * FONT_CHAR_H * FONT_CHAR_W);
}
void Display_Clear_Rect(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int co)
{
	int i, j;


    write_command(0x2a);
	write_data(x>>8&0xff);write_data(x&0xff);
	x += w -1;
	write_data(x>>8&0xff);write_data(x&0xff);
    write_command(0x2b);
	write_data((y)>>8&0xff);write_data((y)&0xff);
	y += h - 1;
	write_data((y)>>8&0xff);write_data((y)&0xff);
	write_command(0x2C);
	for (j=0; j<h; j++) {
		for (i=0; i<w; i++)	{
			LCD_DataWrite(co>>8&0xff, co&0xff);	
		}
  	}
#if 0
	write_command(0x2a);
	write_data(0);write_data(0);
	write_data(W>>8&0xff);write_data(W&0xff);
    write_command(0x2b);
	write_data(0);write_data(0);
	write_data(H>>8&0XFF);write_data(H);
#endif
}
void LCD_ExitSleep_ILI9340C(void)
{
  write_command(0x11);//Exit Sleep
  delay(120);
  write_command(0x29);//Display on
  write_command(0x2C);
}
Beispiel #4
0
void main(){
	init_lcd();
	clear_screen();
	choose_screen(1);
	write_command(x|0);
	write_command(y|0);
	write_data(0x01<<0);
	while(1);
}
void addset(unsigned int x,unsigned int y)
{

	write_command(ILI9341_CASET); // Column addr set
	wr_com16(x>>8,x);
	write_command(ILI9341_PASET); // Row addr set
	wr_com16(y>>8,y);
	write_command(ILI9341_RAMWR); // write to RAM
}
 void Address_set (unsigned int x1, unsigned int x2, unsigned int y1, unsigned int y2)
 {
	     write_command (0x2a); // x -axis
	     write_data (x1);
	     write_data (x2);
         write_command(0x2b); // y -axis
         write_data (y1);
         write_data (y2);
         write_command(0x2c);
 }
Beispiel #7
0
void clear_screen(){
	unsigned char x,y;
	choose_screen(0);
	for(x=0xb8;x<0xc0;x++){
		write_command(x);
		write_command(0x40);
		for(y=0;y<64;y++){
			write_data(0);
		}
	}
}
Beispiel #8
0
void ili9340_clear(void) {
	write_command(0x2A);
	write_data_word(0);
	write_data_word(239);
	write_command(0x2B);
	write_data_word(0);
	write_data_word(319);
	write_command(0x2C);

	bcm2835_spi_writenb((char *) buffer, 2 * ILI9340_HEIGHT * ILI9340_WIDTH);
}
Beispiel #9
0
int hokuyo_init(HokuyoLaser* hokuyoLaser){
    if (hokuyoLaser->fd<=0){
        return -1;
    }


#ifdef HOKUYO_ALWAYS_IN_SCIP20
  fprintf(stderr, "\nAssuming laser is already in SCIP2.0 mode!\n");
  fprintf(stderr, " (if the dirver hangs, either your Hokuyo has the old\n");
  fprintf(stderr, " firmware or you have to disable -DHOKUYO_ALWAYS_IN_SCIP20\n");
  fprintf(stderr, " in the Makefile of the laser driver)\n");

  hokuyoLaser->isContinuous=0;
  hokuyoLaser->isProtocol2=1;
#else

  // stop the  device anyhow

  fprintf(stderr, "Stopping the device... ");
  write_command(hokuyoLaser,HK_QUIT);
  write_command(hokuyoLaser,HK_QUIT);
  write_command(hokuyoLaser,HK_QUIT);
  fprintf(stderr, "done\n");
  hokuyoLaser->isContinuous=0;

  // The UTM-30LX functions only in SCIP2.0 Mode, as do some URG's
  fprintf(stderr, "Switching to enhanced mode (SCIP2.0)... ");
  fprintf(stderr, " (if the dirver hangs you probably configured your Hokuyo\n");
  fprintf(stderr, " so that SCIP is alwas on. IN this case, enable the Option\n");
  fprintf(stderr, " CFLAGS += -DHOKUYO_ALWAYS_IN_SCIP20\n");
  fprintf(stderr, " in the Makefile of the laser driver)\n");


  int status=hokuyo_readStatus(hokuyoLaser, HK_SCIP,1);
  if (status==0){
      fprintf(stderr, "\nSwitching to SCIP 2.0 was successful!\n");
      hokuyoLaser->isProtocol2=1;
  } else {
      fprintf(stderr, "Error. Unable to switch to SCIP2.0 Mode, please upgrade the firmware of your device.\n");
      return -1;
  }

#endif
  fprintf(stderr, "Device initialized successfully\n");
  hokuyoLaser->isInitialized=1;

  hokuyo_readStatus(hokuyoLaser, "\nVV\n", 1);
  hokuyo_readStatus(hokuyoLaser, "\nPP\n", 1);
  hokuyo_readStatus(hokuyoLaser, "\nII\n", 1);

  return 1;
}
Beispiel #10
0
void Display_Clear(unsigned int co)
{
 unsigned char i,j;
 write_command(0x2a);
 write_data(0x00);write_data(0x00);
 write_command(0x2b);
 write_data(0x00);write_data(0x00);

 write_command(0x2C);
 for (i=0;i<H;i++)
    for (j=0;j<W;j++)
        LCD_DataWrite(co>>8&0xff, co&0xff);
}
Beispiel #11
0
int main(int argc, char** argv) {
    if (argc < 3) {
        printf("Usage: jattach <pid> <cmd> <args> ...\n");
        return 1;
    }
    
    int pid = atoi(argv[1]);
    if (!check_socket(pid) && !start_attach_mechanism(pid)) {
        printf("Could not start attach mechanism\n");
        return 1;
    }

    int fd = connect_socket(pid);
    if (fd == -1) {
        printf("Could not connect to socket\n");
        return 1;
    }
    
    printf("Connected to remote JVM\n");
    write_command(fd, argc - 2, argv + 2);

    printf("Response code = ");
    read_response(fd);

    printf("\n");
    close(fd);
    
    return 0;
}
int main(int argc,char *argv[])
{
  if(argc < 3) return usage(argc, argv);

  // set and check device name
  char* tmp=argv[1];
  if(strcmp(tmp,"1") && strcmp(tmp,"2")) return usage(argc, argv);
  char devname[12];
  sprintf(devname, "/dev/schar%s",tmp);
  printf("devname %s\n",devname);
  
  int commandnum = atoi( argv[2] );
  printf("commandnum=%d\n",commandnum);

  int adrnum = 0;
  if (argc > 3){
    adrnum = atoi( argv[3] );
    printf("adrnum=%02x\n",adrnum);
  }

  // open device
  eth_open(devname);
  eth_register_mac();
  
  int e=write_command(commandnum,adrnum);
  
  // close device
  eth_close();
  
  return e;
}
Beispiel #13
0
void ili9340_draw_pixel(uint16_t x, uint16_t y, uint16_t color) {
	if (x >= ILI9340_HEIGHT)
		return;

	if (y >= ILI9340_WIDTH)
		return;

	write_command(0x2A);
	write_data_word(x);
	write_data_word(x);
	write_command(0x2B);
	write_data_word(y);
	write_data_word(y);
	write_command(0x2C);
	write_data_word(color);
}
void process_command(char *command)
{
  char *token;
  char *search = " ";
  strtok(command, "\n");

  token = strtok(command, search);

  if (strcmp(token, "download") == 0) {
    token = strtok(NULL, search);
    int download_id = atoi(token);
    if (in_download_range(download_id)) {
      printf("Downloading %i", download_id);
      write_command(download_id);
      current_download = download_id;
      global_state = GotIndex;
    }
    else {
      printf("Log ID %i outside available range\n", download_id);
      need_input = true;
    }
  }
  else if (strcmp(token, "exit") == 0) {
    keep_running = false;
  }
  else {
    printf("Possible commands:\n"
           "  download <lognumber>\n"
           "  help\n"
           "  exit\n");
    need_input = true;
  }
}
Beispiel #15
0
int adjust_time()
{
  long heure_serveur, heure_locale;
  int res,code;
  char *buf;

  Date_offset=0;
  write_command(CMD_DATE, 0, NULL);
  res=read_server_with_reconnect(tcp_line_read, 3, MAX_READ_SIZE-1);
  if (debug) fprintf(stderr,"Yo :%s\n",tcp_line_read);
  if (res<0) return -1;
  buf=strchr(tcp_line_read,' ');
  code = time(NULL);
  if (buf) {
    code=strtol(buf+9,&buf,10);
    heure_serveur=code %100 + 60*(((code/100)%100) + 60*(((code/10000)%100)));
  } else
    heure_serveur=code;

  heure_locale=time(NULL);
/*  heure_locale = mktime(gmtime(&heure_locale))%86400; */
  Date_offset = ((heure_serveur - heure_locale)%86400);
  if (Date_offset > 43200) Date_offset = Date_offset - 86400;
  if (Date_offset < -43200) Date_offset = Date_offset + 86400;
  if (debug)
    fprintf(stderr,"Yu :%ld %ld %d\n",heure_serveur,
	heure_locale,Date_offset);
  return 0;
}
Beispiel #16
0
static void network_shutdown(struct iio_context *ctx)
{
	struct iio_context_pdata *pdata = ctx->pdata;
	unsigned int i;

	iio_mutex_lock(pdata->lock);
	write_command("\r\nEXIT\r\n", pdata->fd);
	close(pdata->fd);
	iio_mutex_unlock(pdata->lock);

	for (i = 0; i < ctx->nb_devices; i++) {
		struct iio_device *dev = ctx->devices[i];
		struct iio_device_pdata *dpdata = dev->pdata;

		if (dpdata) {
			network_close(dev);
			iio_mutex_destroy(dpdata->lock);
			free(dpdata);
		}
	}

	iiod_client_destroy(pdata->iiod_client);
	iio_mutex_destroy(pdata->lock);
	freeaddrinfo(pdata->addrinfo);
	free(pdata);
}
Beispiel #17
0
/**
 * open_stream_for_write_2
 * @filename: Filename of new stream
 * @geom_filename: The geometry filename to copy
 * @argc: The number of arguments to the program
 * @argv: The arguments to the program
 *
 * Creates a new stream with name @filename, and adds the stream format
 * and version header, plus a verbatim copy of the geometry file
 *
 * You may want to follow this with a call to write_command() to record the
 * command line.
 *
 * Returns: a %Stream, or NULL on failure.
 */
Stream *open_stream_for_write_2(const char *filename,
                                const char *geom_filename, int argc,
                                char *argv[])

{
	Stream *st;

	st = malloc(sizeof(struct _stream));
	if ( st == NULL ) return NULL;

	st->fh = fopen(filename, "w");
	if ( st->fh == NULL ) {
		ERROR("Failed to open stream.\n");
		free(st);
		return NULL;
	}

	st->major_version = LATEST_MAJOR_VERSION;
	st->minor_version = LATEST_MINOR_VERSION;

	fprintf(st->fh, "CrystFEL stream format %i.%i\n",
	        st->major_version, st->minor_version);
	fprintf(st->fh, "Generated by CrystFEL "CRYSTFEL_VERSIONSTRING"\n");
	fflush(st->fh);

	if ( (argc > 0) && (argv != NULL) ) {
		write_command(st, argc, argv);
	}
	if ( geom_filename != NULL ) {
		write_geometry_file(st, geom_filename);
	}

	return st;
}
Beispiel #18
0
static long exec_command(const char *cmd, int fd)
{
	long resp;
	ssize_t ret = write_command(cmd, fd);
	if (ret < 0)
		return (long) ret;

	DEBUG("Reading response\n");
	ret = read_integer(fd, &resp);
	if (ret < 0) {
		char buf[1024];
		iio_strerror(-ret, buf, sizeof(buf));
		ERROR("Unable to read response: %s\n", buf);
		return (long) ret;
	}

#if LOG_LEVEL >= DEBUG_L
	if (resp < 0) {
		char buf[1024];
		iio_strerror(-resp, buf, sizeof(buf));
		DEBUG("Server returned an error: %s\n", buf);
	}
#endif

	return resp;
}
Beispiel #19
0
static int network_close(const struct iio_device *dev)
{
	struct iio_device_pdata *pdata = dev->pdata;
	int ret = -EBADF;

	iio_mutex_lock(pdata->lock);

	if (pdata->fd >= 0) {
		ret = iiod_client_close_unlocked(dev->ctx->pdata->iiod_client,
				pdata->fd, dev);

		write_command("\r\nEXIT\r\n", pdata->fd);

		close(pdata->fd);
		pdata->fd = -1;
	}

#ifdef WITH_NETWORK_GET_BUFFER
	if (pdata->memfd >= 0)
		close(pdata->memfd);
	pdata->memfd = -1;

	if (pdata->mmap_addr) {
		munmap(pdata->mmap_addr, pdata->mmap_len);
		pdata->mmap_addr = NULL;
	}
#endif

	iio_mutex_unlock(pdata->lock);
	return ret;
}
Beispiel #20
0
pcap_dumper_t *
priv_pcap_dump_open(pcap_t *p, char *fname)
{
	int fd, err;
	FILE *f;

	if (priv_fd < 0)
		errx(1, "%s: called from privileged portion", __func__);

	if (fname[0] == '-' && fname[1] == '\0') {
		f = stdout;
		priv_init_done();
	} else {
		write_command(priv_fd, PRIV_OPEN_OUTPUT);
		fd = receive_fd(priv_fd);
		must_read(priv_fd, &err, sizeof(err));
		if (fd < 0)  {
			snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
			    "Failed to open output file %s: %s",
			    fname, strerror(err));
			return (NULL);
		}
		f = fdopen(fd, "w");
		if (f == NULL) {
			snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: %s",
			    fname, pcap_strerror(errno));
			close(fd);
			return (NULL);
		}
	}

	(void)sf_write_header(f, p->linktype, p->tzoff, p->snapshot);
	return ((pcap_dumper_t *)f);
}
Beispiel #21
0
/*
 * Set address window.
 */
static void set_window(int x0, int y0, int x1, int y1)
{
    write_command(S6D04H0_Column_Address_Set);
    write_data(x0 >> 8);
    gpanel_write_byte(x0);
    gpanel_write_byte(x1 >> 8);
    gpanel_write_byte(x1);

    write_command(S6D04H0_Page_Address_Set);
    write_data(y0 >> 8);
    gpanel_write_byte(y0);
    gpanel_write_byte(y1 >> 8);
    gpanel_write_byte(y1);

    write_command(S6D04H0_Memory_Write);
}
Beispiel #22
0
/*
 * Switch the screen orientation.
 */
static void set_rotation(int rotation)
{
    write_command(S6D04H0_Memory_Data_Access_Control);
    switch (rotation & 3) {
    case 0:                     /* Portrait */
        write_data(MADCTL_MY | MADCTL_BGR);
        _width  = 240;
        _height = 320;
        break;
    case 1:                     /* Landscape */
        write_data(MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR);
        _width  = 320;
        _height = 240;
        break;
    case 2:                     /* Upside down portrait */
        write_data(MADCTL_MX | MADCTL_BGR);
        _width  = 240;
        _height = 320;
        break;
    case 3:                     /* Upside down landscape */
        write_data(MADCTL_MV | MADCTL_BGR);
        _width  = 320;
        _height = 240;
        break;
    }
}
Beispiel #23
0
main()
{
 lcd_initial();

      while(1)
  {
 write_command(0x2C);
  //  Disp_gradscal(); //»Ò½×
   // delay(500); 
      
//    dsp_single_colour(0x84,0x10);//»ÒÉ«
//    delay(500);	

    dsp_single_colour(0xff,0xff);//°×É«
    delay(500);	
    	
    dsp_single_colour(0x00,0x00);//ºÚÉ«
    delay(500);	
    	
    dsp_single_colour(0xf8,0x00);//ºìÉ«
    delay(500);	
    	
    dsp_single_colour(0x07,0xe0);//ÂÌÉ«
    delay(500);	
    	
    dsp_single_colour(0x00,0x1f);//À¶É«
    delay(500);	

    }

 }
Beispiel #24
0
static void byd_9177aa_panel_init(struct dsi_device *dsi)
{
	int  i;
	for(i = 0; i < ARRAY_SIZE(byd_9177aa_cmd_list); i++) {
		write_command(dsi,  byd_9177aa_cmd_list[i]);
	}
}
Beispiel #25
0
static int network_close(const struct iio_device *dev)
{
	struct iio_device_pdata *pdata = dev->pdata;
	int ret = -EBADF;
	char buf[1024];

	if (pdata->fd >= 0) {
		snprintf(buf, sizeof(buf), "CLOSE %s\r\n", dev->id);

		network_lock_dev(pdata);
		ret = (int) write_rwbuf_command(dev, buf, true);

		write_command("\r\nEXIT\r\n", pdata->fd);

		close(pdata->fd);
		pdata->fd = -1;
		network_unlock_dev(pdata);
	}

#ifdef WITH_NETWORK_GET_BUFFER
	if (pdata->memfd >= 0)
		close(pdata->memfd);
	pdata->memfd = -1;

	if (pdata->mmap_addr) {
		munmap(pdata->mmap_addr, pdata->mmap_len);
		pdata->mmap_addr = NULL;
	}
#endif
	return ret;
}
Beispiel #26
0
static void network_shutdown(struct iio_context *ctx)
{
	struct iio_context_pdata *pdata = ctx->pdata;
	unsigned int i;

	network_lock(pdata);
	write_command("\r\nEXIT\r\n", pdata->fd);
	close(pdata->fd);
	network_unlock(pdata);

	for (i = 0; i < ctx->nb_devices; i++) {
		struct iio_device *dev = ctx->devices[i];
		struct iio_device_pdata *dpdata = dev->pdata;

		if (dpdata) {
			network_close(dev);
#if HAVE_PTHREAD
			pthread_mutex_destroy(&dpdata->lock);
#endif
			free(dpdata);
		}
	}

#if HAVE_PTHREAD
	pthread_mutex_destroy(&pdata->lock);
#endif
	freeaddrinfo(pdata->addrinfo);
	free(pdata);
}
static int write_to_mipi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	int l_count = (argc - 1) % 256; /* parameter count low 8bits */
	int h_count = (argc - 1) / 256; /* parameter count high 8bits */
	int i;

	struct dsi_cmd_packet my_data;

	if(argc < 2) {
		debug("your parameter is too few\n");
		return -1;
	}
	if(argv[1][0] >= '0' && argv[1][0] <= '9') {
		my_data.packet_type = 0x39; /* sent long packet */
		my_data.cmd0_or_wc_lsb = l_count;
		my_data.cmd1_or_wc_msb = h_count;
		for(i = 0; i < argc - 1; i++)
			my_data.cmd_data[i] = simple_strtol(argv[i+1],'\0',10);
		write_command(dsi,my_data);

		debug(" write success \n ");
		return 0;
	}
	else {
		debug(" your command is wrong \n");
		return -1;
	}
}
Beispiel #28
0
/* write a one byte command to the controller */
int
write_controller_command(KBDC p, int c)
{
    if (!wait_while_controller_busy(kbdcp(p)))
	return FALSE;
    write_command(kbdcp(p), c);
    return TRUE;
}
Beispiel #29
0
static void set_addr_window(uint16_t x_0, uint16_t y_0, uint16_t x_1, uint16_t y_1)
{
    ASSERT(x_0 < x_1);
    ASSERT(y_0 < y_1);

    write_command(ILI9341_CASET);
    write_data(x_0 >> 8);
    write_data(x_0);
    write_data(x_1 >> 8);
    write_data(x_1);
    write_command(ILI9341_PASET);
    write_data(y_0 >> 8);
    write_data(y_0);
    write_data(y_1 >> 8);
    write_data(y_1);
    write_command(ILI9341_RAMWR);
}
Beispiel #30
0
static void set_addr_window(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
{
    ASSERT(x0 <= x1);
    ASSERT(y0 <= y1);

    write_command(ST7735_CASET);
    write_data(0x00);                       // For a 128x160 display, it is always 0.
    write_data(x0);
    write_data(0x00);                       // For a 128x160 display, it is always 0.
    write_data(x1);
    write_command(ST7735_RASET);
    write_data(0x00);                       // For a 128x160 display, it is always 0.
    write_data(y0);
    write_data(0x00);                       // For a 128x160 display, it is always 0.
    write_data(y1);
    write_command(ST7735_RAMWR);
}