void readSettings() {
	int n,cc;
	char ch, buff[24];
	char  buff2[80];
	unsigned int ndx=0;
	int read=0;
    if (!settingsFile.open(&root, settingsFileName, O_READ)) {
        console.printf("DBG: Creating New Settings File\r\n"); console.flush();
        writeSettings();
        return;
	}
    console.printf("DBG: Opened Settings File: %s\r\n",settingsFileName);
	settingsFile.seekSet(0);
	while ((read=settingsFile.read(buff, sizeof(buff))) > 0) {
        //console.printf("DBG: READ %d\r\n",read); console.flush();
        for (cc=0; cc < read ; cc++) {
            
            ch=buff[cc];
            //console.putChar(ch); console.flush();
            buff2[ndx]=ch;
            if (ndx<MAX_INPUT_LINE) {ndx++;}
            if (ch=='\n'){//console.putChar('\r');
                if(ndx) {
                    ndx--; // eat the newline.
                }
                buff2[ndx]='\0';
                //console.puts(buff2);
                if ((ndx>4) && buff2[3]=='!') {//fix this when the files are better
                    buff2[3]='\0';
                    n=lookupIndex(buff2);
                    switch (n) {
                        case _NPW_:
                            networkSetPassword(buff2+4);
                            break;
                        case _NJN_:
                            Watchdog_Reset();
                            networkJoin(buff2 +4);
                            break;
                        case _PKY_:
                            strncpy(pachubeKey, buff2+4, MAX_PATCHUBE_KEY_LENGHT-1);
                            break;
                        case _PFD_:
                            strncpy(pachubeFeed, buff2+4, MAX_PATCHUBE_FEED_LENGHT-1);
                            break;
                        default:
                            break;
                    }
                    
                }
            
                ndx=0; 

            }
        }
    }
    
    console.printf("DBG: Finished with Settings File: %s\r\n",settingsFileName);
    
	settingsFile.close();
}
void parseLine(cmdBuffer *buff) {
    // should check for more than 4 characters
    buff->args=(buff->line)+4; 
    buff->verb=buff->line[3];
    //buff->line[3]='\0';
    buff->kwIndex=lookupIndex(buff->line);
}
bool DataStream::gotLine(unsigned int timeout=5000) {
    char ch=0;
    bool retval=false;
	unsigned long int mark=millis();
    if(available()){
        while( (millis()-mark < timeout) && available() && _ndx < 99 && ((ch=read()) != '\n') && ch !='\r' ) {
            _buf[_ndx++] = ch; 
        }        
        if (_ndx && ((ch=='\n')||(ch=='\r'))) { // should probably check if line is at least 4 chars.
            _buf[_ndx++]='\r';
            _buf[_ndx++]='\n';
            _buf[_ndx]='\0';
            _ndx=0;
            //_gotLine=
            retval=true;
            _key[0]=_buf[0];
            _key[1]=_buf[1];
            _key[2]=_buf[2];
            _key[3]='\0';
            _action=_buf[3];
            _keyVal=lookupIndex(_key);
        }
    }
    return retval;
}    
Exemple #4
0
/**
 * @brief This takes a letter and encodes it.
 *
 * This process is fairly straightforward.  It does a lookup
 * of where the letter would normally occur and then goes to that position
 * in ctx->alphabet given the starting point of ctx->current.
 *
 * ctx->current is then updated to reflect that the starting point in the
 * alphabet has now changed.  (>= end).
 */
static char
encode(
    char letter,
    Encoder_Context *ctx)
{
    char ret;
    uint8_t indx = lookupIndex(letter);
    uint8_t ofs;

    /* if the indx is beyond where we are, the therefore behind current */
    if (indx >= (ctx->end - ctx->current))
    {
        ofs = indx - (ctx->end - ctx->current);

        ret = ctx->alphabet[ofs];
    }
    else
    {
        ret = ctx->current[indx];
    }

    /* adjust substitution table */
    ctx->current += 1;

    if (ctx->current >= ctx->end)
    {
        ctx->current = ctx->alphabet;
    }

    return ret;
}
Exemple #5
0
static int
rotate(
    char letter,
    Encoder_Context *ctx)
{
    uint8_t indx = lookupIndex(letter);
    uint32_t i;
    char move;

    if (indx > sizeof(ctx->alphabet))
    {
        return -1;
    }

    move = ctx->alphabet[indx];

    for (i = indx; i < (sizeof(ctx->alphabet) - 1); i++)
    {
        ctx->alphabet[i] = ctx->alphabet[i+1];
    }

    ctx->alphabet[sizeof(ctx->alphabet) - 1] = move;

    return 0;
}
void parseLine(cmdBuffer *buff) {
    // should check for more than 4 characters
    buff->args=buff->line+4; 
    buff->verb=buff->line[3];
    //buff->line[3]='\0'; // dont need this since lookupindex uses tcharacters
    
    buff->kwIndex=lookupIndex(buff->line);
}
Exemple #7
0
TableOscUGenInternalK::TableOscUGenInternalK(UGen const& freq, 
											 const float initialPhase, 
											 Buffer const& table) throw()
