2016年9月18日日曜日

再修正「簡易ポーズエディタ」

修正「簡易ポーズエディタ」 で作ったスクリプトの再修正
例によって、上部のボタンは意味なし 。

原点に対する補正値を入れられるようにした。
起動時に、原点復帰を行う。

  1. #!/bin/bash
  2.  
  3. export test00='
  4. echo $USER
  5. '
  6. export SERVO0='50'
  7. export SERVO1='50'
  8. export SERVO2='50'
  9. export SERVO3='50'
  10. export SERVO4='50'
  11. export SERVO5='50'
  12. export SERVO6='50'
  13. export SERVO7='50'
  14.  
  15. #原点に対する補正値の設定
  16. export ADJUST0='4'
  17. export ADJUST1='3'
  18. export ADJUST2='-3'
  19. export ADJUST3='5'
  20. export ADJUST4='-4'
  21. export ADJUST5='-3'
  22. export ADJUST6='1'
  23. export ADJUST7='-3'
  24.  
  25. for((i = 0; i <= 7; i++)); do
  26. echo $i=$((SERVO$i + ADJUST$i))% > /dev/servoblaster
  27. done
  28.  
  29. export MAIN_DIALOG='
  30. <window>
  31. <vbox>
  32. <hbox>
  33. <vbox>
  34. <hbox>
  35. <frame サーボ5(%)>
  36. <vscale height-request="200" range-min="10" range-max="90" range-step="1">
  37. <default>50</default>
  38. <variable>SERVO5</variable>
  39. <action>bash -c "echo 5="$((SERVO5 + ADJUST5))"% > /dev/servoblaster"</action>
  40. <action type="refresh">TEXT5</action>
  41. </vscale>
  42. </frame>
  43. <frame サーボ4(%)>
  44. <vscale height-request="200" range-min="10" range-max="90" range-step="1">
  45. <default>50</default>
  46. <variable>SERVO4</variable>
  47. <action>bash -c "echo 4="$((SERVO4 + ADJUST4))"% > /dev/servoblaster"</action>
  48. <action type="refresh">TEXT4</action>
  49. </vscale>
  50. </frame>
  51. </hbox>
  52. <hbox>
  53. <frame サーボ7(%)>
  54. <vscale height-request="200" range-min="10" range-max="90" range-step="1" inverted="true">
  55. <default>50</default>
  56. <variable>SERVO7</variable>
  57. <action>bash -c "echo 7="$((SERVO7 + ADJUST7))"% > /dev/servoblaster"</action>
  58. <action type="refresh">TEXT7</action>
  59. </vscale>
  60. </frame>
  61. <frame サーボ6(%)>
  62. <vscale height-request="200" range-min="10" range-max="90" range-step="1">
  63. <default>50</default>
  64. <variable>SERVO6</variable>
  65. <action>bash -c "echo 6="$((SERVO6 + ADJUST8))"% > /dev/servoblaster"</action>
  66. <action type="refresh">TEXT6</action>
  67. </vscale>
  68. </frame>
  69. </hbox>
  70. </vbox>
  71.  
  72. <vbox>
  73. <hbox>
  74. <button>
  75. <label>ボタン 1</label>
  76. <action>echo $LANG</action>
  77. </button>
  78. <vbox>
  79. <button width-request="110">
  80. <label>前進</label>
  81. <action>bash -c "$test00"</action>
  82. </button>
  83. <button>
  84. <label>後退</label>
  85. </button>
  86. </vbox>
  87. <button>
  88. <label>ボタン 4</label>
  89. </button>
  90. </hbox>
  91. <vbox>
  92. <frame>
  93. <text>
  94. <variable>TEXT0</variable>
  95. <input>echo "echo 0="$SERVO0"% > /dev/servoblaster"</input>
  96. </text>
  97. <text>
  98. <variable>TEXT1</variable>
  99. <input>echo "echo 1="$SERVO1"% > /dev/servoblaster"</input>
  100. </text>
  101. <text>
  102. <variable>TEXT2</variable>
  103. <input>echo "echo 2="$SERVO2"% > /dev/servoblaster"</input>
  104. </text>
  105. <text>
  106. <variable>TEXT3</variable>
  107. <input>echo "echo 3="$SERVO3"% > /dev/servoblaster"</input>
  108. </text>
  109. <text>
  110. <variable>TEXT4</variable>
  111. <input>echo "echo 4="$SERVO4"% > /dev/servoblaster"</input>
  112. </text>
  113. <text>
  114. <variable>TEXT5</variable>
  115. <input>echo "echo 5="$SERVO5"% > /dev/servoblaster"</input>
  116. </text>
  117. <text>
  118. <variable>TEXT6</variable>
  119. <input>echo "echo 6="$SERVO6"% > /dev/servoblaster"</input>
  120. </text>
  121. <text>
  122. <variable>TEXT7</variable>
  123. <input>echo "echo 7="$SERVO7"% > /dev/servoblaster"</input>
  124. </text>
  125. </frame>
  126. </vbox>
  127. <entry>
  128. <variable>FILE0</variable>
  129. <default>"./temp.txt"</default>
  130. </entry>
  131. <button>
  132. <label>新規作成</label>
  133. <action>echo "#!/bin/bash" > $FILE0</action>
  134. <action>echo "" >> $FILE0</action>
  135. <action>echo "echo 0="$((SERVO0 + ADJUST0))"% > /dev/servoblaster" >> $FILE0</action>
  136. <action>echo "echo 1="$((SERVO1 + ADJUST1))"% > /dev/servoblaster" >> $FILE0</action>
  137. <action>echo "echo 2="$((SERVO2 + ADJUST2))"% > /dev/servoblaster" >> $FILE0</action>
  138. <action>echo "echo 3="$((SERVO3 + ADJUST3))"% > /dev/servoblaster" >> $FILE0</action>
  139. <action>echo "echo 4="$((SERVO4 + ADJUST4))"% > /dev/servoblaster" >> $FILE0</action>
  140. <action>echo "echo 5="$((SERVO5 + ADJUST5))"% > /dev/servoblaster" >> $FILE0</action>
  141. <action>echo "echo 6="$((SERVO6 + ADJUST6))"% > /dev/servoblaster" >> $FILE0</action>
  142. <action>echo "echo 7="$((SERVO7 + ADJUST7))"% > /dev/servoblaster" >> $FILE0</action>
  143. </button>
  144. <button>
  145. <label>ポーズ追加</label>
  146. <action>echo "" >> $FILE0</action>
  147. <action>echo "sleep 1" >> $FILE0</action>
  148. <action>echo "" >> $FILE0</action>
  149. <action>echo "echo 0="$((SERVO0 + ADJUST0))"% > /dev/servoblaster" >> $FILE0</action>
  150. <action>echo "echo 1="$((SERVO1 + ADJUST1))"% > /dev/servoblaster" >> $FILE0</action>
  151. <action>echo "echo 2="$((SERVO2 + ADJUST2))"% > /dev/servoblaster" >> $FILE0</action>
  152. <action>echo "echo 3="$((SERVO3 + ADJUST3))"% > /dev/servoblaster" >> $FILE0</action>
  153. <action>echo "echo 4="$((SERVO4 + ADJUST4))"% > /dev/servoblaster" >> $FILE0</action>
  154. <action>echo "echo 5="$((SERVO5 + ADJUST5))"% > /dev/servoblaster" >> $FILE0</action>
  155. <action>echo "echo 6="$((SERVO6 + ADJUST6))"% > /dev/servoblaster" >> $FILE0</action>
  156. <action>echo "echo 7="$((SERVO7 + ADJUST7))"% > /dev/servoblaster" >> $FILE0</action>
  157. </button>
  158. </vbox>
  159.  
  160. <vbox>
  161. <hbox>
  162. <frame サーボ0(%)>
  163. <vscale height-request="200" range-min="10" range-max="90" range-step="1" inverted="true">
  164. <default>50</default>
  165. <variable>SERVO0</variable>
  166. <action>bash -c "echo 0="$((SERVO0 + ADJUST0))"% > /dev/servoblaster"</action>
  167. <action type="refresh">TEXT0</action>
  168. </vscale>
  169. </frame>
  170. <frame サーボ1(%)>
  171. <vscale height-request="200" range-min="10" range-max="90" range-step="1" inverted="true">
  172. <default>50</default>
  173. <variable>SERVO1</variable>
  174. <action>bash -c "echo 1="$((SERVO1 + ADJUST1))"% > /dev/servoblaster"</action>
  175. <action type="refresh">TEXT1</action>
  176. </vscale>
  177. </frame>
  178. </hbox>
  179. <hbox>
  180. <frame サーボ2(%)>
  181. <vscale height-request="200" range-min="10" range-max="90" range-step="1" inverted="true">
  182. <default>50</default>
  183. <variable>SERVO2</variable>
  184. <action>bash -c "echo 2="$((SERVO2 + ADJUST2))"% > /dev/servoblaster"</action>
  185. <action type="refresh">TEXT2</action>
  186. </vscale>
  187. </frame>
  188. <frame サーボ3(%)>
  189. <vscale height-request="200" range-min="10" range-max="90" range-step="1">
  190. <default>50</default>
  191. <variable>SERVO3</variable>
  192. <action>bash -c "echo 3="$((SERVO3 + ADJUST3))"% > /dev/servoblaster"</action>
  193. <action type="refresh">TEXT3</action>
  194. </vscale>
  195. </frame>
  196. </hbox>
  197. </vbox>
  198. </hbox>
  199. </vbox>
  200. </window>
  201. '
  202.  
  203. gtkdialog -p MAIN_DIALOG -c