Пример #1
0
void MainView_Update(void)
{
	if(Keypad_IsKeyStored())
	{
		switch(Keypad_GetKey())
		{
			case 0x24:
				// "8"
				Menu_Down(&menu);
				break;
			case 0x44:
				// "5"
				Menu_Select(&menu);
				return;
				break;
			case 0x84:
				// "2"
				Menu_Up(&menu);
				break;
		}
		Menu_Update(&menu);
	}
}
int main (int argc, char **argv)
{
	int index=0,cindex=0,mainloop=1,dloop=1,tv, spr, resolution;
	char tstr[BUFSIZE]={0}, *rptr;
	PLISTENTRY pl;

	printf("%s Version %.2f\n", __plugin__, SH_VERSION);
	for(tv=1; tv<argc; tv++)
	{
		if(*argv[tv]=='/')
		{
			strcpy(CFG_FILE,argv[tv]);
		}
	}

	//init framebuffer before 1st scale2res
	fb = open(FB_DEVICE, O_RDWR);
#ifdef MARTII
	if (fb < 0)
		fb = open(FB_DEVICE_FALLBACK, O_RDWR);
#endif
	if(fb == -1)
	{
		perror(__plugin__ " <open framebuffer device>");
		exit(1);
	}
	if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1)
	{
		perror(__plugin__ " <FBIOGET_FSCREENINFO>\n");
		return -1;
	}
	if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1)
	{
		perror(__plugin__ " <FBIOGET_VSCREENINFO>\n");
		return -1;
	}
#if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE)
	var_screeninfo.xres = DEFAULT_XRES;
	var_screeninfo.yres = DEFAULT_YRES;
#endif
	if(!(lfb = (uint32_t*)mmap(0, fix_screeninfo.smem_len, PROT_WRITE|PROT_READ, MAP_SHARED, fb, 0)))
	{
		perror(__plugin__ " <mapping of Framebuffer>\n");
		return -1;
	}

	// read config
	ixw=scale2res(600), iyw=scale2res(680), xoffs=scale2res(13);
	if((line_buffer=calloc(BUFSIZE+1, sizeof(char)))==NULL)
	{
		printf(NOMEM);
		return -1;
	}

	if((trstr=calloc(BUFSIZE+1, sizeof(char)))==NULL)
	{
		printf(NOMEM);
		return -1;
	}

	spr=Read_Neutrino_Cfg("screen_preset")+1;
	resolution=Read_Neutrino_Cfg("osd_resolution");

	if (resolution == -1)
		sprintf(trstr,"screen_StartX_%s", spres[spr]);
	else
		sprintf(trstr,"screen_StartX_%s_%d", spres[spr], resolution);
	if((sx=Read_Neutrino_Cfg(trstr))<0)
		sx=scale2res(100);

	if (resolution == -1)
		sprintf(trstr,"screen_EndX_%s", spres[spr]);
	else
		sprintf(trstr,"screen_EndX_%s_%d", spres[spr], resolution);
	if((ex=Read_Neutrino_Cfg(trstr))<0)
		ex=scale2res(1180);

	if (resolution == -1)
		sprintf(trstr,"screen_StartY_%s", spres[spr]);
	else
		sprintf(trstr,"screen_StartY_%s_%d", spres[spr], resolution);
	if((sy=Read_Neutrino_Cfg(trstr))<0)
		sy=scale2res(100);

	if (resolution == -1)
		sprintf(trstr,"screen_EndY_%s", spres[spr]);
	else
		sprintf(trstr,"screen_EndY_%s_%d", spres[spr], resolution);
	if((ey=Read_Neutrino_Cfg(trstr))<0)
		ey=scale2res(620);

	for(index=CMCST; index<=CMH; index++)
	{
		sprintf(trstr,"menu_%s_alpha",menucoltxt[index]);
		if((tv=Read_Neutrino_Cfg(trstr))>=0)
			tr[index]=255-(float)tv*2.55;

		sprintf(trstr,"menu_%s_blue",menucoltxt[index]);
		if((tv=Read_Neutrino_Cfg(trstr))>=0)
			bl[index]=(float)tv*2.55;

		sprintf(trstr,"menu_%s_green",menucoltxt[index]);
		if((tv=Read_Neutrino_Cfg(trstr))>=0)
			gn[index]=(float)tv*2.55;

		sprintf(trstr,"menu_%s_red",menucoltxt[index]);
		if((tv=Read_Neutrino_Cfg(trstr))>=0)
			rd[index]=(float)tv*2.55;
	}

	if(Read_Neutrino_Cfg("rounded_corners")>0) {
		radius = scale2res(11);
		radius_small = scale2res(5);
	}
	else
		radius = radius_small = 0;

	mtmo = Read_Neutrino_Cfg("timing.menu");
	if (mtmo < 0)
		mtmo = 0;

	cindex=CMC;
	for(index=COL_MENUCONTENT_PLUS_0; index<=COL_MENUCONTENT_PLUS_3; index++)
	{
		rd[index]=rd[cindex]+25;
		gn[index]=gn[cindex]+25;
		bl[index]=bl[cindex]+25;
		tr[index]=tr[cindex];
		cindex=index;
	}
	sprintf(trstr,"infobar_alpha");
	if((tv=Read_Neutrino_Cfg(trstr))>=0)
		tr[COL_SHADOW_PLUS_0]=255-(float)tv*2.55;

	sprintf(trstr,"infobar_blue");
	if((tv=Read_Neutrino_Cfg(trstr))>=0)
		bl[COL_SHADOW_PLUS_0]=(float)tv*2.55*0.4;

	sprintf(trstr,"infobar_green");
	if((tv=Read_Neutrino_Cfg(trstr))>=0)
		gn[COL_SHADOW_PLUS_0]=(float)tv*2.55*0.4;

	sprintf(trstr,"infobar_red");
	if((tv=Read_Neutrino_Cfg(trstr))>=0)
			rd[COL_SHADOW_PLUS_0]=(float)tv*2.55*0.4;

	for (index = 0; index <= COL_SHADOW_PLUS_0; index++)
		bgra[index] = (tr[index] << 24) | (rd[index] << 16) | (gn[index] << 8) | bl[index];

	InitRC();
	//InitVFD();

	//init fontlibrary
	if((error = FT_Init_FreeType(&library)))
	{
		printf("%s <FT_Init_FreeType failed with Errorcode 0x%.2X>", __plugin__, error);
		munmap(lfb, fix_screeninfo.smem_len);
		return -1;
	}

	if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager)))
	{
		printf("%s <FTC_Manager_New failed with Errorcode 0x%.2X>\n", __plugin__, error);
		FT_Done_FreeType(library);
		munmap(lfb, fix_screeninfo.smem_len);
		return -1;
	}

	if((error = FTC_SBitCache_New(manager, &cache)))
	{
		printf("%s <FTC_SBitCache_New failed with Errorcode 0x%.2X>\n", __plugin__, error);
		FTC_Manager_Done(manager);
		FT_Done_FreeType(library);
		munmap(lfb, fix_screeninfo.smem_len);
		return -1;
	}

	memset(&menu,0,sizeof(MENU));
	if(Check_Config())
	{
		printf("%s <Check_Config> Unable to read Config %s\n", __plugin__, CFG_FILE);
		FTC_Manager_Done(manager);
		FT_Done_FreeType(library);
		munmap(lfb, fix_screeninfo.smem_len);
		Clear_List(&menu,-1);
		free(line_buffer);
		return -1;
	}

	if((error = FTC_Manager_LookupFace(manager, FONT, &face)))
	{
		printf("%s <FTC_Manager_LookupFace failed with Errorcode 0x%.2X, trying default font>\n", __plugin__, error);
		if((error = FTC_Manager_LookupFace(manager, FONT2, &face)))
		{
			printf("%s <FTC_Manager_LookupFace failed with Errorcode 0x%.2X>\n", __plugin__, error);
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return 2;
		}
		else
			desc.face_id = FONT2;
	}
	else
		desc.face_id = FONT;
	printf("%s <FTC_Manager_LookupFace Font \"%s\" loaded>\n", __plugin__, desc.face_id);

	use_kerning = FT_HAS_KERNING(face);
	desc.flags = FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT;

	//init backbuffer
#if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE)
	lbb = lfb + 1920 * 1080;
	fix_screeninfo.line_length = DEFAULT_XRES * sizeof(uint32_t);
	stride = DEFAULT_XRES;
#else
	stride = fix_screeninfo.line_length/sizeof(uint32_t);
	if(stride == 7680 && var_screeninfo.xres == 1280) {
		var_screeninfo.yres = 1080;
	}

	if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t))))
	{
		printf("%s <allocating of Backbuffer failed>\n", __plugin__);
		FTC_Manager_Done(manager);
		FT_Done_FreeType(library);
		munmap(lfb, fix_screeninfo.smem_len);
		return -1;
	}
#endif

	//lbb=lfb;
