//Step 6 //To be written by the developer void scoresControllerCallback(void* userData, SC_Error_t completionStatus) { switch(completionStatus){ case SC_OK: FREDispatchStatusEventAsync(context, (const uint8_t *)"scorescontroller", (const uint8_t *)"SC_OK"); break; case SC_HTTP_SERVER_ERROR: FREDispatchStatusEventAsync(context, (const uint8_t *)"scorescontroller", (const uint8_t *)"SC_HTTP_SERVER_ERROR"); break; case SC_INVALID_RANGE: FREDispatchStatusEventAsync(context, (const uint8_t *)"scorescontroller", (const uint8_t *)"SC_INVALID_RANGE"); break; case SC_INVALID_SERVER_RESPONSE: FREDispatchStatusEventAsync(context, (const uint8_t *)"scorescontroller", (const uint8_t *)"SC_INVALID_SERVER_RESPONSE"); break; case SC_HANDSHAKE_FAILED: FREDispatchStatusEventAsync(context, (const uint8_t *)"scorescontroller", (const uint8_t *)"SC_HANDSHAKE_FAILED"); break; case SC_REQUEST_FAILED: FREDispatchStatusEventAsync(context, (const uint8_t *)"scorescontroller", (const uint8_t *)"SC_REQUEST_FAILED"); break; case SC_REQUEST_CANCELLED: FREDispatchStatusEventAsync(context, (const uint8_t *)"scorescontroller", (const uint8_t *)"SC_REQUEST_CANCELLED"); break; case SC_TOO_MANY_REQUETS_QUEUED: FREDispatchStatusEventAsync(context, (const uint8_t *)"scorescontroller", (const uint8_t *)"SC_TOO_MANY_REQUETS_QUEUED"); break; case SC_INVALID_GAME_ID: FREDispatchStatusEventAsync(context, (const uint8_t *)"scorescontroller", (const uint8_t *)"SC_INVALID_GAME_ID"); break; default: FREDispatchStatusEventAsync(context, (const uint8_t *)"scorescontroller", (const uint8_t *)"SC_UNKNOWN_ERROR"); break; } }
void stillImageCallback(const uint8_t *data, int32_t size) { if(_cam_shot_data) free(_cam_shot_data); _cam_shot_data = (uint8_t*)malloc(size); memcpy(_cam_shot_data, data, size); _cam_shot_size = size; FREDispatchStatusEventAsync(_ctx, (const uint8_t*)"CAM_SHOT", (const uint8_t*)"0"); }
void *MIDIReadThread(FREContext ctx) { printf("MIDI Start read thread\n"); std::vector<unsigned char> message; int nBytes; double stamp; while(!exitRunThread) { //printf("Check thread, %i devices\n",openMidiIn.size()); for(unsigned int di=0;di<openMidiIn.size();di++) { RtMidiIn * in = openMidiIn[di]; while(true) { stamp = in->getMessage(&message ); nBytes = message.size(); if(nBytes == 3) //complete midi message { midiMessage m; m.device = in; m.stamp = stamp; m.status = message[0]; //printf("Status %i from %i\n",m.status,in); m.data1 = message[1]; m.data2 = message[2]; messageQueue.push_back(m); FREDispatchStatusEventAsync(ctx,(const uint8_t *)"data",(const uint8_t *)"none"); }else if(nBytes == 0) break; } } // Sleep for 10 milliseconds ... platform-dependent. Sleep( 1 ); //FREDispatchStatusEventAsync(ctx,(const uint8_t *)"data",(const uint8_t *)"myo"); } printf("Exit Run Thread !\n"); return 0; }
void* eventLoop(void* data) { FREContext ctx = (FREContext) data; float x, y, z; bps_event_t *event = NULL; char buffer[256]; // Initialize BPS bps_initialize(); // Start the gyroscope if (sensor_request_events(SENSOR_TYPE_GYROSCOPE) != BPS_SUCCESS) { shutdown = true; } // Receive events through the event channel while (!shutdown) { event = NULL; if (bps_get_event(&event, 50) != BPS_SUCCESS) return NULL; if (event) { if (bps_event_get_domain(event) == sensor_get_domain()) { if (bps_event_get_code(event) == SENSOR_GYROSCOPE_READING) { if (sensor_event_get_xyz(event, &x, &y, &z) == BPS_SUCCESS) { sprintf(buffer, "%f&%f&%f", x, y, z); fprintf(stdout, "Sensor event: %f&%f&%f\n", x, y, z); fflush(stdout); if(ctx != NULL) { FREDispatchStatusEventAsync(ctx, (uint8_t*)"CHANGE", (uint8_t*)buffer); } } } } } } if (sensor_stop_events(SENSOR_TYPE_GYROSCOPE) != BPS_SUCCESS) { fprintf(stdout, "Unable to stop sensor\n"); fflush(stdout); } // Stop BPS bps_shutdown(); return NULL; }
void *pollForData(void *) { unsigned char incomingBuffer[4096]; int incomingBufferSize = 0; uint8_t prevCollection = 0; while (1) { multiplatformSleep(2); // used only for testing. I want manageable loops, not crazy ones. //从10ms缩短到2ms,可以提高通信速率_wh incomingBufferSize = PollComport(comPort, incomingBuffer, 4095); if (incomingBufferSize > 0) { pthread_mutex_lock(&safety); memcpy(buffer + bufferSize, incomingBuffer, incomingBufferSize); bufferSize = bufferSize + incomingBufferSize; buffer[bufferSize] = 0; pthread_mutex_unlock(&safety); prevCollection = 1; } else { prevCollection = 0; } if ((sentEvent == 0) && (((prevCollection == 0) && (bufferSize > 0)) || (bufferSize > 1024))) { sentEvent = 1; FREDispatchStatusEventAsync(dllContext, (uint8_t*) "bufferHasData", (const uint8_t*) "INFO"); } else if (sentEvent == 1) { multiplatformSleep(200);//从500ms减到200ms_wh sentEvent = 0; } } return NULL; }
void imageSavedCallback() { FREDispatchStatusEventAsync(_ctx, (const uint8_t *)"IMAGE_SAVED", (const uint8_t *)"0"); }
void previewReadyCallback() { FREDispatchStatusEventAsync(_ctx, (const uint8_t*)"PREVIEW_READY", (const uint8_t*)"0"); }
void statusBarTappedCallback() { FREDispatchStatusEventAsync(_ctx, (const uint8_t*)"STATUS_BAR", (const uint8_t*)"0"); }
void ANESteam::DispatchEvent(char* code, char* level) { // ignore unsuccessful dispatches FREDispatchStatusEventAsync(AIRContext, (const uint8_t*)code, (const uint8_t*)level); }
/** * Called when a new contact event is received from the BBMSP library. */ void handle_contact_event( bbmsp_event_t* bbmsp_event, int event_type ) { trace( "processing contact event" ); bbmsp_result_t result = BBMSP_FAILURE; //Full contact list has been retrieved. if( event_type == BBMSP_SP_EVENT_CONTACT_LIST_FULL ) { if( bbmsp_event_contact_list_register_event() == BBMSP_FAILURE ) { trace( "bbmsp_event_contact_list_register_event() failure" ); } //we got the entire contact list bbmsp_contact_list_t *list; result = bbmsp_event_contact_list_get_full_contact_list( bbmsp_event, &list ); trace( "bbmsp_event_contact_list_get_full_contact_list %i", result ); contact_size = bbmsp_contact_list_get_size( list ); trace( "bbmsp_contact_list_get_size %i", contact_size ); contact_list = (bbmsp_contact_t**) malloc(sizeof(bbmsp_contact_t*) *contact_size); result = bbmsp_contact_list_get_all_contacts( list, contact_list ); trace( "bbmsp_contact_list_get_all_contacts %i", result ); pthread_mutex_lock( &amutex ); contactsCreated = false; //Dispatch event to ActionScript, which then calls getContactList() to retrieve the contact list. FREDispatchStatusEventAsync(context, (const uint8_t *)"contact", (const uint8_t *)"contact_list"); while( !contactsCreated ) { pthread_cond_wait( &acond, &amutex ); } pthread_mutex_unlock( &amutex ); free( contact_list ); } else if( event_type == BBMSP_SP_EVENT_CONTACT_CHANGED ) { //contact was changed bbmsp_contact_t* contact = 0; bbmsp_contact_create(&contact); result = bbmsp_event_contact_changed_get_contact(bbmsp_event, &contact); trace( "bbmsp_event_contact_changed_get_contact %i", result ); bbmsp_presence_update_types_t updateType; if(bbmsp_event_contact_changed_get_presence_update_type(bbmsp_event, &updateType) == BBMSP_SUCCESS) { trace( "updateType %i", updateType ); if( updateType & BBMSP_INSTALL_APP ) { trace( "adding contact" ); pthread_mutex_lock( &amutex ); bbmsp_contact_create( &contactToAdd ); bbmsp_contact_copy( contactToAdd, contact ); contactAdded = false; //Dispatch event to ActionScript, which then calls getAddedContact() to get the added contact. FREDispatchStatusEventAsync(context, (const uint8_t *)"contact", (const uint8_t *)"contact_added"); while( !contactAdded ) { pthread_cond_wait( &acond, &amutex ); } bbmsp_contact_destroy( &contactToAdd ); pthread_mutex_unlock( &amutex ); } if( updateType & BBMSP_DISPLAY_NAME ) { addContactUpdate( contact, BBMSP_DISPLAY_NAME ); FREDispatchStatusEventAsync(context, ( uint8_t* )"contact", (const uint8_t*)"contact_update"); } if( updateType & BBMSP_DISPLAY_PICTURE ) { addContactUpdate( contact, BBMSP_DISPLAY_PICTURE ); FREDispatchStatusEventAsync(context, ( uint8_t* )"contact", (const uint8_t*)"contact_update"); } if( updateType & BBMSP_PERSONAL_MESSAGE ) { addContactUpdate( contact, BBMSP_PERSONAL_MESSAGE ); FREDispatchStatusEventAsync(context, ( uint8_t* )"contact", (const uint8_t*)"contact_update"); } if( updateType & BBMSP_STATUS ) { addContactUpdate( contact, BBMSP_STATUS ); FREDispatchStatusEventAsync(context, ( uint8_t* )"contact", (const uint8_t*)"contact_update"); } if( updateType & BBMSP_UNINSTALL_APP ) { addContactUpdate( contact, BBMSP_UNINSTALL_APP ); FREDispatchStatusEventAsync(context, ( uint8_t* )"contact", (const uint8_t*)"contact_update"); } } } }
void KinectDevice::dispatchInfoMessage(const uint8_t* infoMessage) { FREDispatchStatusEventAsync(freContext, (const uint8_t*) "info", infoMessage); }
void KinectDevice::dispatchErrorMessage(const uint8_t* errorMessage) { FREDispatchStatusEventAsync(freContext, (const uint8_t*) "error", errorMessage); }
void KinectDevice::trace(const uint8_t* traceMessage) { FREDispatchStatusEventAsync(freContext, (const uint8_t*) "trace", traceMessage); }
void KinectDevice::dispatchStatusMessage(const uint8_t* statusMessage) { FREDispatchStatusEventAsync(freContext, (const uint8_t*) "status", statusMessage); }
//util void as3Print(const char * message) { FREDispatchStatusEventAsync(freContext, (const uint8_t*)"print", (const uint8_t*)message); }
void LNLeapListener::onExit(const Controller& controller) { std::cout << "LNLeapListener::Exited" << std::endl; FREDispatchStatusEventAsync(*m_ctx, (const uint8_t*) "onExit", (const uint8_t*) ""); }
void LNLeapListener::onFrame(const Controller& controller) { FREDispatchStatusEventAsync(*m_ctx, (const uint8_t*) "onFrame", (const uint8_t*) ""); }
void LNLeapListener::onServiceDisconnect(const Controller& controller) { std::cout << "LNLeapListener::ServiceDisconnect" << std::endl; FREDispatchStatusEventAsync(*m_ctx, (const uint8_t*) "onServiceDisconnect", (const uint8_t*) ""); }
void LNLeapListener::onDeviceChange(const Controller& controller) { std::cout << "LNLeapListener::DeviceChange" << std::endl; FREDispatchStatusEventAsync(*m_ctx, (const uint8_t*) "onDeviceChange", (const uint8_t*) ""); }
void dispatchMouseEvent(const uint8_t* code) { FREDispatchStatusEventAsync(context, code, (const uint8_t *) "info"); }