how do you create objects and methods with squirrel?
Here is a fragment of one from my reflow oven project. I cut out a bunch of the functions because it is redundant to show that over and over. I put a reference to an output port inside the object but that really isn’t necessary in this case; I was just checking if I could do that.
There doesn’t seem to be a notation for public or private methods but I tried to code with the idea of only using some of the functions outside the object.
hope it helps,
`
class ProcessTemperature {
//This is how you add a class name in Squirrel, but we don't need it
static classname="Process temperature node";
//This is not used, but it could be if we implement multiple temperature
//sensors
idNumber =null; //Change this during construction and ONLY then
CurrentTemp = null;
PreviousTemp = null;
OutputInstance=null; //This will be an output port (noodle)
constructor(number,myport)
{
idNumber = number;
OutputInstance = myport;
CurrentTemp=0;
PreviousTemp= 0;
}
function getTempinC(){
local tempC = 1.0;
tempC = ((tempC*CurrentTemp)/::SCALE);//gets value in FLOAT
return tempC;
}
function write(temperature){
OutputInstance.set(temperature); //use this to write to the output port
}
}//end class
//Constructs new object of this type and assigns index letter 2
outputTemperature <- OutputPort(“Temperature”,“number”);
OvenTempMgr <- ProcessTemperature(2,outputTemperature); //Creates an instance of a class and assigns the output node
`
I’ll give this a try,
thanks