#if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE)
	FillRect(0, 0, DEFAULT_XRES, DEFAULT_YRES, 0);
	blit();
#else
	memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
	memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
	//blit();
#endif

	startx = sx;
	starty = sy;

	/* scale to resolution */
	FSIZE_BIG = scale2res(FSIZE_BIG);
	FSIZE_MED = scale2res(FSIZE_MED);
	FSIZE_SMALL = scale2res(FSIZE_SMALL);

	TABULATOR = scale2res(TABULATOR);

	OFFSET_MED = scale2res(OFFSET_MED);
	OFFSET_SMALL = scale2res(OFFSET_SMALL);
	OFFSET_MIN = scale2res(OFFSET_MIN);

	/* Set up signal handlers. */
	signal(SIGINT, quit_signal);
	signal(SIGTERM, quit_signal);
	signal(SIGQUIT, quit_signal);
	signal(SIGSEGV, quit_signal);

	index=0;
	if(vfd)
	{
		sprintf(tstr,"%s -c", VFD);
		system(tstr);
	}
	ShowInfo(&menu, 1);
	//main loop
	menu.act_entry=0;
	if(Get_Menu(1))
	{
		printf("%s <unable to create menu>\n", __plugin__);
		FTC_Manager_Done(manager);
		FT_Done_FreeType(library);
		munmap(lfb, fix_screeninfo.smem_len);
		return -1;
	}
	cindex=0;

	put_instance(instance=get_instance()+1);

	while(mainloop)
	{
		cindex=Get_Selection(&menu);
		dloop=1;
		switch(cindex)
		{
			case -1:
				mainloop=0;
				break;

			case 0:
				mainloop=Menu_Up(&menu);
				break;

			case 1:
				pl=menu.list[menu.act_entry];
				switch (pl->type)
				{
					case TYP_MENU:
						menu.act_header=pl->headerpos;
						menu.lastheaderentrys[menu.act_header]=menu.act_entry;
						menu.headerwait[menu.act_header]=pl->message!=NULL;
						if(menu.headerwait[menu.act_header])
							{
								strcpy(tstr,pl->entry);
								if((rptr=strxchr(tstr,','))!=NULL)
								{
									*rptr=0;
								}
								ShowMessage(tstr, pl->message, 0);
							}
						Get_Menu(0);
						menu.act_entry=0;
						break;

					case TYP_EXECUTE:
						if((rptr=strxchr(pl->entry,','))!=NULL)
						{
							strcpy(tstr,pl->entry);
							rptr=strxchr(tstr,',');
							*rptr=0;
							rptr=strxchr(pl->entry,',');
							rptr++;
							if(pl->stay)
							{
								if(pl->stay==1)
								{
									if(pl->message)
									{
										if(strlen(pl->message))
										{
											ShowMessage(tstr, pl->message, 0);
										}
									}
									else
									{
										ShowMessage(tstr, "Bitte warten", 0);
									}
								}
								else
								{
#if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE)
									FillRect(0, 0, DEFAULT_XRES, DEFAULT_YRES, 0);
									blit();
#else
									memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
									memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
									//blit();
#endif
								}

								if(*(rptr+strlen(rptr)-1)=='&')
								{
									*(rptr+strlen(rptr)-1)=0;
								}
							}
							else
							{
								if(*(rptr+strlen(rptr)-1)!='&')
								{
									sprintf(tstr,"%s &",rptr);
									rptr=tstr;
								}
							}
							CloseRC();
							system(rptr);
							InitRC();

							mainloop= pl->stay==1;
							if(pl->stay==1)
							{
								Get_Menu(1);
							}
						}
						break;
				}
		}
	}

	//cleanup
	Clear_List(&menu,-1);

	FTC_Manager_Done(manager);
	FT_Done_FreeType(library);
#if 0
	if(strlen(url))
	{
		sprintf(line_buffer,"/sbin/rdate -s %s > /dev/null &",url);
		system(line_buffer);
	}
#endif
	CloseRC();
	//CloseVFD();

	free(line_buffer);
	free(trstr);

	// clear Display
#if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE)
	FillRect(0, 0, DEFAULT_XRES, DEFAULT_YRES, 0);
	blit();
#else
	memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
	memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
	//blit();
#endif
	munmap(lfb, fix_screeninfo.smem_len);

	close(fb);
#if !defined(MARTII) && !defined(HAVE_SPARK_HARDWARE) && !defined(HAVE_DUCKBOX_HARDWARE)
	free(lbb);
#endif

	put_instance(get_instance()-1);

	return 0;
}