Advertisement
Guest User

Untitled

a guest
Nov 14th, 2011
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. /********************************************************************
  2. * Description: message.comp
  3. * Message HAL component.
  4. *
  5. * Author: Les Newell <les at sheetcam dot com>
  6. * License: GPL Version 2 or later
  7. *
  8. * Copyright (c) 2011 All rights reserved.
  9. *
  10. ********************************************************************
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of version 2 or later of the GNU General
  14. * Public License as published by the Free Software Foundation.
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  23. *
  24. * THE AUTHORS OF THIS LIBRARY ACCEPT ABSOLUTELY NO LIABILITY FOR
  25. * ANY HARM OR LOSS RESULTING FROM ITS USE. IT IS _EXTREMELY_ UNWISE
  26. * TO RELY ON SOFTWARE ALONE FOR SAFETY. Any machinery capable of
  27. * harming persons must have provisions for completely removing power
  28. * from all motors, etc, before persons enter any danger area. All
  29. * machinery must be designed to comply with local and national safety
  30. * codes, and the authors of this software can not, and do not, take
  31. * any responsibility for such compliance.
  32. *
  33. * This code was written as part of the EMC HAL project. For more
  34. * information, go to www.linuxcnc.org.
  35. *
  36. *************************************************************************/
  37.  
  38. component message "Display a message with a HAL pin";
  39.  
  40. description """Allows HAL pins to trigger a message.
  41.  
  42. Example hal commands:
  43.  
  44. loadrt message names=oillow,oilpressure messages="Slideway oil low,No oil pressure"
  45. addf oillow servo-thread
  46. addf oilpressure servo-thread
  47.  
  48. #change this pin to be active low
  49. setp oillow.edge 0
  50.  
  51. net no-oil classicladder.0.out-21 oillow.trigger
  52. net no-pressure classicladder.0.out-22 oilpressure.trigger
  53.  
  54. When any pin goes active, it's message will be displayed.""";
  55.  
  56. pin in bit trigger =FALSE "signal that triggers the message";
  57. pin in bit force =FALSE "A FALSE->TRUE transition forces the message to be displayed again if the trigger is active";
  58.  
  59. param rw bit edge =TRUE "Selects the desired edge: TRUE means falling, FALSE means rising";
  60.  
  61. variable int myidx;
  62. variable bool prev_trigger = FALSE;
  63. variable bool prev_force = TRUE;
  64. variable bool prev_edge = TRUE;
  65.  
  66.  
  67. option extra_setup yes;
  68.  
  69. function _ nofp "Display a message";
  70. license "LGPL";
  71. ;;
  72.  
  73.  
  74. char *messages[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  75. RTAPI_MP_ARRAY_STRING(messages, 16, "Displayed strings");
  76.  
  77. FUNCTION(_){
  78. bool show = false;
  79. if(prev_edge != edge) /* edge type has changed */
  80. {
  81. prev_edge = edge;
  82. prev_trigger = !edge;
  83. }
  84. if(force != prev_force) /* force type has changed */
  85. {
  86. prev_force = force;
  87. if(force && (trigger == edge))
  88. {
  89. show = true;
  90. }
  91. }
  92. if(trigger != prev_trigger) /* trigger has changed */
  93. {
  94. prev_trigger = trigger;
  95. if(trigger == edge)
  96. {
  97. show = true;
  98. }
  99. }
  100. if(show)
  101. {
  102. rtapi_print_msg(RTAPI_MSG_ERR, messages[myidx]);
  103. }
  104. }
  105.  
  106. EXTRA_SETUP(){
  107. myidx = extra_arg;
  108. if(myidx<0 || myidx >15)
  109. {
  110. rtapi_print_msg(RTAPI_MSG_ERR,"Count out of range\n");
  111. return(EINVAL);
  112. }
  113. if(messages[myidx] == 0)
  114. {
  115. rtapi_print_msg(RTAPI_MSG_ERR,"Message string missing\n");
  116. return(EINVAL);
  117. }
  118. return(0);
  119. }
  120.  
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement