cardwriter.c
上传用户:caisangzi8
上传日期:2013-10-25
资源大小:15756k
文件大小:11k
源码类别:

DVD

开发平台:

C/C++

  1. /**********************************************************
  2. **  Description: Switch interface for CDROM & CF Card
  3. **  Creater:wuxiaofeng
  4. **  Date:03-09-01 16:33
  5. **  Maintain Date: 03-09-15  18:14
  6. **  Modified: let COPY button gray at CF Card side
  7. **  Maintain Date: 03-09-15  11:54
  8. **  Modified: delete the wrong color define
  9. **  Maintain Date: 03-09-17  15:36
  10. **  Modified: if deleting the last file in card, then turn to CDROM side.
  11. ***********************************************************/
  12. #include "user_init.h"
  13. #include "global.h"
  14. #include "memmap0.h"
  15. #include "ircmd.h"
  16. #include "types.h"
  17. #include "memcfg.h"
  18. #include "framebuf.h"
  19. #include "memmap.h"
  20. #include "osd.h"
  21. #include "cardfs.h"
  22. #include "fsNav.h"
  23. #ifdef CF_CARD_WRITE
  24. #define FUNCTION_REGION 3
  25. #define MESSAGE_REGION 2
  26. #define COLOR_WHITE 2
  27. #define COLOR_GRAY 3
  28. #define COLOR_DBLUE 4
  29. #define COLOR_LBLUE 6
  30. #define COLOR_YELLOW 7
  31. #define COLOR_GREEN 9
  32. #define COLOR_RED 12
  33. #define BUTTON_UP 0
  34. #define BUTTON_DOWN 1
  35. #define BUTTON_LEN 18
  36. #define BUTTON_CD2CF 1
  37. #define BUTTON_CF2CD 2
  38. #define BUTTON_COPY 3
  39. #define BUTTON_DELETE 4
  40. #define BUTTON_FORMAT 5
  41. #define BUTTON_CREADIR 6
  42. #define ERROR_MESSAGE 0
  43. #define CFFUN_WRITE 1
  44. #define CFFUN_DELETE 2
  45. #define CFFUN_FORMAT 3
  46. #define CFFUN_CREADIR 4
  47. #define CFFUN_COPYING 5
  48. #define CF_CARDFULL  6
  49. #define CF_CARDEMPTY  7
  50. #define __palette4F(G,B,R,A) 
  51.         ( ((UINT32)((G)&0xff)<<24)|((UINT32)((B)&0xff)<<16)|((UINT32)((R)&0xff)<<8)|(A&0xff) ) 
  52. extern void osd_init_cardswitch(void);
  53. extern void osd_DrawRegionString(BYTE xStart, BYTE yStart, BYTE *str, BYTE fontColor, BYTE bkColor, BYTE r);
  54. extern void osd_draw_button(BYTE xStart, BYTE yStart, BYTE xLen, BYTE color, BYTE bDown, BYTE r);
  55. extern int AVD_SetMediaInterrupt(void);
  56. //extern int CardSchedule(void);
  57. extern int FSSchedule(void);
  58. //指针数组: int *p[4];
  59. BYTE  *string[]={" ","CDROM TO CARD","CARD TO CDROM","COPY THE FILE","DELETE THE FILE","FORMAT CARD","CREATE DIR"};
  60. BYTE KeyID;
  61. BYTE read_card_sign=0;
  62. BYTE flag_cd2cf=0, flag_cf2cd=0;
  63. BYTE sign_cfFun=0;
  64. /***************************************************************
  65. **Function: Set_Button()
  66. **Description: Draw the button in the region 3.
  67. **return value:   none
  68. **Create: wuxiaofeng, 2003-9-4 
  69. ***************************************************************/
  70. void Set_Button(void)
  71. {
  72. BYTE item;
  73. if(media_type==MEDIA_CD)
  74. {
  75. for(item=BUTTON_CD2CF; item<=BUTTON_COPY; item++)//normal display former three
  76. {
  77. osd_draw_button(2, item, BUTTON_LEN, COLOR_LBLUE, BUTTON_UP, FUNCTION_REGION);
  78. osd_DrawRegionString(3, item*8+3, string[item], COLOR_DBLUE, COLOR_LBLUE, FUNCTION_REGION); //draw string on button
  79. }
  80. for(item=BUTTON_DELETE; item<=BUTTON_CREADIR; item++)//invalidate the latter three
  81. {
  82. osd_draw_button(2, item, BUTTON_LEN, COLOR_LBLUE, BUTTON_UP, FUNCTION_REGION);
  83. osd_DrawRegionString(3, item*8+3, string[item], COLOR_GRAY, COLOR_LBLUE, FUNCTION_REGION); //draw string on button
  84. }
  85. }
  86. if(media_type==MEDIA_CARD)
  87. {
  88. for(item=BUTTON_CD2CF; item<=BUTTON_CF2CD; item++)//all six are ok
  89. {
  90. osd_draw_button(2, item, BUTTON_LEN, COLOR_LBLUE, BUTTON_UP, FUNCTION_REGION);
  91. osd_DrawRegionString(3, item*8+3, string[item], COLOR_DBLUE, COLOR_LBLUE, FUNCTION_REGION); //draw string on button
  92. }
  93. //for copy gray
  94. osd_draw_button(2, BUTTON_COPY, BUTTON_LEN, COLOR_LBLUE, BUTTON_UP, FUNCTION_REGION);
  95. osd_DrawRegionString(3, BUTTON_COPY*8+3, string[BUTTON_COPY], COLOR_GRAY, COLOR_LBLUE, FUNCTION_REGION); //draw string on button
  96. for(item=BUTTON_DELETE; item<=BUTTON_CREADIR; item++)//all six are ok
  97. {
  98. osd_draw_button(2, item, BUTTON_LEN, COLOR_LBLUE, BUTTON_UP, FUNCTION_REGION);
  99. osd_DrawRegionString(3, item*8+3, string[item], COLOR_DBLUE, COLOR_LBLUE, FUNCTION_REGION); //draw string on button
  100. }
  101. }
  102. }
  103. /***************************************************************
  104. **Function: highlight_button()
  105. **Description: highlight the cursor assigned button.
  106. **return value:   none
  107. **Create: wuxiaofeng, 2003-9-4 
  108. ***************************************************************/
  109. void highlight_button(BYTE selectID)
  110. {
  111. Set_Button();// back to the default color
  112. switch(selectID)
  113. {
  114. case BUTTON_CD2CF:
  115. osd_draw_button(2, BUTTON_CD2CF, BUTTON_LEN, COLOR_GREEN, BUTTON_UP, FUNCTION_REGION);
  116. osd_DrawRegionString(3, BUTTON_CD2CF*8+3, string[BUTTON_CD2CF], COLOR_DBLUE, COLOR_GREEN, FUNCTION_REGION);  //draw string on button
  117. break;
  118. case BUTTON_CF2CD:
  119. osd_draw_button(2, BUTTON_CF2CD, BUTTON_LEN, COLOR_GREEN, BUTTON_UP, FUNCTION_REGION);
  120. osd_DrawRegionString(3, BUTTON_CF2CD*8+3, string[BUTTON_CF2CD], COLOR_DBLUE, COLOR_GREEN, FUNCTION_REGION);  //draw string on button
  121. break;
  122. case BUTTON_COPY:
  123. osd_draw_button(2, BUTTON_COPY, BUTTON_LEN, COLOR_GREEN, BUTTON_UP, FUNCTION_REGION);
  124. osd_DrawRegionString(3, BUTTON_COPY*8+3, string[BUTTON_COPY], COLOR_DBLUE, COLOR_GREEN, FUNCTION_REGION);  //draw string on button
  125. break;
  126. case BUTTON_DELETE:
  127. osd_draw_button(2, BUTTON_DELETE, BUTTON_LEN, COLOR_GREEN, BUTTON_UP, FUNCTION_REGION);
  128. osd_DrawRegionString(3, BUTTON_DELETE*8+3, string[BUTTON_DELETE], COLOR_DBLUE, COLOR_GREEN, FUNCTION_REGION);  //draw string on button
  129. break;
  130. case BUTTON_FORMAT:
  131. osd_draw_button(2, BUTTON_FORMAT, BUTTON_LEN, COLOR_GREEN, BUTTON_UP, FUNCTION_REGION);
  132. osd_DrawRegionString(3, BUTTON_FORMAT*8+3, string[BUTTON_FORMAT], COLOR_DBLUE, COLOR_GREEN, FUNCTION_REGION);  //draw string on button
  133. break;
  134. case BUTTON_CREADIR:
  135. osd_draw_button(2, BUTTON_CREADIR, BUTTON_LEN, COLOR_GREEN, BUTTON_UP, FUNCTION_REGION);
  136. osd_DrawRegionString(3, BUTTON_CREADIR*8+3, string[BUTTON_CREADIR], COLOR_DBLUE, COLOR_GREEN, FUNCTION_REGION); //draw string on button
  137. break;
  138. }
  139. }
  140. /***************************************************************
  141. **Function: show_card_switch()
  142. **Description: draw the OSD region.
  143. **return value:   none
  144. **Create: wuxiaofeng, 2003-9-4 
  145. ***************************************************************/
  146. void show_card_switch(void)
  147. {
  148. osd_init_cardswitch();
  149. BYTE *title_str="USER OPERATION";
  150. osd_DrawRegionString(1, 0, title_str, COLOR_YELLOW, COLOR_GRAY, FUNCTION_REGION); //draw the note
  151. SetOsdCol(FUNCTION_REGION, FUNCTION_REGION, 0, __palette4F( 128, 255, 128, 0xff)); //draw background of the region
  152. Set_Button();
  153. KeyID=BUTTON_CD2CF;
  154. highlight_button(KeyID);
  155. }
  156. void card_switch_left()
  157. {
  158. }
  159. void card_switch_right()
  160. {
  161. }
  162. void card_switch_down(void)
  163. {
  164. if(media_type==MEDIA_CD)
  165. {
  166. if(KeyID>=BUTTON_COPY)
  167. {
  168. KeyID=BUTTON_CD2CF;
  169. }
  170. else
  171. {
  172. KeyID++;
  173. }
  174. }
  175. else if(media_type==MEDIA_CARD)
  176. {
  177. if(KeyID>=BUTTON_CREADIR)
  178. {
  179. KeyID=BUTTON_CD2CF;
  180. }
  181. else
  182. {
  183. KeyID++;
  184. }
  185. if(KeyID==BUTTON_COPY)//add 09/15 disable COPY
  186. {
  187. KeyID=BUTTON_DELETE;
  188. }
  189. }
  190. highlight_button(KeyID);
  191. }
  192. void card_switch_up(void)
  193. {
  194. if(media_type==MEDIA_CD)
  195. {
  196. if(KeyID<=BUTTON_CD2CF)
  197. {
  198. KeyID=BUTTON_COPY;
  199. }
  200. else
  201. {
  202. KeyID--;
  203. }
  204. }
  205. else if(media_type==MEDIA_CARD)
  206. {
  207. if(KeyID<=BUTTON_CD2CF)
  208. {
  209. KeyID=BUTTON_CREADIR;
  210. }
  211. else
  212. {
  213. KeyID--;
  214. }
  215. if(KeyID==BUTTON_COPY)//add 09/15  disable COPY
  216. {
  217. KeyID=BUTTON_CF2CD;
  218. }
  219. }
  220. highlight_button(KeyID);
  221. }
  222. /***************************************************************
  223. **Function: Message_Show()
  224. **Description: display some message in region 2.
  225. **return value:   none
  226. **Create: wuxiaofeng, 2003-9-4 
  227. ***************************************************************/
  228. void Message_Show(BYTE strID)
  229. {
  230. BYTE *str[]={"CARD ERROR","WRITE FILE OK","DELETE FILE OK","CARD FORMATED","DIR CREATED","FILE COPYING","CARD FULL","CARD EMPTY"};
  231. osd_init_cardswitch();
  232. SetOsdCol(MESSAGE_REGION, MESSAGE_REGION, 0, 0);
  233. osd_DrawRegionString(6, 1, str[strID], COLOR_RED, COLOR_LBLUE, MESSAGE_REGION); //draw the error
  234. delay_1ms(2000);
  235. }
  236. /***************************************************************
  237. **Function: card_switch_select()
  238. **Description: perform the actual function by selecting the assigned button.
  239. **return value:   none
  240. **Create: wuxiaofeng, 2003-9-4 
  241. ***************************************************************/
  242. void card_switch_select(void)
  243. {
  244. switch(KeyID)
  245. {
  246. case BUTTON_COPY:
  247. // if(CardIdentify()!=0)//very important!!!
  248. if(FSIdentify()!=0)//very important!!!
  249. {
  250. Message_Show(ERROR_MESSAGE);
  251. show_card_switch();
  252. }
  253. else
  254. {
  255. if(pFsJpeg->gifsFuncBtn == FS_FUNC_MP3)
  256. {
  257. sign_cfFun=CFFUN_WRITE;//write cf card
  258. AVD_SetMediaInterrupt();//stop the current mp3, Can't be used for JPEG!!
  259. Message_Show(CFFUN_COPYING);
  260. }
  261. else if(pFsJpeg->gifsFuncBtn == FS_FUNC_JPEG)
  262. {
  263. sign_cfFun=CFFUN_WRITE;//write JPEG
  264. Message_Show(CFFUN_COPYING);
  265. // if(CardSchedule()==-1)
  266. if(FSSchedule()==-1)
  267. {
  268. Message_Show(CF_CARDFULL);
  269. }
  270. else
  271. {
  272. Message_Show(CFFUN_WRITE);
  273. }
  274. full_scrn &= (~CARDOSDSHOW);//for release the IR
  275. osd_init();
  276. }
  277. }
  278. break;
  279. case BUTTON_DELETE://share the break with BUTTON_CD2CF!!
  280. // if(CardIdentify()!=0)//very important!!!
  281. if(FSIdentify()!=0)//very important!!!
  282. {
  283. Message_Show(ERROR_MESSAGE);
  284. show_card_switch();
  285. }
  286. else
  287. {
  288. sign_cfFun=CFFUN_DELETE;//delete data
  289. // if(CardSchedule()==-1)
  290. if(FSSchedule()==-1)
  291. {
  292. Message_Show(CF_CARDEMPTY);
  293. full_scrn &= (~CARDOSDSHOW);//for release the IR
  294. osd_init();
  295. //turn to CDROM
  296. flag_cd2cf=0;    //xulf
  297. flag_cf2cd=1;
  298. media_type=MEDIA_CD;
  299. ircmd_post_func(CMD_FUNC | CMD_FUNC_STOP);
  300. bDiscType=CDUNKNOWN;
  301. sys_cmd=CMD_FUNC_PLAY;
  302. break;
  303. }
  304. else
  305. {
  306. Message_Show(CFFUN_DELETE);
  307. }
  308. }
  309. case BUTTON_CD2CF://cdrom to card
  310. full_scrn &= (~CARDOSDSHOW);//for release the IR
  311. osd_init();
  312. read_card_sign=1;    //xulf0827
  313. flag_cd2cf=1;
  314. flag_cf2cd=0;
  315. media_type=MEDIA_CARD;
  316. ircmd_post_func(CMD_FUNC | CMD_FUNC_STOP);
  317. break;
  318. case BUTTON_FORMAT://share the break with BUTTON_CF2CD!!
  319. // if(CardIdentify()!=0)//very important!!!
  320. if(FSIdentify()!=0)//very important!!!
  321. {
  322. Message_Show(ERROR_MESSAGE);
  323. show_card_switch();
  324. }
  325. else
  326. {
  327. sign_cfFun=CFFUN_FORMAT;//format card
  328. // CardSchedule();
  329. FSSchedule();
  330. Message_Show(CFFUN_FORMAT);
  331. }
  332. case BUTTON_CF2CD://card to cdrom
  333. full_scrn &= (~CARDOSDSHOW);//for release the IR
  334. osd_init();
  335. flag_cd2cf=0;    //xulf
  336. flag_cf2cd=1;
  337. media_type=MEDIA_CD;
  338. ircmd_post_func(CMD_FUNC | CMD_FUNC_STOP);
  339. bDiscType=CDUNKNOWN;
  340. sys_cmd=CMD_FUNC_PLAY;
  341. break;
  342. case BUTTON_CREADIR:
  343. // if(CardIdentify()!=0)//very important!!!
  344. if(FSIdentify()!=0)//very important!!!
  345. {
  346. Message_Show(ERROR_MESSAGE);
  347. show_card_switch();
  348. }
  349. else
  350. {
  351. sign_cfFun=CFFUN_CREADIR;//Create Dir
  352. // CardSchedule();
  353. FSSchedule();
  354. Message_Show(CFFUN_CREADIR);
  355. full_scrn &= (~CARDOSDSHOW);//for release the IR
  356. osd_init();
  357. }
  358. break;
  359. }
  360. }
  361. #endif //#ifdef CF_CARD_WRITE