//--------------------------- Model
 PyObject* LMF_ModelLoad(PyObject *self, PyObject *args){
	char* path;
	if (!PyArg_ParseTuple(args, "s", &path)) {
		ParsePyTupleError( __func__, __LINE__ );
		return nullptr;
	}
	unsigned int ModelID = ModelLoad(path);
	return Py_BuildValue("i", ModelID);
}
Example #2
0
u32 PageModelSel(u8 event)
{	
	static u32 DrawMask;
	
	if(event==PV_INIT)
	{
		LcdClear(0);
		LcdDrawStart(0, 0,LCD_W-1, LCD_H-1, DRAW_NWSE);  
		LcdDrawText(3,0,"选择模型");		
		LcdDrawHLine(0,128,14,1);
		LcdDrawHLine(0,128,15,1);
		LcdDrawStop();
		
		DrawMask=PD_ALL;
		
		PageModFileCnt=0;
		PageModFileIdx=0;
		PageModFileStart=0;
		
		//枚举所有模型图标
    	if(FS_OpenDir("model"))
    	{
			char modfile[13];
        	int type;
        	while((type = FS_ReadDir(modfile)) != 0 && PageModFileCnt<MODCFG_NUM)
        	{
        		BeepHandler();//此循环耗时太长,需要执行一些必要过程
            	if (type == 1)
            	{
            		//打开配置文件读取模型名称
            		char filename[32];
            		strcpy(filename,"model/");
            		strcat(filename,modfile);
            		FILE *fcfg=fopen(filename,"rb");
            		if(fcfg)
            		{
            			MODEL model;
            			fread(&model,sizeof(model),1,fcfg);
            			if(model.Mark==CFGMARK || model.Mark==CFGMARKOLD)
            			{            	
		            		u16 idx=(modfile[0]-'0')*10+(modfile[1]-'0');       
		            		
            				PageModFiles[PageModFileCnt][0]=modfile[0];
            				PageModFiles[PageModFileCnt][1]=modfile[1];
            				PageModFiles[PageModFileCnt][2]=0xba;//号
            				PageModFiles[PageModFileCnt][3]=0xc5;//号
            				PageModFiles[PageModFileCnt][4]='.';
            				if(idx==TxSys.ModelNo)	strcpy(&PageModFiles[PageModFileCnt][5],Model.Name);
            				else					strcpy(&PageModFiles[PageModFileCnt][5],model.Name);
            					    		
		            		if(idx==TxSys.ModelNo)//寻找当前配置文件
		            		{
		            			PageModFileIdx=PageModFileCnt;
		            		}
		            		PageModFileCnt++;    
		            	}
		            	fclose(fcfg);
            		}            
            	}
            }
        	FS_CloseDir();
        }
		
		//判断是否有配置文件
		if(PageModFileCnt==0)
		{
			PageAlert("没有配置文件...",1000,PV_END);
		}
		
		return 1;
	}	
	
	//绘制界面
	if(DrawMask)
	{		
		//起始位置整理
		if(PageModFileIdx<PageModFileStart) 				PageModFileStart=PageModFileIdx;
		if(PageModFileIdx>PageModFileStart+LCD_MENULINES-1)	PageModFileStart=PageModFileIdx-LCD_MENULINES+1;	
	
		LcdDrawStart(0, 0,LCD_W-1, LCD_H-1, DRAW_NWSE);  
		/*
		//菜单项索引号
		if(DrawMask&PD_IDX)
		{
			if(PageModFileCnt>9)
			{
				LcdDrawMiniInt(110,4,PageModFileIdx+1,2,0,0xff,1);
				LcdDrawMiniNum(110,4,LCD_MN_SPA);
				LcdDrawMiniInt(114,4,PageModFileCnt,2,0,0xff,0);
			}
			else
			{
				LcdDrawMiniInt(120,4,PageModFileIdx+1,2,0,0xff,1);
				LcdDrawMiniNum(120,4,LCD_MN_SPA);
				LcdDrawMiniInt(124,4,PageModFileCnt,1,0,0xff,0);
			}
		}
		*/
		
		//绘制文件列表和模型图标
		if(DrawMask&PD_LIST)
		{			
			//显示列表
			int i,y,idx;
			for(i=0,y=16;i<LCD_MENULINES;i++,y+=16)
			{
				idx=PageModFileStart+i;
				LcdBw=(idx==PageModFileIdx);				
				LcdDrawRect(2,y,125,y+15,LcdBw);		//绘制选中框
				LcdDrawText(3,y,PageModFiles[idx]);	//绘制名称
				LcdBw=0;
			}
		}
		LcdDrawStop();
		DrawMask=0;
	}
	
	//上下按键处理
	if(KeyTstDown(KEY_UP))
	{
		if(PageModFileIdx>0)	PageModFileIdx--;
		else		 			PageModFileIdx=PageModFileCnt-1;
		DrawMask=PD_LIST|PD_IDX;
	}
	if(KeyTstDown(KEY_DW))
	{
		if(PageModFileIdx<PageModFileCnt-1)	PageModFileIdx++;
		else		 							PageModFileIdx=0;
		DrawMask=PD_LIST|PD_IDX;
	}
	
	//选中位图
	if(KeyTstDown(KEY_ENT))
	{
		//取得选中的模型号
		PageModFileIdx= 10*(PageModFiles[PageModFileIdx][0]-'0')+PageModFiles[PageModFileIdx][1]-'0';
		
		//保存现有模型的配置
		ModelSave(TxSys.ModelNo);
		
		//加载新遥控器配置
		ModelLoad(TxSys.ModelNo=PageModFileIdx,1);
		
		PageAlert("模型已切换!",1000,PV_END);
	}
	
	//退出消息
	if(KeyTstDown(KEY_EXT) || event==PV_END)	PageReturn(PV_INIT);//这里不要用REDRAW,要用INIT,让模型菜单初始化
	KeyClearDown(KEY_MENUALL);	
	
	return 0;
}