Herrpaule

test script

Feb 22nd, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 6.83 KB | None | 0 0
  1. <objdefs>
  2.    <obj.normal id="scripti" uuid="658fd6b9f34d62a11628565d2b24884665e6af99" sha="362a4413ceaefbe716480bf8f9c62eb3587fe6c0">
  3.       <upgradeSha>4ff07e359d2eb13dc0829312e7ab0427616949aa</upgradeSha>
  4.       <sDescription>script with 2 inputs and 2 outputs, running in a separate thread, you must define &quot;void setup(void){}&quot; and &quot;void loop(void)&quot;</sDescription>
  5.       <author>paul</author>
  6.       <license>BSD</license>
  7.       <inlets>
  8.          <frac32 name="in1_" description="in1"/>
  9.          <frac32 name="in2_" description="in2"/>
  10.       </inlets>
  11.       <outlets>
  12.          <frac32 name="out1_" description="out1"/>
  13.          <frac32 name="out2_" description="out2"/>
  14.       </outlets>
  15.       <displays/>
  16.       <params/>
  17.      
  18.  
  19.  
  20.  
  21.       <attribs>
  22.  
  23.         <text name="script"/>
  24.      
  25.         <sText><![CDATA[
  26.            uint8_t *txbuf;
  27.            uint8_t *rxbuf;
  28.  
  29.            int pin = 0;
  30.  
  31.            void setup(void){
  32.              static uint8_t _txbuf[8] __attribute__ ((section (".sram2")));
  33.              static uint8_t _rxbuf[8] __attribute__ ((section (".sram2")));
  34.              txbuf = _txbuf;
  35.              rxbuf = _rxbuf;
  36.  
  37.              palSetPadMode(GPIOA,2,PAL_MODE_OUTPUT_PUSHPULL);
  38.              palWritePad(GPIOA,2,1);
  39.              palSetPadMode(GPIOA,3,PAL_MODE_OUTPUT_PUSHPULL);
  40.              palWritePad(GPIOA,3,1);
  41.            }
  42.  
  43.            void loop(void){
  44.  
  45.              
  46.              txbuf[2] = 0b00000000;
  47.              
  48.                  for(int pin=0; pin<8; pin++){
  49.            
  50.                      txbuf[0] = pin < 4 ? 0b01100000 : 0b11100000;
  51.              
  52.                      if (pin % 4 == 0) { // pin == 0 || pin == 4
  53.                          txbuf[1] = 0b00000000;
  54.                      } else if (pin % 4 == 1) { // pin == 1 || pin == 5
  55.                          txbuf[1] = 0b00000010;
  56.                      } else if (pin % 4 == 2) { // pin == 2 || pin == 6
  57.                          txbuf[1] = 0b00000001;
  58.                      } else {
  59.                          txbuf[1] = 0b00000011;
  60.                      }
  61.                  
  62.  
  63.  
  64.                
  65.                palWritePad(GPIOA,3,0);
  66.                spiSelect(&SPID1);    // START SPI
  67.                spiSend(&SPID1,3,txbuf);
  68.                spiReceive(&SPID1,3,rxbuf);
  69.                spiUnselect(&SPID1);
  70.                palWritePad(GPIOA,3,1);
  71.  
  72.              
  73.                int z = (rxbuf[1] << 8| rxbuf[0]) << 16;
  74.  
  75.  
  76.  
  77.                if (pin == 0){
  78.                  PExParameterChange(&parent->PExch[PARAM_INDEX_cv0_value],z,0xFFFD);
  79.                }
  80.                else if (pin == 1){
  81.                  PExParameterChange(&parent->PExch[PARAM_INDEX_cv1_value],z,0xFFFD);
  82.                }
  83.                else if (pin == 2){
  84.                  PExParameterChange(&parent->PExch[PARAM_INDEX_cv2_value],z,0xFFFD);
  85.                }
  86.                else if (pin == 3){
  87.                  PExParameterChange(&parent->PExch[PARAM_INDEX_cv3_value],z,0xFFFD);
  88.                }
  89.                else if (pin == 4){
  90.                  PExParameterChange(&parent->PExch[PARAM_INDEX_cv4_value],z,0xFFFD);
  91.                }
  92.                else if (pin == 5){
  93.                  PExParameterChange(&parent->PExch[PARAM_INDEX_cv5_value],z,0xFFFD);
  94.                }
  95.                else if (pin == 6){
  96.                  PExParameterChange(&parent->PExch[PARAM_INDEX_cv6_value],z,0xFFFD);
  97.                }
  98.                else if (pin == 7){
  99.                  PExParameterChange(&parent->PExch[PARAM_INDEX_cv7_value],z,0xFFFD);
  100.                }
  101.                
  102.                chThdSleepMilliseconds(1);
  103.  
  104.                  }
  105.                  
  106.                  txbuf[2] = 0b00000000;
  107.              
  108.                  for(int pin=0; pin<8; pin++){
  109.            
  110.                      txbuf[0] = pin < 4 ? 0b01100000 : 0b11100000;
  111.              
  112.                      if (pin % 4 == 0) { // pin == 0 || pin == 4
  113.                          txbuf[1] = 0b00000000;
  114.                      } else if (pin % 4 == 1) { // pin == 1 || pin == 5
  115.                          txbuf[1] = 0b00000010;
  116.                      } else if (pin % 4 == 2) { // pin == 2 || pin == 6
  117.                          txbuf[1] = 0b00000001;
  118.                      } else {
  119.                          txbuf[1] = 0b00000011;
  120.                      }
  121.                  
  122.  
  123.  
  124.                
  125.                palWritePad(GPIOA,2,0);
  126.                spiSelect(&SPID1);    // START SPI
  127.                spiSend(&SPID1,3,txbuf);
  128.                spiReceive(&SPID1,3,rxbuf);
  129.                spiUnselect(&SPID1);
  130.                palWritePad(GPIOA,2,1);
  131.  
  132.              
  133.                int z = 0x07FFFFFF - ((rxbuf[1] << 8| rxbuf[0]) << 16);
  134.              
  135.              
  136.                if (pin == 0){
  137.                  PExParameterChange(&parent->PExch[PARAM_INDEX_p0_value],z,0xFFFD);
  138.                }
  139.                else if (pin == 1){
  140.                  PExParameterChange(&parent->PExch[PARAM_INDEX_p1_value],z,0xFFFD);
  141.                }
  142.                else if (pin == 2){
  143.                  PExParameterChange(&parent->PExch[PARAM_INDEX_p2_value],z,0xFFFD);
  144.                }
  145.                else if (pin == 3){
  146.                  PExParameterChange(&parent->PExch[PARAM_INDEX_p3_value],z,0xFFFD);
  147.                }
  148.                else if (pin == 4){
  149.                  PExParameterChange(&parent->PExch[PARAM_INDEX_p4_value],z,0xFFFD);
  150.                }
  151.                else if (pin == 5){
  152.                  PExParameterChange(&parent->PExch[PARAM_INDEX_p5_value],z,0xFFFD);
  153.                }
  154.                else if (pin == 6){
  155.                  PExParameterChange(&parent->PExch[PARAM_INDEX_p6_value],z,0xFFFD);
  156.                }
  157.                else if (pin == 7){
  158.                  PExParameterChange(&parent->PExch[PARAM_INDEX_p7_value],(z),0xFFFD);
  159.                }
  160.                
  161.                chThdSleepMilliseconds(1);
  162.                  }
  163.              
  164.            }]]></sText>
  165.          
  166.       </attribs>
  167.  
  168.       <code.declaration><![CDATA[int32_t in1,in2;
  169. int32_t out1,out2;
  170. attr_script
  171. msg_t ThreadX2(){
  172.  setup();
  173.  while(!chThdShouldTerminate()){
  174.     loop();
  175.     chThdSleepMilliseconds(1);
  176.  }
  177.  chThdExit((msg_t)0);
  178. }
  179. static msg_t ThreadX(void *arg) {
  180. ((attr_parent *)arg)->ThreadX2();
  181. }
  182. WORKING_AREA(waThreadX, 1024);
  183. Thread *Thd;
  184. ]]></code.declaration>
  185.       <code.init><![CDATA[in1=0;in2=0;out1=0;out2=0;
  186.  Thd = chThdCreateStatic(waThreadX, sizeof(waThreadX),
  187.                    NORMALPRIO, ThreadX, (void *)this);
  188. ]]></code.init>
  189.       <code.dispose><![CDATA[chThdTerminate(Thd);
  190. chThdWait(Thd);
  191. ]]></code.dispose>
  192.       <code.krate><![CDATA[outlet_out1__ = this->out1;
  193. outlet_out2__ = this->out2;
  194. this->in1 = inlet_in1__;
  195. this->in2 = inlet_in2__;
  196. ]]></code.krate>
  197.    </obj.normal>
  198. </objdefs>
Advertisement
Add Comment
Please, Sign In to add comment