:	TableOscUGenInternal(freq, initialPhase, table),
	value(lookupIndex(initialPhase))
{
	rate = ControlRate;
}
Exemple #8
0
void TableOscUGenInternalK::processBlock(bool& shouldDelete, const unsigned int blockID, const int channel) throw()
{	
	const int krBlockSize = UGen::getControlRateBlockSize();
	unsigned int blockPosition = blockID % krBlockSize;
	double krBlockSizeOverSampleRate = UGen::getReciprocalSampleRate() * krBlockSize;
	int numSamplesToProcess = uGenOutput.getBlockSize();
	float* outputSamples = uGenOutput.getSampleData();
	float* freqSamples = inputs[Freq].processBlock(shouldDelete, blockID, channel);
	
	int numKrSamples = blockPosition % krBlockSize;
	
	while(numSamplesToProcess > 0)
	{
		float nextValue = value;
		
		if(numKrSamples == 0)			
		{
			nextValue = lookupIndex(currentPhase);
			
			currentPhase += *freqSamples * krBlockSizeOverSampleRate * wavetableSize;
			
			while(currentPhase >= wavetableSize)	currentPhase -= wavetableSize;
			while(currentPhase < 0.f)				currentPhase += wavetableSize;
		}
		
		numKrSamples = krBlockSize - numKrSamples;
		
		blockPosition		+= numKrSamples;
		freqSamples			+= numKrSamples;
		
		if(nextValue == value)
		{
			while(numSamplesToProcess && numKrSamples)
			{
				*outputSamples++ = nextValue;
				--numSamplesToProcess;
				--numKrSamples;
			}
		}
		else
		{
			float valueSlope = (nextValue - value) / (float)UGen::getControlRateBlockSize();
			
			while(numSamplesToProcess && numKrSamples)
			{
				*outputSamples++ = value;
				value += valueSlope;
				--numSamplesToProcess;
				--numKrSamples;
			}
			
			value = nextValue;
		}
	}
}
Exemple #9
0
void TableOscUGenInternal::processBlock(bool& shouldDelete, const unsigned int blockID, const int channel) throw()
{	
	float tableSizeOverSampleRate = UGen::getReciprocalSampleRate() * wavetableSize;
	int numSamplesToProcess = uGenOutput.getBlockSize();
	float* outputSamples = uGenOutput.getSampleData();
	float* freqSamples = inputs[Freq].processBlock(shouldDelete, blockID, channel);
	LOCAL_DECLARE(float, currentPhase);
	LOCAL_DECLARE(float, wavetableSize);
	
	while(numSamplesToProcess--)
	{
		*outputSamples++ = lookupIndex(currentPhase);
		currentPhase += *freqSamples++ * tableSizeOverSampleRate;
		
		if(currentPhase >= wavetableSize)	currentPhase -= wavetableSize;
		else if(currentPhase < 0.f)			currentPhase += wavetableSize;
	}
	
	LOCAL_COPY(currentPhase);
}
Exemple #10
0
BEGIN_UGEN_NAMESPACE

#include "ugen_TableOsc.h"
#include "../../core/ugen_Constants.h"


TableOscUGenInternal::TableOscUGenInternal(UGen const& freq, 
										   const float initialPhase, 
										   Buffer const& table) throw()
