diff --git a/library_surveyor.c b/library_surveyor.c index d86d225..9eef65b 100644 --- a/library_surveyor.c +++ b/library_surveyor.c @@ -2,7 +2,7 @@ static int Blobcnt, Blobx1, Blobx2, Bloby1, Bloby2, Iy1, Iy2, Iu1, Iu2, Iv1, Iv2; static int GPSlat, GPSlon, GPSalt, GPSfix, GPSsat, GPSutc, Elcount, Ercount; -static int ScanVect[16]; +static int ScanVect[16], NNVect[NUM_OUTPUT]; void PlatformLibraryInit() { @@ -10,6 +10,7 @@ void PlatformLibraryInit() IntArrayType = TypeGetMatching(NULL, &IntType, TypeArray, 16, NULL); VariableDefinePlatformVar(NULL, "scanvect", IntArrayType, (union AnyValue *)&ScanVect, FALSE); + VariableDefinePlatformVar(NULL, "neuron", IntArrayType, (union AnyValue *)&NNVect, FALSE); VariableDefinePlatformVar(NULL, "blobcnt", &IntType, (union AnyValue *)&Blobcnt, FALSE); VariableDefinePlatformVar(NULL, "blobx1", &IntType, (union AnyValue *)&Blobx1, FALSE); VariableDefinePlatformVar(NULL, "blobx2", &IntType, (union AnyValue *)&Blobx2, FALSE); @@ -323,9 +324,9 @@ void Cvpix(struct ParseState *Parser, struct Value *ReturnValue, struct Value ** x = Param[0]->Val->Integer; y = Param[1]->Val->Integer; ix = vpix((unsigned char *)FRAME_BUF, x, y); - Iy1 = ((ix>>16) & 0x000000FF); // Y1 - Iu1 = ((ix>>24) & 0x000000FF); // U - Iv1 = ((ix>>8) & 0x000000FF); // V + Iy1 = ((ix>>16) & 0x000000FF); // Y1 + Iu1 = ((ix>>24) & 0x000000FF); // U + Iv1 = ((ix>>8) & 0x000000FF); // V } void Cvscan(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) @@ -343,11 +344,11 @@ void Cvscan(struct ParseState *Parser, struct Value *ReturnValue, struct Value * void Cvmean(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { - vmean((unsigned char *)FRAME_BUF); + vmean((unsigned char *)FRAME_BUF); Iy1 = mean[0]; Iu1 = mean[1]; Iv1 = mean[2]; -} +} // search for blob by color, index; return center point X,Y and width Z void Cvblob(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { @@ -362,7 +363,7 @@ void Cvblob(struct ParseState *Parser, struct Value *ReturnValue, struct Value * numblob = vblob((unsigned char *)FRAME_BUF, (unsigned char *)FRAME_BUF3, ix); - if (blobcnt[iblob] == 0) { + if ((blobcnt[iblob] == 0) || (numblob == -1)) { Blobcnt = 0; } else { Blobcnt = blobcnt[iblob]; @@ -374,6 +375,39 @@ void Cvblob(struct ParseState *Parser, struct Value *ReturnValue, struct Value * ReturnValue->Val->Integer = numblob; } +void Cvjpeg (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { + unsigned int image_size, qual; + unsigned char *output_start, *output_end; + + qual = Param[0]->Val->Integer; + if ((qual < 1) || (qual > 8)) + ProgramFail(NULL, "vjpeg(): quality parameter out of range"); + + output_start = (unsigned char *)JPEG_BUF; + output_end = encode_image((unsigned char *)FRAME_BUF, output_start, qual, + FOUR_TWO_TWO, imgWidth, imgHeight); + image_size = (unsigned int)(output_end - output_start); + + ReturnValue->Val->Integer = image_size; +} + +void Cvsend (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { + unsigned int ix, image_size; + unsigned char *cp; + + image_size = Param[0]->Val->Integer; + if ((image_size < 0) || (image_size > 200000)) + ProgramFail(NULL, "vsend(): image size out of range"); + + led1_on(); + + cp = (unsigned char *)JPEG_BUF; + for (ix=0; ixVal->Integer = ix; } void Cnnmatchblob(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { - int ix, i1; + int ix, i1, max; ix = Param[0]->Val->Integer; if (ix > MAX_BLOBS) @@ -640,9 +681,16 @@ void Cnnmatchblob(struct ParseState *Parser, struct Value *ReturnValue, struct V nnscale8x8((unsigned char *)FRAME_BUF3, blobix[ix], blobx1[ix], blobx2[ix], bloby1[ix], bloby2[ix], imgWidth, imgHeight); nncalculate_network(); - for (i1=0; i1Val->Integer = ix; } void Cnnlearnblob (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { @@ -657,6 +705,23 @@ void Cnnlearnblob (struct ParseState *Parser, struct Value *ReturnValue, struct bloby1[0], bloby2[0], imgWidth, imgHeight); nnpack8x8(ix); nndisplay(ix); +} + +void Cautorun (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { + int ix, t0; + unsigned char ch; + + ix = Param[0]->Val->Integer; + t0 = readRTC(); + while (readRTC() < (t0 + ix*1000)) { // watch for ESC in 'ix' seconds + if (getchar(&ch)) { + if (ch == 0x1B) { // if ESC found, exit picoC + printf("found ESC\r\n"); + ExitBuf[40] = 1; + longjmp(ExitBuf, 1); + } + } + } } /* list of all library functions and their prototypes */ @@ -691,6 +756,8 @@ struct LibraryFunction PlatformLibrary[] = { Cvscan, "int vscan(int, int)" }, { Cvmean, "void vmean()" }, { Cvblob, "int vblob(int, int)" }, + { Cvjpeg, "int vjpeg(int)" }, + { Cvsend, "void vsend(int)" }, { Ccompass, "int compass()" }, { Canalog, "int analog(int)" }, { Ctilt, "int tilt(int)" }, @@ -711,9 +778,10 @@ struct LibraryFunction PlatformLibrary[] = { Cnnset, "void nnset(int, int, int, int, int, int, int, int, int)" }, { Cnninit, "void nninit()" }, { Cnntrain, "void nntrain()" }, - { Cnntest, "void nntest(int, int, int, int, int, int, int, int)" }, - { Cnnmatchblob, "void nnmatchblob(int)" }, + { Cnntest, "int nntest(int, int, int, int, int, int, int, int)" }, + { Cnnmatchblob, "int nnmatchblob(int)" }, { Cnnlearnblob, "void nnlearnblob(int)" }, + { Cautorun, "void autorun(int)" }, { NULL, NULL } }; diff --git a/picoc.c b/picoc.c index 2db57be..672cae7 100644 --- a/picoc.c +++ b/picoc.c @@ -64,8 +64,8 @@ int picoc(char *SourceStr) for (ix=0; ix