Here is a sneak peek at one of the simplest CAD blocks - the input CAD block.
Code: Select all
/* 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 com.holycityaudio.SpinCAD.SpinCADBlock;
import com.holycityaudio.SpinCAD.SpinCADPin;
import com.holycityaudio.SpinCAD.fxblocks.basic.SpinFXBlock;
public class InputCADBlock extends SpinCADBlock{
/**
*
*/
private static final long serialVersionUID = -4680315672929089295L;
public InputCADBlock(int x, int y) {
super(x, y);
addOutputPin(this);
addOutputPin(this);
setName("Input");
setBorderColor(Color.darkGray);
}
public void generateCode(SpinFXBlock eP) {
System.out.println("Input codegen!");
SpinCADPin p = this.getPin("Output 1");
p.setRegister(ADCL);
p = this.getPin("Output 2");
p.setRegister(ADCR);
}
}
We'll skip the "super(x,y)" statement to start.
Code: Select all
addOutputPin(this);
addOutputPin(this);
setName("Input");
setBorderColor(Color.darkGray);
1) Add an output pin.
2) Add another output pin.
3) Set the name of this block to "Input"
4) Set the border color to dark gray. This color is used to draw the block.
So, for each type of block, you add pins (they can be input, output, control input, or control output), give the block a name (which is displayed on the block) and set the color.
You can also create intermediate classes to group your blocks according to some parameter. For example, ModulationCADBlocks are all green and have a minimum of one input pin, while POTCADBlocks are all pink and have a single control output.
Below this we have the "generateCode" function that is part of all SpinCADBlocks and is called every time we add or delete a block, make a connection, and for good measure, just before we run the simulator or save the Spin ASM file.
Code: Select all
public void generateCode(SpinFXBlock eP) {
System.out.println("Input codegen!");
SpinCADPin p = this.getPin("Output 1");
p.setRegister(ADCL);
p = this.getPin("Output 2");
p.setRegister(ADCR);
}
However it DOES associate the Output 1 pin with FV-1 register ADCL and the Output 2 pin with register ADCR. You'll see how this is used when I describe the OutputCADBlock class.