Advertisement
Guest User

Untitled

a guest
Nov 13th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 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";
  39.  
  40. description """Allows HAL pins to trigger a message. Example hal commands:
  41. loadrt message names=oillow,oilpressure,inverterfail messages="Slideway oil low,No oil
  42. pressure,Spindle inverter fault"
  43. addf oillow servo-thread
  44. addf oilpressure servo-thread
  45. addf inverterfail servo-thread
  46.  
  47. setp oillow.edge 0 #this pin should be active low
  48. net no-oil classicladder.0.out-21 oillow.trigger
  49. net no-pressure classicladder.0.out-22 oilpressure.trigger
  50. net no-inverter classicladder.0.out-23 inverterfail.trigger
  51.  
  52. When any pin goes active, it's message will be displayed.""";
  53.  
  54. pin in bit trigger =FALSE "signal that triggers the message";
  55. pin in bit force =FALSE "A FALSE->TRUE transition forces the message to be displayed again if the trigger is active";
  56.  
  57. param rw bit edge =TRUE "Selects the desired edge: TRUE means falling, FALSE means rising";
  58.  
  59. variable int myidx;
  60. variable bool prev_trigger = FALSE;
  61. variable bool prev_force = TRUE;
  62. variable bool prev_edge = TRUE;
  63.  
  64. option extra_setup yes;
  65.  
  66. function _ nofp "Display a message";
  67. license "LGPL";
  68. ;;
  69.  
  70. char *messages[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  71. RTAPI_MP_ARRAY_STRING(messages, 16, "Displayed strings");
  72.  
  73. FUNCTION(_){
  74. bool show = false;
  75. if(prev_edge != edge) /* edge type has changed */
  76. {
  77. prev_edge = edge;
  78. prev_trigger = !edge;
  79. }
  80. if(force != prev_force) /* force type has changed */
  81. {
  82. prev_force = force;
  83. if(force && (trigger == edge))
  84. {
  85. show = true;
  86. }
  87. }
  88. if(trigger != prev_trigger) /* trigger has changed */
  89. {
  90. prev_trigger = trigger;
  91. if(trigger == edge)
  92. {
  93. show = true;
  94. }
  95. }
  96. if(show)
  97. {
  98. rtapi_print_msg(RTAPI_MSG_ERR, messages[myidx]);
  99. }
  100. }
  101.  
  102. EXTRA_SETUP(){
  103. myidx = extra_arg;
  104. if(myidx<0 || myidx >15)
  105. {
  106. rtapi_print_msg(RTAPI_MSG_ERR,"Count of names= is outside the allowable range 0..15\n");
  107. return -EINVAL;
  108. }
  109. if(messages[myidx] == 0)
  110. {
  111. rtapi_print_msg(RTAPI_MSG_ERR,"Message string for index %d missing\n", myidx);
  112. return -EINVAL;
  113. }
  114. return(0);
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement