Herrpaule

test2

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