:	UGenInternal(NumInputs),
	table_(table),
	wavetableSize(table_.size()),
	wavetable(table_.getData(0)),
	currentPhase((initialPhase < 0.f) || (initialPhase >= 1.f) ? 0.f : initialPhase * wavetableSize)
{
	ugen_assert(initialPhase >= 0.f && initialPhase <= 1.f);
	
	inputs[Freq] = freq;
	initValue(lookupIndex(currentPhase));
}
Exemple #11
0
int
readObj (FILE * fp, objObj obj, nameIndex * mtlIndex)
{
	char line[255];
	enum dataType t;

	float v[3];
	int i;

	int vertexCount = 0;
	int texcoordCount = 0;
	int normalCount = 0;
	int faceCount = 0;
	int currentMaterialIndex = -1;

	while (!readLinePlus (fp, line, &t))
	{
		switch (t)
		{
		case (T_V):
			if (vertexCount >= obj.nbVertex)
			{
				fprintf (stderr,
					 "Problem with vertices Count\n");
				return 1;
			}
			sscanf (line, "%f %f %f", &v[0], &v[1], &v[2]);
			for (i = 0; i < 3; i++)
				obj.vertexList[vertexCount].coords[i] = v[i];
			vertexCount++;
			break;
		case (T_VN):
			if (normalCount >= obj.nbNormal)
			{
				fprintf (stderr,
					 "Problem with normals Count\n");
				return 1;
			}
			sscanf (line, "%f %f %f", &v[0], &v[1], &v[2]);
			for (i = 0; i < 3; i++)
				obj.normalList[normalCount].coords[i] = v[i];
			normalCount++;
			break;
		case (T_VT):
			if (texcoordCount >= obj.nbTexcoord)
			{
				fprintf (stderr,
					 "Problem with texcoords Count\n");
				return 1;
			}
			sscanf (line, "%f %f %f", &v[0], &v[1], &v[2]);
			for (i = 0; i < 3; i++)
				obj.texcoordList[texcoordCount].coords[i] =
					v[i];
			texcoordCount++;
			break;
		case (T_USEMTL):
			if (lookupIndex
			    (mtlIndex, &(obj.nbMaterial), obj.nbMaterial,
			     line, 0, &currentMaterialIndex))
			{
				fprintf (stderr,
					 "Problem with material count\n");
				return 1;
			}
			break;
		case (T_F):
			if (faceCount >= obj.nbFace)
			{
				fprintf (stderr,
					 "Problem with faces Count\n");
				return 1;
			}

			if (readFace
			    (line, &(obj.faceList[faceCount]),
			     currentMaterialIndex))
				return 1;

			faceCount++;
			break;
		default:
			continue;
		}

	}
	return 0;
}
Exemple #12
0
int
readMtl (FILE * fp, objObj obj, nameIndex * mtlIndex, nameIndex * texIndex)
{
	char line[255];
	enum dataType t;
	float v[3];
	int i;
	int texCount;
	int maxTexCount;
	int val;

	int index = -1;

	texCount = 0;
	maxTexCount = 3 * obj.nbMaterial;

	while (!readLinePlus (fp, line, &t))
	{
		if (t == T_NEWMTL)
		{
			index = index + 1;
			strcpy (mtlIndex[index].val, line);
			if (index >= obj.nbMaterial)
			{
				fprintf (stderr,
					 "Problem with materials count\n");
				return 1;
			}
			obj.materialList[index].ambientTexId = -1;
			obj.materialList[index].diffuseTexId = -1;
			obj.materialList[index].specularTexId = -1;
			obj.materialList[index].alpha = 1.0;
			obj.materialList[index].shininess = 0.0;
			obj.materialList[index].refrac = 1.0;
			obj.materialList[index].illumModel = 1;
			for (i = 0; i < 3; i++)
			{
				obj.materialList[index].ambient[i] = 0.2;
				obj.materialList[index].diffuse[i] = 0.8;
				obj.materialList[index].specular[i] = 1.0;
			}
		}
		if (index >= 0)
		{
			switch (t)
			{
			case T_MAP_KA:
				if (lookupIndex
				    (texIndex, &texCount, maxTexCount, line,
				     1,
				     &(obj.materialList[index].ambientTexId)))
				{
					fprintf (stderr,
						 "Problem with textures count\n");
					return 1;
				}
				break;
			case T_MAP_KD:
				if (lookupIndex
				    (texIndex, &texCount, maxTexCount, line,
				     1,
				     &(obj.materialList[index].diffuseTexId)))
				{
					fprintf (stderr,
						 "Problem with textures count\n");
					return 1;
				}
				break;
			case T_MAP_KS:
				if (lookupIndex
				    (texIndex, &texCount, maxTexCount, line,
				     1,
				     &(obj.materialList[index].
				       specularTexId)))
				{
					fprintf (stderr,
						 "Problem with textures count\n");
					return 1;
				}
				break;
			case T_KA:
				sscanf (line, "%f %f %f", &v[0], &v[1],
					&v[2]);
				for (i = 0; i < 3; i++)
					obj.materialList[index].ambient[i] =
						v[i];
				break;
			case T_KD:
				sscanf (line, "%f %f %f", &v[0], &v[1],
					&v[2]);
				for (i = 0; i < 3; i++)
					obj.materialList[index].diffuse[i] =
						v[i];
				break;
			case T_KS:
				sscanf (line, "%f %f %f", &v[0], &v[1],
					&v[2]);
				for (i = 0; i < 3; i++)
					obj.materialList[index].specular[i] =
						v[i];
				break;
			case T_ILLUM:
				sscanf (line, "%d", &val);
				obj.materialList[index].illumModel = val;
			case T_TR:
				sscanf (line, "%f", &v[0]);
				obj.materialList[index].alpha = v[0];
			case T_D:
				sscanf (line, "%f", &v[0]);
				obj.materialList[index].alpha = v[0];
			case T_NS:
				sscanf (line, "%f", &v[0]);
				obj.materialList[index].shininess = v[0];
			case T_NI:
				sscanf (line, "%f", &v[0]);
				obj.materialList[index].refrac = v[0];
			default:
				continue;
			}
		}


	}


	return 0;
}