void ActionNode::start(shared_ptr<InstanceSpecification> host, map<string, shared_ptr<InstanceSpecification> > affectations, bool sync) { if(!_action) { cerr << "[ActionNode Warning] Le noeud "<< getName() << " n'a pas d'action associée !!!" << endl; return; } Parameters param; if (_action->getKind() == "SendSignal") { param = _paramsSendSignal(affectations); } else if (_action->getKind() == "CallOperation") { param = _paramsCallOperation(affectations); } else if (_action->getKind() == "CallBehavior") { param = _paramsCallBehavior(affectations); } { cerr << "Action Kind: " << _action->getKind() << endl; } if (getActivity()) { _action->setContext(getActivity()->getContext()); } _currentExecution = BehaviorScheduler::getInstance()->executeBehavior(_action, host, param,sync); //_currentExecution=_action->createBehaviorExecution(host,param); //_currentExecution->execute(); // a basic action is a one shot action //_currentExecution->stop(); //to say the job is finished (because not done by BehaviorScheduler) }
bool IRP6pServo::configureHook() { if(fabs(getActivity()->getPeriod() - DT) > 0.00001) return false; std::vector<std::string> ports; ports.push_back("/dev/ttyMI0"); ports.push_back("/dev/ttyMI1"); ports.push_back("/dev/ttyMI2"); ports.push_back("/dev/ttyMI3"); ports.push_back("/dev/ttyMI4"); ports.push_back("/dev/ttyMI5"); try { hi_.init(ports); } catch (std::exception& e) { std::cout << e.what() << std::endl; return false; } for(unsigned int i = 0; i < NUMBER_OF_DRIVES; i++) reg_[i].setParam(A[i], BB0[i], BB1[i]); dsrJntPos_.resize(NUMBER_OF_DRIVES); msrJntPos_.resize(NUMBER_OF_DRIVES); cmdJntPos_.resize(NUMBER_OF_DRIVES); return true; }
int MaskFromMemoryBuffer::updateState(double time, double dt) { if (imageLayer->getDataLeft() == dataLeft && imageLayer->getDataTop() == dataTop && imageLayer->getDataWidth() == dataRight-dataLeft && imageLayer->getDataHeight() && dataBottom-dataTop) { return PV_SUCCESS; // mask only needs to change if the imageLayer changes its active region } dataLeft = imageLayer->getDataLeft(); dataRight = dataLeft+imageLayer->getDataWidth(); dataTop = imageLayer->getDataTop(); dataBottom = dataTop + imageLayer->getDataHeight(); PVLayerLoc const * loc = getLayerLoc(); for(int b = 0; b < loc->nbatch; b++) { pvdata_t * ABatch = getActivity() + b * getNumExtended(); int const num_neurons = getNumNeurons(); #ifdef PV_USE_OPENMP_THREADS #pragma omp parallel for #endif for(int ni = 0; ni < num_neurons; ni++) { PVHalo const * halo = &loc->halo; int const nx = loc->nx; int const ny = loc->ny; int const nf = loc->nf; int x = kxPos(ni, nx, ny, nf); int y = kyPos(ni, nx, ny, nf); pvadata_t a = (pvadata_t) (x>=dataLeft && x < dataRight && y >= dataTop && y < dataBottom); int nExt = kIndexExtended(ni, nx, ny, nf, halo->lt, halo->rt, halo->dn, halo->up); ABatch[nExt] = a; } } return PV_SUCCESS; }
EglContext::EglContext(EglContext* shared, const ContextSettings& settings, const WindowImpl* owner, unsigned int bitsPerPixel) : m_display (EGL_NO_DISPLAY), m_context (EGL_NO_CONTEXT), m_surface (EGL_NO_SURFACE), m_config (NULL) { #ifdef SFML_SYSTEM_ANDROID // On Android, we must save the created context ActivityStates* states = getActivity(NULL); Lock lock(states->mutex); states->context = this; #endif // Get the initialized EGL display m_display = getInitializedDisplay(); // Get the best EGL config matching the requested video settings m_config = getBestConfig(m_display, bitsPerPixel, settings); updateSettings(); // Create EGL context createContext(shared); #if !defined(SFML_SYSTEM_ANDROID) // Create EGL surface (except on Android because the window is created // asynchronously, its activity manager will call it for us) createSurface((EGLNativeWindowType)owner->getSystemHandle()); #endif }
ResourceStream::ResourceStream(const std::string& filename) : m_file (NULL) { ActivityStates* states = getActivity(NULL); Lock(states->mutex); m_file = AAssetManager_open(states->activity->assetManager, filename.c_str(), AASSET_MODE_UNKNOWN); }
int SegmentifyTest::updateState(double timef, double dt){ //Do update state first Segmentify::updateState(timef, dt); const PVLayerLoc * loc = getLayerLoc(); pvdata_t * A = getActivity(); assert(A); for(int bi = 0; bi < loc->nbatch; bi++){ pvdata_t * batchA = A + bi * getNumExtended(); for(int yi = 0; yi < loc->ny; yi++){ for(int xi = 0; xi < loc->nx; xi++){ for(int fi = 0; fi < loc->nf; fi++){ int extIdx = (yi + loc->halo.up) * (loc->nx + loc->halo.lt + loc->halo.rt) * loc->nf + (xi + loc->halo.lt) * loc->nf + fi; float actualVal = batchA[extIdx]; float targetVal = getTargetVal(yi+loc->ky0, xi+loc->kx0, fi); checkOutputVals(yi+loc->ky0, xi+loc->kx0, fi, targetVal, actualVal); //std::cout << "Idx: (" << bi << "," << yi << "," << xi << "," << fi << ") Val: " << actualVal << " Target: " << targetVal << "\n"; } } } } return PV_SUCCESS; }
void Mops_Rec::updateHook(){ MyData msg; readMOPS((char*)msg.data, MAX_MESSAGE_LENGTH); _outPort.write(msg); getActivity()->trigger(); if(_verbose) std::cout << "Mops_Rec executes updateHook !" <<std::endl; }
int WindowImplAndroid::getUnicode(AInputEvent* event) { // Retrieve activity states ActivityStates* states = getActivity(NULL); Lock lock(states->mutex); // Initializes JNI jint lResult; jint lFlags = 0; JavaVM* lJavaVM = states->activity->vm; JNIEnv* lJNIEnv = states->activity->env; JavaVMAttachArgs lJavaVMAttachArgs; lJavaVMAttachArgs.version = JNI_VERSION_1_6; lJavaVMAttachArgs.name = "NativeThread"; lJavaVMAttachArgs.group = NULL; lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs); if (lResult == JNI_ERR) err() << "Failed to initialize JNI, couldn't get the Unicode value" << std::endl; // Retrieve key data from the input event jlong downTime = AKeyEvent_getDownTime(event); jlong eventTime = AKeyEvent_getEventTime(event); jint action = AKeyEvent_getAction(event); jint code = AKeyEvent_getKeyCode(event); jint repeat = AKeyEvent_getRepeatCount(event); // not sure! jint metaState = AKeyEvent_getMetaState(event); jint deviceId = AInputEvent_getDeviceId(event); jint scancode = AKeyEvent_getScanCode(event); jint flags = AKeyEvent_getFlags(event); jint source = AInputEvent_getSource(event); // Construct a KeyEvent object from the event data jclass ClassKeyEvent = lJNIEnv->FindClass("android/view/KeyEvent"); jmethodID KeyEventConstructor = lJNIEnv->GetMethodID(ClassKeyEvent, "<init>", "(JJIIIIIIII)V"); jobject ObjectKeyEvent = lJNIEnv->NewObject(ClassKeyEvent, KeyEventConstructor, downTime, eventTime, action, code, repeat, metaState, deviceId, scancode, flags, source); // Call its getUnicodeChar() method to get the Unicode value jmethodID MethodGetUnicode = lJNIEnv->GetMethodID(ClassKeyEvent, "getUnicodeChar", "(I)I"); int unicode = lJNIEnv->CallIntMethod(ObjectKeyEvent, MethodGetUnicode, metaState); lJNIEnv->DeleteLocalRef(ClassKeyEvent); lJNIEnv->DeleteLocalRef(ObjectKeyEvent); // Detach this thread from the JVM lJavaVM->DetachCurrentThread(); return unicode; }
//Makes a layer such that the restricted space is the index, but with spinning order be [x, y, f] as opposed to [f, x, y] int InputLayer::updateState(double timef, double dt){ //Grab layer size const PVLayerLoc* loc = getLayerLoc(); int nx = loc->nx; int ny = loc->ny; int nf = loc->nf; int nxGlobal = loc->nxGlobal; int nyGlobal = loc->nyGlobal; int kx0 = loc->kx0; int ky0 = loc->ky0; for(int b = 0; b < parent->getNBatch(); b++){ pvdata_t * A = getActivity() + b * getNumExtended(); //looping over ext for(int iY = 0; iY < ny+loc->halo.up+loc->halo.dn; iY++){ for(int iX = 0; iX < nx+loc->halo.lt+loc->halo.rt; iX++){ //Calculate x and y global extended int xGlobalExt = iX + loc->kx0; int yGlobalExt = iY + loc->ky0; //Calculate x and y in restricted space int xGlobalRes = xGlobalExt - loc->halo.lt; int yGlobalRes = yGlobalExt - loc->halo.up; //Calculate base value //xGlobal and yGlobalRes can be negative int baseActivityVal = yGlobalRes * nxGlobal + xGlobalRes; for(int iFeature = 0; iFeature < nf; iFeature++){ int ext_idx = kIndex(iX, iY, iFeature, nx+loc->halo.lt+loc->halo.rt, ny+loc->halo.dn+loc->halo.up, nf); //Feature gives an offset, since it spins slowest int activityVal = baseActivityVal + iFeature * nxGlobal * nyGlobal; A[ext_idx] = activityVal; } } } } ////Printing for double checking //printf("\nOutMat\n"); ////looping over ext //for(int iFeature = 0; iFeature < nf; iFeature++){ // for(int iY = 0; iY < ny+loc->halo.up+loc->halo.dn; iY++){ // for(int iX = 0; iX < nx+loc->halo.lt+loc->halo.rt; iX++){ // int ext_idx = kIndex(iX, iY, iFeature, nx+loc->halo.lt+loc->halo.rt, ny+loc->halo.dn+loc->halo.up, nf); // printf("%03d ", (int)A[ext_idx]); // } // printf("\n"); // } // printf("\n\n"); //} return PV_SUCCESS; }
int GatePoolTestLayer::updateState(double timef, double dt) { //Do update state of ANN Layer first ANNLayer::updateState(timef, dt); //Grab layer size const PVLayerLoc* loc = getLayerLoc(); int nx = loc->nx; int ny = loc->ny; int nxGlobal = loc->nxGlobal; int nyGlobal = loc->nyGlobal; int nf = loc->nf; int kx0 = loc->kx0; int ky0 = loc->ky0; bool isCorrect = true; //Grab the activity layer of current layer for(int b = 0; b < loc->nbatch; b++) { const pvdata_t * A = getActivity() + b * getNumExtended(); //We only care about restricted space, but iY and iX are extended for(int iY = loc->halo.up; iY < ny + loc->halo.up; iY++) { for(int iX = loc->halo.lt; iX < nx + loc->halo.lt; iX++) { for(int iFeature = 0; iFeature < nf; iFeature++) { int ext_idx = kIndex(iX, iY, iFeature, nx+loc->halo.lt+loc->halo.rt, ny+loc->halo.dn+loc->halo.up, nf); float actualvalue = A[ext_idx]; int xval = (iX + kx0 - loc->halo.lt)/2; int yval = (iY + ky0 - loc->halo.up)/2; assert(xval >= 0 && xval < loc->nxGlobal); assert(yval >= 0 && yval < loc->nxGlobal); float expectedvalue; expectedvalue = iFeature * 64 + yval * 16 + xval * 2 + 4.5; expectedvalue*=4; if(fabs(actualvalue - expectedvalue) >= 1e-4) { pvErrorNoExit() << "Connection " << name << " Mismatch at (" << iX << "," << iY << ") : actual value: " << actualvalue << " Expected value: " << expectedvalue << ". Discrepancy is a whopping " << actualvalue - expectedvalue << "! Horrors!" << "\n"; isCorrect = false; } } } } } if(!isCorrect) { InterColComm * icComm = parent->icCommunicator(); MPI_Barrier(icComm->communicator()); // If there is an error, make sure that MPI doesn't kill the run before process 0 reports the error. exit(-1); } return PV_SUCCESS; }
void WindowImplAndroid::forwardEvent(const Event& event) { ActivityStates* states = getActivity(NULL); if (event.type == Event::GainedFocus) { WindowImplAndroid::singleInstance->m_size.x = ANativeWindow_getWidth(states->window); WindowImplAndroid::singleInstance->m_size.y = ANativeWindow_getHeight(states->window); WindowImplAndroid::singleInstance->m_windowBeingCreated = true; } else if (event.type == Event::LostFocus) { WindowImplAndroid::singleInstance->m_windowBeingDestroyed = true; } WindowImplAndroid::singleInstance->pushEvent(event); }
int MatchingPursuitResidual::updateState(double timed, double dt) { pvdata_t * V = getV(); if (inputInV) { for (int k=0; k<getNumNeuronsAllBatches(); k++) { V[k] -= GSyn[1][k]; } } else { for (int k=0; k<getNumNeuronsAllBatches(); k++) { V[k] = GSyn[0][k]; } inputInV = true; } PVLayerLoc const * loc = getLayerLoc(); setActivity_HyPerLayer(loc->nbatch, getNumNeurons(), getActivity(), V, loc->nx, loc->ny, loc->nf, loc->halo.lt, loc->halo.rt, loc->halo.dn, loc->halo.up); return PV_SUCCESS; }
int LeakyIntegrator::updateState(double timed, double dt) { pvdata_t * V = getV(); pvdata_t * gSyn = GSyn[0]; pvdata_t decayfactor = (pvdata_t) exp(-dt/integrationTime); for (int k=0; k<getNumNeuronsAllBatches(); k++) { V[k] *= decayfactor; V[k] += gSyn[k]; } int nx = getLayerLoc()->nx; int ny = getLayerLoc()->ny; int nf = getLayerLoc()->nf; int nbatch = getLayerLoc()->nbatch; PVHalo const * halo = &getLayerLoc()->halo; pvdata_t * A = getActivity(); int status = setActivity_PtwiseLinearTransferLayer(nbatch, getNumNeurons(), A, V, nx, ny, nf, halo->lt, halo->rt, halo->dn, halo->up, numVertices, verticesV, verticesA, slopes); return status; }
int InputLayer::updateState(double timef, double dt){ //Grab the activity layer of current layer pvdata_t * A = getActivity(); //Grab layer size const PVLayerLoc* loc = getLayerLoc(); int nx = loc->nx; int ny = loc->ny; int nf = loc->nf; int kx0 = loc->kx0; int ky0 = loc->ky0; assert(nf == 4); assert(loc->nxGlobal == 2 && loc->nyGlobal == 2); //We only care about restricted space for(int iY = loc->halo.up; iY < ny + loc->halo.up; iY++){ for(int iX = loc->halo.lt; iX < nx + loc->halo.lt; iX++){ for(int iF = 0; iF < loc->nf; iF++){ int idx = kIndex(iX, iY, iF, nx+loc->halo.lt+loc->halo.rt, ny+loc->halo.dn+loc->halo.up, nf); int xval = iX+kx0-loc->halo.lt; int yval = iY+ky0-loc->halo.up; if(timef == 10 && xval == 0 && yval == 0 && iF == 0){ A[idx] = 1; } else if(timef == 10 && xval == 1 && yval == 0 && iF == 1){ A[idx] = 1; } else if(timef == 10 && xval == 0 && yval == 1 && iF == 2){ A[idx] = 1; } else if(timef == 10 && xval == 1 && yval == 1 && iF == 3){ A[idx] = 1; } else{ A[idx] = 0; } } } } return PV_SUCCESS; }
int PursuitLayer::updateState(double time, double dt) { if (!updateReady) return PV_SUCCESS; int nx = getLayerLoc()->nx; int ny = getLayerLoc()->ny; int nf = getLayerLoc()->nf; PVHalo const * halo = &getLayerLoc()->halo; pvdata_t * activity = getActivity(); memset(activity, 0, getNumExtended()*sizeof(*activity)); int nxy = nx*ny; for (int kxy=0; kxy<nxy; kxy++) { int kf = foundFeatures[kxy]; if (kf>=0) { int kx = kxPos(kxy,nx,ny,1); int ky = kyPos(kxy,nx,ny,1); int kex = kIndex(kx+halo->lt, ky+halo->up, kf, nx+halo->lt+halo->rt, ny+halo->dn+halo->up, nf); /* Is this correct? Before splitting x- and y- margin widths, the ny argument was ny*nb, which seems weird. */ activity[kex] = gSynSparse[kxy]; } } //resetGSynBuffers_HyPerLayer(getNumNeurons(), getNumChannels(), GSyn[0]); updateReady = false; return PV_SUCCESS; }
void drawModifyTimeslot(uint8_t screenType){ //Copy the list of used elements from datahandler.cpp (from memory) //go through usedElements list to see which memory cells have valid data //make a note of the index values that contain valid data //now we know what indexes to look at when we want to print data to the screen. uint8_t iter_higher_than_end = 0; char tempString[3]; uint8_t menuPage = 0; uint8_t totalPages = 0; char timeBuf[18]; char buf[18]; memset(buf, 0, sizeof(buf)); memset(timeBuf, 0, sizeof(timeBuf)); printTime(); if(screenType == ADD){ printStringOnLine(1," Add Timeslot ", 1,NONE); printStringOnLine(6,"Choose nearby time", 1,NOBOXMENU); printStringOnLine(7,"to one being added", 1,NOBOXMENU); } else if(screenType == EDIT){ printStringOnLine(1," Edit Timeslot ", 1,NONE); printStringOnLine(6,"Choose a timeslot ", 1,NOBOXMENU); printStringOnLine(7,"to edit ", 1,NOBOXMENU); } else if(screenType == REMOVE){ printStringOnLine(1," Remove Timeslot ", 1,NONE); printStringOnLine(6,"Choose a timeslot ", 1,NOBOXMENU); printStringOnLine(7,"to remove ", 1,NOBOXMENU); } uint8_t index = 0; start = getMemMapStartIndex(); end = getMemMapEndIndex(); iter = start; if(iter > end) iter_higher_than_end = 1; uint8_t currentMenuLength = getUnencrpytedRecordCount(); for (uint8_t i = 0; i < cellsPerFrame; i++){ char hourString[3] = {"0"}; char minuteString[3] = {"0"}; if (currentMenuLength == 0){ printTimeLineIsEmpty(); break; } totalPages = ((currentMenuLength-1)/cellsPerFrame); menuPage = (selectionInMenu/cellsPerFrame); index = ((menuPage)*cellsPerFrame)+i; iter = (index + start) % maxRecNum; selectedHour = getHour(getMemMapElement(iter)); itoa(selectedHour, tempString, 10); if (selectedHour < 10) strcat(hourString, tempString); else{ strcpy(hourString, tempString); } selectedMinute = getMinute(getMemMapElement(iter)); itoa(selectedMinute, tempString, 10); if (selectedMinute < 10) strcat(minuteString, tempString); else{ strcpy(minuteString, tempString); } if(iter <= end || (i == 0 && currentMenuLength >= maxRecNum) || (iter_higher_than_end == 1)){ if (iter <= end) iter_higher_than_end = 0; snprintf(buf, sizeof(buf), "%s%s%s%s", hourString, ":", minuteString, "|"); snprintf(buf, sizeof(buf), "%s%s%s%s%s", buf, activityArray[getActivity(getMemMapElement(iter))], "-", moodArray[getMood(getMemMapElement(iter))], " "); timeBuf[17] = ' '; buf[17] = ' '; drawMenuBands(menuPage,totalPages,TOPBAND); //Draw Menu Contents if (i == selectionInFrame){ printStringOnLine(i+yOffset,buf, 1,NOBOXMENU); } else if (index < currentMenuLength){ printStringOnLine(i+yOffset,buf, 0,NOBOXMENU); } } else printStringOnLine(i+yOffset," ", 0,NOBOXMENU); drawMenuBands(menuPage,totalPages,BOTTOMBANDMODIFY); } }
int BinningLayer::updateState(double timef, double dt) { int status; assert(GSyn==NULL); pvdata_t * gSynHead = NULL; status = doUpdateState(timef, dt, originalLayer->getLayerLoc(), getLayerLoc(), originalLayer->getLayerData(delay), getActivity(), binMax, binMin); return status; }
bool cvzMmcm_IDL::read(yarp::os::ConnectionReader& connection) { yarp::os::idl::WireReader reader(connection); reader.expectAccept(); if (!reader.readListHeader()) { reader.fail(); return false; } yarp::os::ConstString tag = reader.readTag(); bool direct = (tag=="__direct__"); if (direct) tag = reader.readTag(); while (!reader.isError()) { // TODO: use quick lookup, this is just a test if (tag == "start") { start(); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(0)) return false; } reader.accept(); return true; } if (tag == "pause") { pause(); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(0)) return false; } reader.accept(); return true; } if (tag == "quit") { bool _return; _return = quit(); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "setLearningRate") { double l; if (!reader.readDouble(l)) { reader.fail(); return false; } setLearningRate(l); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(0)) return false; } reader.accept(); return true; } if (tag == "getLearningRate") { double _return; _return = getLearningRate(); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeDouble(_return)) return false; } reader.accept(); return true; } if (tag == "setSigma") { double s; if (!reader.readDouble(s)) { reader.fail(); return false; } setSigma(s); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(0)) return false; } reader.accept(); return true; } if (tag == "getSigma") { double _return; _return = getSigma(); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeDouble(_return)) return false; } reader.accept(); return true; } if (tag == "getActivity") { int32_t x; int32_t y; int32_t z; if (!reader.readI32(x)) { reader.fail(); return false; } if (!reader.readI32(y)) { reader.fail(); return false; } if (!reader.readI32(z)) { reader.fail(); return false; } double _return; _return = getActivity(x,y,z); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeDouble(_return)) return false; } reader.accept(); return true; } if (tag == "saveWeightsToFile") { std::string path; if (!reader.readString(path)) { reader.fail(); return false; } bool _return; _return = saveWeightsToFile(path); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "loadWeightsFromFile") { std::string path; if (!reader.readString(path)) { reader.fail(); return false; } bool _return; _return = loadWeightsFromFile(path); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "saveRF") { std::string path; if (!reader.readString(path)) { reader.fail(); return false; } bool _return; _return = saveRF(path); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(1)) return false; if (!writer.writeBool(_return)) return false; } reader.accept(); return true; } if (tag == "help") { std::string functionName; if (!reader.readString(functionName)) { functionName = "--all"; } std::vector<std::string> _return=help(functionName); yarp::os::idl::WireWriter writer(reader); if (!writer.isNull()) { if (!writer.writeListHeader(2)) return false; if (!writer.writeTag("many",1, 0)) return false; if (!writer.writeListBegin(BOTTLE_TAG_INT, static_cast<uint32_t>(_return.size()))) return false; std::vector<std::string> ::iterator _iterHelp; for (_iterHelp = _return.begin(); _iterHelp != _return.end(); ++_iterHelp) { if (!writer.writeString(*_iterHelp)) return false; } if (!writer.writeListEnd()) return false; } reader.accept(); return true; } if (reader.noMore()) { reader.fail(); return false; } yarp::os::ConstString next_tag = reader.readTag(); if (next_tag=="") break; tag = tag + "_" + next_tag; } return false; }
void CMuscle::draw() { double pi = 3.14159; // double colorCoef; GLUquadricObj *quadObj; quadObj = gluNewQuadric(); /* if(strength >= income - threshold) { colorCoef = (income > threshold) * (income - threshold) / strength; } else { colorCoef = 1; } */ //if(activity == 1) //{ //glColor3ub(250 / MStrength * (income - threshold) , 0, 0); //} //else //{ // glColor3ub(50 + (int)(150 *colorCoef), 70, 70); //} float act; int r,g,b; r = 80; g = 80; b = 80; /* double dl = (getP1Pos()-getP2Pos()).length() - getLength0(); if( (act = getActivity())<=1 || dl < 0.0) { r += (int)((float)r*2.f*act); } */ r += (255-80)*min(getActivity(),1.f); /**/ //double dl = (getP1Pos()-getP2Pos()).length() - getLength0(); //if( dl < 0.0) g+= -dl*300; /*if( dl < 0.0) { r+= -(int)(dl*500); g+= (int)dl*200; b += (int)dl*200; } if(r>255) r = 255; if(g<0) g = 0; if(b<0) b = 0;*/ /**/ //(i_p1->getPos() - i_p2->getPos()).length() glColor3ub(r,g,b); //Vector3D rp1 = (ort1*p1->getX() + ort2*p1->getY() + ort3*p1->getZ())*scale + vcenter; Vector3D rp1 = (ort1*(p1->getX()-pos_rc.x) + ort2*(p1->getY()-pos_rc.y) + ort3*(p1->getZ()-pos_rc.z))*scale + vcenter; //Vector3D rp2 = (ort1*p2->getX() + ort2*p2->getY() + ort3*p2->getZ())*scale + vcenter; Vector3D rp2 = (ort1*(p2->getX()-pos_rc.x) + ort2*(p2->getY()-pos_rc.y) + ort3*(p2->getZ()-pos_rc.z))*scale + vcenter; Vector3D p = rp2 - rp1; double h = p.length();// /2; glPushMatrix(); glTranslated(rp1.x, rp1.y, rp1.z); glRotated(180.0f*(double)atan2(p.x,p.z)/pi,0,1,0); glRotated(-180.0f*(double)atan2(p.y,sqrt(p.x*p.x+p.z*p.z))/pi,1,0,0); if(mode==0) gluCylinder(quadObj, 0, 0.02*scale, h, 16, 16); else gluCylinder(quadObj, 0, 0.05*scale, h, 16, 16); glPopMatrix(); //p = p1->getPos() - p2->getPos(); /* p = rp1 - rp2; glPushMatrix(); glTranslated(rp2.x, rp2.y, rp2.z); glRotated(180.0f*(double)atan2(p.x,p.z)/pi,0,1,0); glRotated(-180.0f*(double)atan2(p.y,sqrt(p.x*p.x+p.z*p.z))/pi,1,0,0); gluCylinder(quadObj, 0, 0.05*scale, h, 16, 16); glPopMatrix(); */ gluDeleteQuadric(quadObj); }
void PCPG::updateOutputs(){ //***CPG post processing***** pcpg_step.at(0) = getActivity(0); pcpg_step.at(1) = getActivity(1); setold.at(0) = set.at(0); setold.at(1) = set.at(1); countupold.at(0) = countup.at(0); countupold.at(1) = countup.at(1); countdownold.at(0) = countdown.at(0); countdownold.at(1) = countdown.at(1); //1) Linear threshold transfer function neuron 1 , or called step function neuron// /********************************************************/ if (pcpg_step.at(0)>=0.85) ////////////////////Intuitively select { set.at(0) = 1.0; } if (pcpg_step.at(0)<0.85) ////////////////////Intuitively select { set.at(0) = -1.0; } if (pcpg_step.at(1)>=0.85) ////////////////////Intuitively select { set.at(1) = 1.0; } if (pcpg_step.at(1)<0.85) ////////////////////Intuitively select { set.at(1) = -1.0; } diffset.at(0) = set.at(0)-setold.at(0); // double diffset.at(1) = set.at(1)-setold.at(1); // double //2) Count how many step of Swing /********************************************************/ if (set.at(0) == 1.0) { countup.at(0) = countup.at(0)+1.0; //Delta x0 up countdown.at(0) = 0.0; } // Count how many step of Stance else if (set.at(0) == -1.0) { countdown.at(0) = countdown.at(0)+1.0; //Delta x0 down countup.at(0) = 0.0; } if (set.at(1) == 1.0) { countup.at(1) = countup.at(1)+1.0; //Delta x0 up countdown.at(1) = 0.0; } // Count how many step of Stance else if (set.at(1) == -1.0) { countdown.at(1) = countdown.at(1)+1.0; //Delta x0 down countup.at(1) = 0.0; } //3) Memorized the total steps of swing and stance /********************************************************/ if (countup.at(0) == 0.0 && diffset.at(0) == -2.0 && set.at(0) == -1.0) deltaxup.at(0) = countupold.at(0); // if (countdown.at(0) == 0.0 && diffset.at(0) == 2.0 && set.at(0) == 1.0) deltaxdown.at(0) = countdownold.at(0); // // if (countup.at(1) == 0.0 && diffset.at(1) == -2.0 && set.at(1) == -1.0) deltaxup.at(1) = countupold.at(1); // if (countdown.at(1) == 0.0 && diffset.at(1) == 2.0 && set.at(1) == 1.0) deltaxdown.at(1) = countdownold.at(1); //4) Comput y up and down !!!! /********************************************************/ xup.at(0) = countup.at(0); xdown.at(0) = countdown.at(0); xup.at(1) = countup.at(1); xdown.at(1) = countdown.at(1); ////////////Scaling Slope Up calculation//////// yup.at(0) = ((2./deltaxup.at(0))*xup.at(0))-1; ////////////Scaling Slope Down calculation////// ydown.at(0) = ((-2./deltaxdown.at(0))*xdown.at(0))+1; ////////////Scaling Slope Up calculation//////// yup.at(1) = ((2./deltaxup.at(1))*xup.at(1))-1; ////////////Scaling Slope Down calculation////// ydown.at(1) = ((-2./deltaxdown.at(1))*xdown.at(1))+1; //5) Combine y up and down !!!! /********************************************************/ if (set.at(0) >= 0.0) pcpg_output.at(0) = yup.at(0); if (set.at(0) < 0.0) pcpg_output.at(0) = ydown.at(0); if (set.at(1) >= 0.0) pcpg_output.at(1) = yup.at(1); if (set.at(1) < 0.0) pcpg_output.at(1) = ydown.at(1); //********Limit upper and lower boundary if(pcpg_output.at(0)>1.0) pcpg_output.at(0) = 1.0; else if(pcpg_output.at(0)<-1.0) pcpg_output.at(0) = -1.0; if(pcpg_output.at(1)>1.0) pcpg_output.at(1) = 1.0; else if(pcpg_output.at(1)<-1.0) pcpg_output.at(1) = -1.0; //***CPG post processing*end* setOutput(0,pcpg_output.at(0)); setOutput(1,pcpg_output.at(1)); }
void InputImpl::setVirtualKeyboardVisible(bool visible) { // todo: Check if the window is active ActivityStates* states = getActivity(NULL); Lock lock(states->mutex); // Initializes JNI jint lResult; jint lFlags = 0; JavaVM* lJavaVM = states->activity->vm; JNIEnv* lJNIEnv = states->activity->env; JavaVMAttachArgs lJavaVMAttachArgs; lJavaVMAttachArgs.version = JNI_VERSION_1_6; lJavaVMAttachArgs.name = "NativeThread"; lJavaVMAttachArgs.group = NULL; lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs); if (lResult == JNI_ERR) err() << "Failed to initialize JNI, couldn't switch the keyboard visibility" << std::endl; // Retrieves NativeActivity jobject lNativeActivity = states->activity->clazz; jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity); // Retrieves Context.INPUT_METHOD_SERVICE jclass ClassContext = lJNIEnv->FindClass("android/content/Context"); jfieldID FieldINPUT_METHOD_SERVICE = lJNIEnv->GetStaticFieldID(ClassContext, "INPUT_METHOD_SERVICE", "Ljava/lang/String;"); jobject INPUT_METHOD_SERVICE = lJNIEnv->GetStaticObjectField(ClassContext, FieldINPUT_METHOD_SERVICE); lJNIEnv->DeleteLocalRef(ClassContext); // Runs getSystemService(Context.INPUT_METHOD_SERVICE) jclass ClassInputMethodManager = lJNIEnv->FindClass("android/view/inputmethod/InputMethodManager"); jmethodID MethodGetSystemService = lJNIEnv->GetMethodID(ClassNativeActivity, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;"); jobject lInputMethodManager = lJNIEnv->CallObjectMethod(lNativeActivity, MethodGetSystemService, INPUT_METHOD_SERVICE); lJNIEnv->DeleteLocalRef(INPUT_METHOD_SERVICE); // Runs getWindow().getDecorView() jmethodID MethodGetWindow = lJNIEnv->GetMethodID(ClassNativeActivity, "getWindow", "()Landroid/view/Window;"); jobject lWindow = lJNIEnv->CallObjectMethod(lNativeActivity, MethodGetWindow); jclass ClassWindow = lJNIEnv->FindClass("android/view/Window"); jmethodID MethodGetDecorView = lJNIEnv->GetMethodID(ClassWindow, "getDecorView", "()Landroid/view/View;"); jobject lDecorView = lJNIEnv->CallObjectMethod(lWindow, MethodGetDecorView); lJNIEnv->DeleteLocalRef(lWindow); lJNIEnv->DeleteLocalRef(ClassWindow); if (visible) { // Runs lInputMethodManager.showSoftInput(...) jmethodID MethodShowSoftInput = lJNIEnv->GetMethodID(ClassInputMethodManager, "showSoftInput", "(Landroid/view/View;I)Z"); jboolean lResult = lJNIEnv->CallBooleanMethod(lInputMethodManager, MethodShowSoftInput, lDecorView, lFlags); } else { // Runs lWindow.getViewToken() jclass ClassView = lJNIEnv->FindClass("android/view/View"); jmethodID MethodGetWindowToken = lJNIEnv->GetMethodID(ClassView, "getWindowToken", "()Landroid/os/IBinder;"); jobject lBinder = lJNIEnv->CallObjectMethod(lDecorView, MethodGetWindowToken); lJNIEnv->DeleteLocalRef(ClassView); // lInputMethodManager.hideSoftInput(...) jmethodID MethodHideSoftInput = lJNIEnv->GetMethodID(ClassInputMethodManager, "hideSoftInputFromWindow", "(Landroid/os/IBinder;I)Z"); jboolean lRes = lJNIEnv->CallBooleanMethod(lInputMethodManager, MethodHideSoftInput, lBinder, lFlags); lJNIEnv->DeleteLocalRef(lBinder); } lJNIEnv->DeleteLocalRef(ClassNativeActivity); lJNIEnv->DeleteLocalRef(ClassInputMethodManager); lJNIEnv->DeleteLocalRef(lDecorView); // Finished with the JVM lJavaVM->DetachCurrentThread(); }
int WindowImplAndroid::processEvent(int fd, int events, void* data) { ActivityStates* states = getActivity(NULL); Lock lock(states->mutex); AInputEvent* _event = NULL; if (AInputQueue_getEvent(states->inputQueue, &_event) >= 0) { if (AInputQueue_preDispatchEvent(states->inputQueue, _event)) return 1; int handled = 0; int32_t type = AInputEvent_getType(_event); if (type == AINPUT_EVENT_TYPE_KEY) { int32_t action = AKeyEvent_getAction(_event); int32_t key = AKeyEvent_getKeyCode(_event); if ((action == AKEY_EVENT_ACTION_DOWN || action == AKEY_EVENT_ACTION_UP || action == AKEY_EVENT_ACTION_MULTIPLE) && key != AKEYCODE_VOLUME_UP && key != AKEYCODE_VOLUME_DOWN) { handled = processKeyEvent(_event, states); } } else if (type == AINPUT_EVENT_TYPE_MOTION) { int32_t action = AMotionEvent_getAction(_event); switch (action & AMOTION_EVENT_ACTION_MASK) { case AMOTION_EVENT_ACTION_SCROLL: { handled = processScrollEvent(_event, states); break; } // todo: should hover_move indeed trigger the event? // case AMOTION_EVENT_ACTION_HOVER_MOVE: case AMOTION_EVENT_ACTION_MOVE: { handled = processMotionEvent(_event, states); break; } // todo: investigate AMOTION_EVENT_OUTSIDE case AMOTION_EVENT_ACTION_POINTER_DOWN: case AMOTION_EVENT_ACTION_DOWN: { handled = processPointerEvent(true, _event, states); break; } case AMOTION_EVENT_ACTION_POINTER_UP: case AMOTION_EVENT_ACTION_UP: case AMOTION_EVENT_ACTION_CANCEL: { handled = processPointerEvent(false, _event, states); break; } } } AInputQueue_finishEvent(states->inputQueue, _event, handled); } return 1; }
int SegmentLayer::updateState(double timef, double dt) { pvdata_t* srcA = originalLayer->getActivity(); pvdata_t* thisA = getActivity(); assert(srcA); assert(thisA); const PVLayerLoc* loc = getLayerLoc(); //Segment input layer based on segmentMethod if(strcmp(segmentMethod, "none") == 0){ int numBatchExtended = getNumExtendedAllBatches(); //Copy activity over //Since both buffers should be identical size, we can do a memcpy here memcpy(thisA, srcA, numBatchExtended * sizeof(pvdata_t)); } else{ //This case should never happen assert(0); } assert(loc->nf == 1); //Clear centerIdxs for(int bi = 0; bi < loc->nbatch; bi++){ centerIdx[bi].clear(); } for(int bi = 0; bi < loc->nbatch; bi++){ pvdata_t* batchA = thisA + bi * getNumExtended(); //Reset max/min buffers maxX.clear(); maxY.clear(); minX.clear(); minY.clear(); //Loop through this buffer to fill labelVec and idxVec //Looping through restricted, but indices are extended for(int yi = loc->halo.up; yi < loc->ny+loc->halo.up; yi++){ for(int xi = loc->halo.lt; xi < loc->nx+loc->halo.lt; xi++){ //Convert to local extended linear index int niLocalExt = yi * (loc->nx+loc->halo.lt+loc->halo.rt) + xi; //Convert yi and xi to global res index int globalResYi = yi - loc->halo.up + loc->ky0; int globalResXi = xi - loc->halo.lt + loc->kx0; //Get label value //Note that we're assuming that the activity here are integers, //even though the buffer is floats int labelVal = round(batchA[niLocalExt]); //Calculate max/min x and y for a single batch //If labelVal exists in map if(maxX.count(labelVal)){ //Here, we're assuming the 4 maps are in sync, so we use the //.at method, as it will throw an exception as opposed to the //[] operator, which will simply add the key into the map if(globalResXi > maxX.at(labelVal)){ maxX[labelVal] = globalResXi; } if(globalResXi < minX.at(labelVal)){ minX[labelVal] = globalResXi; } if(globalResYi > maxY.at(labelVal)){ maxY[labelVal] = globalResYi; } if(globalResYi < minY.at(labelVal)){ minY[labelVal] = globalResYi; } } //If doesn't exist, add into map with current vals else{ maxX[labelVal] = globalResXi; minX[labelVal] = globalResXi; maxY[labelVal] = globalResYi; minY[labelVal] = globalResYi; } } } //We need to mpi across processors in case a segment crosses an mpi boundary InterColComm * icComm = parent->icCommunicator(); int numMpi = icComm->commSize(); int rank = icComm->commRank(); //Local comm rank //Non root processes simply send buffer size and then buffers int numLabels = maxX.size(); if(rank != 0){ //Load buffers loadLabelBuf(); //Send number of labels first MPI_Send(&numLabels, 1, MPI_INT, 0, rank, icComm->communicator()); //Send labels, then max/min buffers MPI_Send(labelBuf, numLabels, MPI_INT, 0, rank, icComm->communicator()); MPI_Send(maxXBuf, numLabels, MPI_INT, 0, rank, icComm->communicator()); MPI_Send(maxYBuf, numLabels, MPI_INT, 0, rank, icComm->communicator()); MPI_Send(minXBuf, numLabels, MPI_INT, 0, rank, icComm->communicator()); MPI_Send(minYBuf, numLabels, MPI_INT, 0, rank, icComm->communicator()); //Receive the full centerIdxBuf from root process int numCenterIdx = 0; MPI_Bcast(&numCenterIdx, 1, MPI_INT, 0, icComm->communicator()); checkIdxBufSize(numCenterIdx); MPI_Bcast(allLabelsBuf, numCenterIdx, MPI_INT, 0, icComm->communicator()); MPI_Bcast(centerIdxBuf, numCenterIdx, MPI_INT, 0, icComm->communicator()); //Load buffer into centerIdx map loadCenterIdxMap(bi, numCenterIdx); } //Root process stores everything else{ //One recv per buffer for(int recvRank = 1; recvRank < numMpi; recvRank++){ int numRecvLabels = 0; MPI_Recv(&numRecvLabels, 1, MPI_INT, recvRank, recvRank, icComm->communicator(), NULL); checkLabelBufSize(numRecvLabels); MPI_Recv(labelBuf, numRecvLabels, MPI_INT, recvRank, recvRank, icComm->communicator(), NULL); MPI_Recv(maxXBuf, numRecvLabels, MPI_INT, recvRank, recvRank, icComm->communicator(), NULL); MPI_Recv(maxYBuf, numRecvLabels, MPI_INT, recvRank, recvRank, icComm->communicator(), NULL); MPI_Recv(minXBuf, numRecvLabels, MPI_INT, recvRank, recvRank, icComm->communicator(), NULL); MPI_Recv(minYBuf, numRecvLabels, MPI_INT, recvRank, recvRank, icComm->communicator(), NULL); for(int i = 0; i < numRecvLabels; i++){ int label = labelBuf[i]; //Add on to maps //If the label already exists, fill with proper max/min if(maxX.count(label)){ if(maxXBuf[i] > maxX.at(label)){ maxX[label] = maxXBuf[i]; } if(maxYBuf[i] > maxY.at(label)){ maxY[label] = maxYBuf[i]; } if(minXBuf[i] < minX.at(label)){ minX[label] = minXBuf[i]; } if(minYBuf[i] < minY.at(label)){ minY[label] = minYBuf[i]; } } else{ maxX[label] = maxXBuf[i]; maxY[label] = maxYBuf[i]; minX[label] = minXBuf[i]; minY[label] = minYBuf[i]; } } } //Maps are now filled with all segments from the image //Fill centerIdx based on max/min for(std::map<int, int>::iterator it = maxX.begin(); it != maxX.end(); ++it){ int label = it->first; int centerX = minX.at(label) + (maxX.at(label) - minX.at(label))/2; int centerY = minY.at(label) + (maxY.at(label) - minY.at(label))/2; //Convert centerpoints (in global res idx) to linear idx (in global res space) int centerIdxVal = centerY * (loc->nxGlobal) + centerX; //Add to centerIdxMap centerIdx[bi][label] = centerIdxVal; } //Fill centerpoint buffer int numCenterIdx = centerIdx[bi].size(); checkIdxBufSize(numCenterIdx); int idx = 0; for(std::map<int, int>::iterator it = centerIdx[bi].begin(); it != centerIdx[bi].end(); ++it){ allLabelsBuf[idx] = it->first; centerIdxBuf[idx] = it->second; idx++; } //Broadcast buffers MPI_Bcast(&numCenterIdx, 1, MPI_INT, 0, icComm->communicator()); MPI_Bcast(allLabelsBuf, numCenterIdx, MPI_INT, 0, icComm->communicator()); MPI_Bcast(centerIdxBuf, numCenterIdx, MPI_INT, 0, icComm->communicator()); } } //End batch loop //centerIdx now stores each center coordinate of each segment return PV_SUCCESS; }
void drawTimeline(void){ uint8_t iter_higher_than_end = 0; uint8_t menuPage = 0; uint8_t totalPages = 0; char tempString[3]; char timeBuf[18]; char buf[18]; printTime(); printStringOnLine(1," Timeline ", 1,NONE); uint8_t index = 0; start = getMemMapStartIndex(); end = getMemMapEndIndex(); iter = start; if(iter > end) iter_higher_than_end = 1; uint8_t currentMenuLength = getUnencrpytedRecordCount(); for (uint8_t i = 0; i < cellsPerFrame; i++){ char hourString[3] = {"0"}; char minuteString[3] = {"0"}; char yearString[3] = {"0"}; char monthString[3] = {"0"}; char dateString[3] = {"0"}; if (currentMenuLength == 0){ printTimeLineIsEmpty(); break; } totalPages = ((currentMenuLength-1)/cellsPerFrame); menuPage = (selectionInMenu/cellsPerFrame); index = ((menuPage)*cellsPerFrame)+i; iter = (index + start) % maxRecNum; selectedDate = getDate(getMemMapElement(iter)); itoa(selectedDate, tempString, 10); if (selectedDate < 10) strcat(dateString, tempString); else{ strcpy(dateString, tempString); } selectedMonth = getMonth(getMemMapElement(iter)); itoa(selectedMonth, tempString, 10); if (selectedMonth < 10) strcat(monthString, tempString); else{ strcpy(monthString, tempString); } selectedYear = getYear(getMemMapElement(iter)); itoa(selectedYear, tempString, 10); if (selectedYear < 10) strcat(yearString, tempString); else{ strcpy(yearString, tempString); } selectedHour = getHour(getMemMapElement(iter)); itoa(selectedHour, tempString, 10); if (selectedHour < 10) strcat(hourString, tempString); else{ strcpy(hourString, tempString); } selectedMinute = getMinute(getMemMapElement(iter)); itoa(selectedMinute, tempString, 10); if (selectedMinute < 10) strcat(minuteString, tempString); else{ strcpy(minuteString, tempString); } //USART_Sendbyte(totalPages); //USART_Sendbyte(menuPage); //USART_Sendbyte(index); //USART_Sendbyte(iter); //USART_Sendbyte(start); //USART_Sendbyte(end); //USART_Sendbyte(iter_higher_than_end); if(iter <= end || (i == 0 && currentMenuLength >= maxRecNum) || (iter_higher_than_end == 1)){ if (iter <= end) iter_higher_than_end = 0; snprintf(timeBuf, sizeof(timeBuf), "%s%s%s%s%s%s%s%s%s%s", dateString, "/", monthString, "/", yearString, " - ", hourString, ":", minuteString, " "); snprintf(buf, sizeof(buf), "%s%s%s%s", activityArray[getActivity(getMemMapElement(iter))], "-", moodArray[getMood(getMemMapElement(iter))], " "); timeBuf[17] = ' '; buf[17] = ' '; drawMenuBands(menuPage,totalPages,TOPBAND); //Draw Menu Contents if (i == selectionInFrame){ printStringOnLine(i*2+yOffset,timeBuf, 1,NOBOXMENU); printTimelineStringOnLine(i*2+yOffset+1,buf, 1,faceArray[getMood(getMemMapElement(iter))]); } else if (index < currentMenuLength){ printStringOnLine(i*2+yOffset,timeBuf, 0,NOBOXMENU); printTimelineStringOnLine(i*2+yOffset+1,buf, 0,faceArray[getMood(getMemMapElement(iter))]); } } else{ printStringOnLine(i*2+yOffset," ", 0,NOBOXMENU); printStringOnLine(i*2+yOffset+1," ", 0,NOBOXMENU); } drawMenuBands(menuPage,totalPages,BOTTOMBAND); } }
//advance to next menu screen with current selection void incrementMenuID(){ clearLCD(); previousMenuID = currentMenuID; //Coming From... //[Sleep] if (currentMenuID == 0 || currentMenuID == 1) currentMenuID = 10; //[Main Menu] else if (currentMenuID == 10){ if(researchPeriod == 0){ if (selectionInMenu == 0) currentMenuID = 20; else if (selectionInMenu == 1) currentMenuID = 30; else if (selectionInMenu == 2){ currentMenuID = 40; } else if (selectionInMenu == 3) currentMenuID = 70; else if (selectionInMenu == 4) currentMenuID = 0; else if (selectionInMenu == 5) currentMenuID = 80; } else{ if(selectionInMenu == 3 || selectionInMenu == 4 || selectionInMenu == 5){ if (selectionInMenu == 3) currentMenuID = 70; else if(selectionInMenu == 4) currentMenuID = 0; else if(selectionInMenu == 5) currentMenuID = 80; } else currentMenuID = 11; } } //[Log - Choose Activity] else if (currentMenuID == 20){ selectedActivity = selectionInMenu; selectedYear = getTimeYear(); selectedMonth = getTimeMonth(); selectedDate = getTimeDate(); selectedDay = getTimeDay(); selectedHour = getTimeHour(); selectedMinute = getTimeMinute(); selectedSecond = getTimeSecond(); currentMenuID++; } //[Log - Choose Mood] else if (currentMenuID == 21){ selectedMood = selectionInMenu; currentMenuID++; } //[Log - Confirm] else if (currentMenuID == 22){ insertRecord(selectedYear,selectedMonth,selectedDate, selectedDay, selectedHour,selectedMinute,selectedSecond,selectedActivity,selectedMood); currentMenuID = 10; } //[View Timeline] else if (currentMenuID == 30){ currentMenuID = 10; } //[Edit,Add,Remove] else if (currentMenuID == 40){ uint8_t numberOfRecords = getUnencrpytedRecordCount(); if (selectionInMenu == 0){ if(numberOfRecords == 0){ selectedYear = getTimeYear(); selectedMonth = getTimeMonth(); selectedDate = getTimeDate(); selectedDay = getTimeDay(); currentMenuID = 42; } else{ currentMenuID = 41; } } else{ if(numberOfRecords == 0) currentMenuID = 43; else{ if (selectionInMenu == 1) currentMenuID = 50; else if (selectionInMenu == 2) currentMenuID = 60; } } } //[Add] else if (currentMenuID == 41){ uint8_t numberOfRecords = getUnencrpytedRecordCount(); if(numberOfRecords != 0){ iter = getMemMapStartIndex(); selectedRecord = (selectionInMenu + iter) % maxRecNum; address = getMemMapElement(selectedRecord); } else{ selectedMinute = getTimeMinute(); selectedSecond = getTimeSecond(); } selectedYear = getTimeYear(); selectedMonth = getTimeMonth(); selectedDate = getTimeDate(); selectedDay = getTimeDay(); selectedHour = getTimeHour(); firstPass = 0; currentMenuID = 42; } //[Add - choose time] else if (currentMenuID == 42){ if(timeSelection == HOUR) timeSelection = MINUTE; else currentMenuID = 44; } //[Edit - NO RECORDS] else if (currentMenuID == 43){ currentMenuID = 10; } //[Add - choose Activity] else if (currentMenuID == 44){ selectedActivity = selectionInMenu; currentMenuID = 45; } //[Add - choose Mood] else if (currentMenuID == 45){ selectedMood = selectionInMenu; currentMenuID = 46; } //[Add - Confirm] else if (currentMenuID == 46){ insertRecord(selectedYear,selectedMonth,selectedDate, selectedDay, selectedHour,selectedMinute,0,selectedActivity,selectedMood); currentMenuID = 10; } //[Edit - choose time] else if (currentMenuID == 50){ start = getMemMapStartIndex(); selectedIndex = (selectionInMenu + start) % maxRecNum; address = getMemMapElement(selectedIndex); activityInRecord = getActivity(address); moodInRecord = getMood(address); selectedHour = getHour(address); selectedMinute = getMinute(address); currentMenuID = 51; } //[Edit - Mood or Act] else if (currentMenuID == 51){ if (selectionInMenu == 0){ firstPass = 0; currentMenuID = 52; } else if (selectionInMenu == 1) currentMenuID = 56; } //[Edit - Act - Choose Time] else if (currentMenuID == 52){ if(timeSelection == HOUR) timeSelection = MINUTE; else currentMenuID = 54; } //[Edit - Act - Choose Act] else if (currentMenuID == 54){ selectedActivity = selectionInMenu; selectedMood = moodInRecord; currentMenuID = 55; } //[Edit - Act - Confirm] else if (currentMenuID == 55){ setHourByAddress(address,selectedHour); setMinuteByAddress(address,selectedMinute); setActivityByAddress(address,selectedActivity); currentMenuID = 10; } //[Edit - Mood - Choose Mood] else if (currentMenuID == 56){ selectedMood = selectionInMenu; selectedActivity = activityInRecord; currentMenuID = 57; } //[Edit - Mood - Confirm] else if (currentMenuID == 57){ setMoodByAddress(address,selectedMood); currentMenuID = 10; } //[Remove - choose record] else if (currentMenuID == 60){ iter = getMemMapStartIndex(); selectedRecord = (selectionInMenu + iter) % maxRecNum; address = getMemMapElement(selectedRecord); selectedActivity = getActivity(address); selectedMood = getMood(address); selectedHour = getHour(address); selectedMinute = getMinute(address); currentMenuID = 61; } //[Remove - confirm] else if (currentMenuID == 61){ deleteRecord(selectedRecord); currentMenuID = 10; } //[Settings] else if (currentMenuID == 70){ if(selectionInMenu == 0){ firstPass = 0; currentMenuID = 71; } else if(selectionInMenu == 1) currentMenuID = 72; else if(selectionInMenu == 2) currentMenuID = 73; } //[Settings - modify Time] else if (currentMenuID == 71){ if(timeSelection == HOUR) timeSelection = MINUTE; else if (timeSelection == MINUTE) timeSelection = DAY; else if (timeSelection == DAY) timeSelection = MONTH; else if (timeSelection == MONTH) timeSelection = YEAR; else{ currentMenuID = 70; modifiedTimeFlag = 1; } } //[Settings - Invert Screen] else if (currentMenuID == 72){ invertColours = getInvertColourSetting(); setInvertColourSetting(!invertColours); invertColours = !invertColours; } //[Settings - Reset] else if (currentMenuID == 73){ currentMenuID = 74; } //[Settings - Reset] else if (currentMenuID == 74){ resetRecords(); currentMenuID = 70; } //[Upload] else if (currentMenuID == 80){ //currentMenuID = 10; } selectionInFrame = 0; selectionInMenu = 0; }