Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <objdefs>
- <obj.normal id="scripti" uuid="658fd6b9f34d62a11628565d2b24884665e6af99" sha="362a4413ceaefbe716480bf8f9c62eb3587fe6c0">
- <upgradeSha>4ff07e359d2eb13dc0829312e7ab0427616949aa</upgradeSha>
- <sDescription>script with 2 inputs and 2 outputs, running in a separate thread, you must define "void setup(void){}" and "void loop(void)"</sDescription>
- <author>paul</author>
- <license>BSD</license>
- <inlets>
- <frac32 name="in1_" description="in1"/>
- <frac32 name="in2_" description="in2"/>
- </inlets>
- <outlets>
- <frac32 name="out1_" description="out1"/>
- <frac32 name="out2_" description="out2"/>
- </outlets>
- <displays/>
- <params/>
- <attribs>
- <text name="script">
- <![CDATA[
- uint8_t *txbuf;
- uint8_t *rxbuf;
- int pin = 0;
- void setup(void){
- static uint8_t _txbuf[8] __attribute__ ((section (".sram2")));
- static uint8_t _rxbuf[8] __attribute__ ((section (".sram2")));
- txbuf = _txbuf;
- rxbuf = _rxbuf;
- palSetPadMode(GPIOA,2,PAL_MODE_OUTPUT_PUSHPULL);
- palWritePad(GPIOA,2,1);
- palSetPadMode(GPIOA,3,PAL_MODE_OUTPUT_PUSHPULL);
- palWritePad(GPIOA,3,1);
- }
- void loop(void){
- txbuf[2] = 0b00000000;
- for(int pin=0; pin<8; pin++){
- txbuf[0] = pin < 4 ? 0b01100000 : 0b11100000;
- if (pin % 4 == 0) { // pin == 0 || pin == 4
- txbuf[1] = 0b00000000;
- } else if (pin % 4 == 1) { // pin == 1 || pin == 5
- txbuf[1] = 0b00000010;
- } else if (pin % 4 == 2) { // pin == 2 || pin == 6
- txbuf[1] = 0b00000001;
- } else {
- txbuf[1] = 0b00000011;
- }
- palWritePad(GPIOA,3,0);
- spiSelect(&SPID1); // START SPI
- spiSend(&SPID1,3,txbuf);
- spiReceive(&SPID1,3,rxbuf);
- spiUnselect(&SPID1);
- palWritePad(GPIOA,3,1);
- int z = (rxbuf[1] << 8| rxbuf[0]) << 16;
- if (pin == 0){
- PExParameterChange(&parent->PExch[PARAM_INDEX_cv0_value],z,0xFFFD);
- }
- else if (pin == 1){
- PExParameterChange(&parent->PExch[PARAM_INDEX_cv1_value],z,0xFFFD);
- }
- else if (pin == 2){
- PExParameterChange(&parent->PExch[PARAM_INDEX_cv2_value],z,0xFFFD);
- }
- else if (pin == 3){
- PExParameterChange(&parent->PExch[PARAM_INDEX_cv3_value],z,0xFFFD);
- }
- else if (pin == 4){
- PExParameterChange(&parent->PExch[PARAM_INDEX_cv4_value],z,0xFFFD);
- }
- else if (pin == 5){
- PExParameterChange(&parent->PExch[PARAM_INDEX_cv5_value],z,0xFFFD);
- }
- else if (pin == 6){
- PExParameterChange(&parent->PExch[PARAM_INDEX_cv6_value],z,0xFFFD);
- }
- else if (pin == 7){
- PExParameterChange(&parent->PExch[PARAM_INDEX_cv7_value],z,0xFFFD);
- }
- chThdSleepMilliseconds(1);
- }
- txbuf[2] = 0b00000000;
- for(int pin=0; pin<8; pin++){
- txbuf[0] = pin < 4 ? 0b01100000 : 0b11100000;
- if (pin % 4 == 0) { // pin == 0 || pin == 4
- txbuf[1] = 0b00000000;
- } else if (pin % 4 == 1) { // pin == 1 || pin == 5
- txbuf[1] = 0b00000010;
- } else if (pin % 4 == 2) { // pin == 2 || pin == 6
- txbuf[1] = 0b00000001;
- } else {
- txbuf[1] = 0b00000011;
- }
- palWritePad(GPIOA,2,0);
- spiSelect(&SPID1); // START SPI
- spiSend(&SPID1,3,txbuf);
- spiReceive(&SPID1,3,rxbuf);
- spiUnselect(&SPID1);
- palWritePad(GPIOA,2,1);
- int z = 0x07FFFFFF - ((rxbuf[1] << 8| rxbuf[0]) << 16);
- if (pin == 0){
- PExParameterChange(&parent->PExch[PARAM_INDEX_p0_value],z,0xFFFD);
- }
- else if (pin == 1){
- PExParameterChange(&parent->PExch[PARAM_INDEX_p1_value],z,0xFFFD);
- }
- else if (pin == 2){
- PExParameterChange(&parent->PExch[PARAM_INDEX_p2_value],z,0xFFFD);
- }
- else if (pin == 3){
- PExParameterChange(&parent->PExch[PARAM_INDEX_p3_value],z,0xFFFD);
- }
- else if (pin == 4){
- PExParameterChange(&parent->PExch[PARAM_INDEX_p4_value],z,0xFFFD);
- }
- else if (pin == 5){
- PExParameterChange(&parent->PExch[PARAM_INDEX_p5_value],z,0xFFFD);
- }
- else if (pin == 6){
- PExParameterChange(&parent->PExch[PARAM_INDEX_p6_value],z,0xFFFD);
- }
- else if (pin == 7){
- PExParameterChange(&parent->PExch[PARAM_INDEX_p7_value],(z),0xFFFD);
- }
- chThdSleepMilliseconds(1);
- }
- }]]>
- </text>
- </attribs>
- <code.declaration><![CDATA[int32_t in1,in2;
- int32_t out1,out2;
- attr_script
- msg_t ThreadX2(){
- setup();
- while(!chThdShouldTerminate()){
- loop();
- chThdSleepMilliseconds(1);
- }
- chThdExit((msg_t)0);
- }
- static msg_t ThreadX(void *arg) {
- ((attr_parent *)arg)->ThreadX2();
- }
- WORKING_AREA(waThreadX, 1024);
- Thread *Thd;
- ]]></code.declaration>
- <code.init><![CDATA[in1=0;in2=0;out1=0;out2=0;
- Thd = chThdCreateStatic(waThreadX, sizeof(waThreadX),
- NORMALPRIO, ThreadX, (void *)this);
- ]]></code.init>
- <code.dispose><![CDATA[chThdTerminate(Thd);
- chThdWait(Thd);
- ]]></code.dispose>
- <code.krate><![CDATA[outlet_out1__ = this->out1;
- outlet_out2__ = this->out2;
- this->in1 = inlet_in1__;
- this->in2 = inlet_in2__;
- ]]></code.krate>
- </obj.normal>
- </objdefs>
Advertisement
Add Comment
Please, Sign In to add comment