touch.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * switch.c
  3. *
  4. * Created on: 2025年11月6日
  5. * Author: wulianwei
  6. */
  7. #include "nim_config.h"
  8. #include "tr_protocol.h"
  9. extern volatile unsigned int TocuhTime; //触控时间
  10. extern volatile unsigned char TocuhTrigger; //触控触发
  11. static volatile char gui_power_status = 0; //gui开机状态,1:开机,0:关机
  12. void touch_opengui();
  13. void touch_deivce_init()
  14. {
  15. GPIOBank0Pin11Init();
  16. GPIOBank5Pin5Init();
  17. }
  18. /**
  19. * 中断调用函数,尽快结束
  20. */
  21. void touch_switch(int len)
  22. {
  23. if(len)
  24. {
  25. TocuhTrigger = 0;
  26. TocuhTime = TOUCH_TIME;
  27. ConsolePuts("swith 1", -1);
  28. }
  29. else
  30. {
  31. TocuhTrigger = 1;
  32. TocuhTime = TOUCH_TIME;
  33. ConsolePuts("swith 0", -1);
  34. }
  35. }
  36. /**
  37. * 设置gui电源状态
  38. */
  39. void setGuiPowerStatus(char value)
  40. {
  41. gui_power_status = value;
  42. }
  43. void touch_askgui()
  44. {
  45. trProtocol verPro;
  46. ProtocolInit(&verPro);
  47. ProtocolSetDestAddress(&verPro,3);
  48. ProtocolSetSourceAddress(&verPro,1);
  49. ProtocolSetType(&verPro,2);
  50. ProtocolSetOptionChar(&verPro, 99, 2);//关机请求
  51. ProtocolPackage(&verPro);
  52. ConsolePuts("\n===shutdown request to gui\n", -1);
  53. ConsolePutsHexStr(verPro.message, verPro.length);
  54. lwip_tcp_send_gui(verPro.message,verPro.length);
  55. }
  56. //gui上电
  57. void touch_opengui()
  58. {
  59. ConsolePuts("\n===open gui\n", -1);
  60. GPIOPinWrite(SOC_GPIO_0_REGS, 86, GPIO_PIN_HIGH); // GPIO5[5]
  61. gui_power_status = 1;
  62. init_ip();
  63. }
  64. //gui断电
  65. void touch_closegui()
  66. {
  67. ConsolePuts("\n===close gui\n", -1);
  68. GPIOPinWrite(SOC_GPIO_0_REGS, 86, GPIO_PIN_LOW);
  69. gui_power_status = 0;
  70. }
  71. void touch_task()
  72. {
  73. if(TocuhTime == 0)
  74. {
  75. TocuhTime = TOUCH_TIME;
  76. if(gui_power_status)
  77. {
  78. touch_askgui();
  79. }
  80. else
  81. {
  82. touch_opengui();
  83. }
  84. }
  85. }