Spin Semiconductor Forum Index Spin Semiconductor
Support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SpinCAD Designer - the OutputCADBlock

 
Post new topic   Reply to topic    Spin Semiconductor Forum Index -> FV-1 software questions
View previous topic :: View next topic  
Author Message
Digital Larry



Joined: 12 Nov 2012
Posts: 274

PostPosted: Tue Apr 30, 2013 5:47 am    Post subject: SpinCAD Designer - the OutputCADBlock Reply with quote

This is the first SpinCADBlock class I'm showing which actually generates code.

There are some internal parameters, lGain and rGain, which will eventually be adjustable using a popup control panel.

Down in the generateCode() method, you'll see that I query the "Input 1" pin to see if it has a connection. If it doesn't have a connection, that call will return "null". If it DOES have a connection, then I query the pin to see what register has been associated with this pin (which is set by the previous block's generateCode() method. Then I read the register, scale it by the gain value, and write that out to DACL or DACR depending on which Input Pin it was.

There is some extra code in there that verifies that the input register is within an acceptable range. Right now I'm not completely sure that it's necessary.

Code:

/* SpinCAD Designer - DSP Development Tool for the Spin FV-1
 * Copyright (C)2013 - Gary Worsham
 * Based on ElmGen by Andrew Kilpatrick
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *     
 */

package com.holycityaudio.SpinCAD.CADBlocks;

import java.awt.Color;
import java.util.Map;

import com.holycityaudio.SpinCAD.SpinCADBlock;
import com.holycityaudio.SpinCAD.SpinCADPin;
import com.holycityaudio.SpinCAD.fxblocks.basic.SpinFXBlock;

public class OutputCADBlock extends SpinCADBlock{

   /**
    *
    */
   private static final long serialVersionUID = -2094768928842616450L;
   /**
    *
    */
   static double lGain = 1.0;
   static double rGain = 1.0;
   
   public OutputCADBlock(int x, int y) {
      super(x, y);
      addInputPin(this);
      addInputPin(this);
      setName("Output");
      setBorderColor(Color.darkGray);
   }

   public void generateCode(SpinFXBlock eP) {
      System.out.println("Output codegen!");
      // look to see if there is a pin called "Input 1"
      SpinCADPin p = getPin("Input 1").getPinConnection();
      if (p != null) {
      // if there's an "Input 1" pin, request its register value
         int i = p.getRegister();
         if( (i >= 32 && i <= 64) || i == ADCR || i == ADCL) {
            eP.readRegister(i,lGain);
            eP.writeRegister(DACL, 0.0);
         }         
      }

   // look to see if there is a pin called "Input 2"
       p = getPin("Input 2").getPinConnection();
      if (p != null) {
   // if there's an "Input 2" pin, request its register value
         int i = p.getRegister();
         if(( i >= 32 && i <= 64) || i == ADCR || i == ADCL) {
            eP.readRegister(i,rGain);
            eP.writeRegister(DACR, 0.0);
         }
      }
   }
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Spin Semiconductor Forum Index -> FV-1 software questions All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group