void hmi3d_message_handle(hmi_t *hmi, const void *msg, int size) { /* NOTE messages are ensured to have a size of at least 4 bytes */ const unsigned char *data = (const unsigned char*)msg; switch(GET_U8(data+3)) { case hmi3d_msg_System_Status: hmi3d_handle_system_status(hmi, data, size); break; #if !defined(HMI3D_NO_FW_VERSION) || !defined(HMI3D_NO_UPDATE) case hmi3d_msg_Fw_Version_Info: hmi3d_handle_version_info(hmi, data, size); break; #endif #ifndef HMI3D_NO_DATA_RETRIEVAL case hmi3d_msg_Sensor_Data_Output: hmi3d_handle_data_output(hmi, data); break; #endif #ifndef HMI3D_NO_RTC case hmi3d_msg_Set_Runtime_Parameter: hmi3d_handle_runtime_parameter(hmi, data); break; #endif default: break; } }
void hmi2d_handle_fw_version(hmi_t *hmi, const unsigned char *msg) { int size = msg[1]; const unsigned char *data = msg + 2; hmi2d_version_request_t *request; hmi2d_version_info_t *version; if(size != 128) { HMI_BAD_DATA("hmi2d_handle_fw_version", "Expected message size of 128 bytes", size, 0); return; } #ifdef HMI3D_SYNC_THREADING /* Synchronize against hmi2d_query_fw_version calls from application */ HMI_SYNC_LOCK(hmi->io_sync); #endif request = hmi->version2d_request; if(request) { version = request->version; if(version) { version->svn_revision = GET_U16(data + 0); version->wc_mixed = GET_U8(data + 2); version->wc_modified = GET_U8(data + 3); version->build_year = GET_U16(data + 4); version->build_month = GET_U8(data + 6); version->build_day = GET_U8(data + 7); version->build_hour = GET_U8(data + 8); version->build_minute = GET_U8(data + 9); version->build_second = GET_U8(data + 10); HMI_MEMCPY(version->buildBy, data + 11, 9); HMI_MEMCPY(version->infoString, data + 20, 76); version->checksum = GET_U32(data + 108); version->fw_app_id = GET_U32(data + 120); HMI_MEMCPY(version->fw_version, data + 124, 4); } request->received = 1; } #ifdef HMI3D_SYNC_THREADING /* Release synchronization against hmi2d_query_fw_version */ HMI_SYNC_UNLOCK(hmi->io_sync); #endif }
void hmi3d_handle_system_status(hmi_t *hmi, const unsigned char *data, int size) { if(size == 16) { int msg_id = GET_U8(data + 4); int error_code = GET_U16(data + 6); if(msg_id == hmi->resp_msg_id || error_code == hmi3d_system_WakeupHappened) { hmi->resp_msg_id = 0; hmi->resp_error_code = error_code; } } else { HMI_BAD_DATA("hmi3d_handle_system_status", "Expected message size of 16 bytes", size, 0); } }
void hmi2d_handle_parameter(hmi_t *hmi, const unsigned char *msg) { hmi_param_request_t *request; int size = msg[1]; const unsigned char *data = msg + 2; int param_id; int value = 0; int i; if(size < 3 || size > 6) { HMI_BAD_DATA("hmi2d_handle_parameter", "Expected message size of 3 to 6 bytes", size, 0); return; } #ifdef HMI_SYNC_THREADING /* Synchronize against calls to hmi2d_get_param from application */ HMI_SYNC_LOCK(hmi->io_sync); #endif request = hmi->param2d_request; param_id = GET_U16(data); if(request && request->param == param_id) { for(i = 0; i < size-2; ++i) value |= GET_U8(data + 2 + i) << (8*i); if(request->arg0) *request->arg0 = value; request->param = 0; } #ifdef HMI_SYNC_THREADING /* Release synchronization against hmi2d_get_param */ HMI_SYNC_UNLOCK(hmi->io_sync); #endif }
void gestic_handle_data_output(gestic_t *gestic, const unsigned char *data) { int dataOutputConfig = GET_U16(data + 4); unsigned char timestamp = GET_U8(data + 6); int systemInfo = GET_U8(data + 7); const unsigned char *cursor = data + 8; int systemMode = (dataOutputConfig & gestic_DataOutConfigMask_ElectrodeConfiguration) >> 8; int electrodeCount = systemModeElectrodes[systemMode]; int increment; gestic_input_data_t *dest = &gestic->internal; int airWheelActive = (systemInfo & gestic_SystemInfo_AirWheelValid) ? 1 : 0; #ifdef GESTIC_SYNC_THREADING /* Synchronize against interaction with the internal buffer * from the Application-Layer */ GESTIC_SYNC_LOCK(gestic->io_sync); #endif /* NOTE Overflows should not be a problem as long as more * than one message per 256 samples is received. * Otherwise this algorithm will loose precision but should * still work as counts are only compared for equality * or via substraction. */ increment = (unsigned char)(timestamp - gestic->last_time_stamp); dest->frame_counter += increment ? increment : 1; gestic->last_time_stamp = timestamp; if(dataOutputConfig & gestic_DataOutConfigMask_DSPStatus) { int calibration = GET_U8(cursor); int frequency = GET_U8(cursor + 1); if(calibration != 0) { dest->calib.reason = calibration; dest->calib.last_event = dest->frame_counter; } if(frequency != dest->frequency.frequency) { dest->frequency.frequency = frequency; dest->frequency.freq_changed = 1; dest->frequency.last_event = dest->frame_counter; } cursor += 2; } if(dataOutputConfig & gestic_DataOutConfigMask_GestureInfo) { int gestureInfo = GET_U32(cursor); int raw = gestureInfo & 0xFF; int gesture = raw > 1 ? raw - 1 : 0; if(gesture) { dest->gesture.gesture = gesture; dest->gesture.flags = gestureInfo & gestic_gesture_flags_mask; dest->gesture.last_event = dest->frame_counter; } cursor += 4; } if(dataOutputConfig & gestic_DataOutConfigMask_TouchInfo) { int info = GET_U32(cursor); int touch = info & gestic_touch_mask; int tap = info & gestic_tap_mask; if((gestic_touch_flags_t)touch != dest->touch.flags) { dest->touch.flags = touch; dest->touch.last_event = dest->frame_counter; dest->touch.last_touch_event_start = dest->frame_counter - ((info & 0xFF0000) >> 16); }
/***************************************************************************** * FUNCTION * image_gif_get_frame_count * DESCRIPTION * get frame count of a gif from file * PARAMETERS * filename [IN] * framecount [OUT] * RETURNS * MMI_BOOL MMI_TRUE or MMI_FALSE *****************************************************************************/ static MMI_BOOL image_gif_get_frame_count(S8 *filename, U32 *framecount) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ FILE *fp; U8 *buf, *src; U32 header; U32 file_size; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ /* open file and read header to buffer */ fp = fopen((char *)filename, "rb"); if (fp == NULL) { fprintf(stderr, "Open file error:\t%s\n", filename); fprintf(stderr, "\t%s\n", strerror(errno)); return MMI_FALSE; } fseek(fp, 0, SEEK_END); file_size = (U32)ftell(fp); fseek(fp, 0, SEEK_SET); buf = (U8*)malloc(file_size*sizeof(U8)); if (buf == NULL) { fprintf(stderr, "Memory allocation failed:\t%s\n", filename); MYFCLOSE(fp); return MMI_FALSE; } if (fread(buf, sizeof(char), file_size, fp) != file_size) { fprintf(stderr, "Read file error:\t%s\n", filename); MYFCLOSE(fp); return MMI_FALSE; } src = buf; MYFCLOSE(fp); /* init the return frame_count value */ *framecount = 0; /* read the GIF file signature */ { U8 sig[3]; GET_U8(src, sig[0]); GET_U8(src, sig[1]); GET_U8(src, sig[2]); if (sig[0] != 'G' || sig[1] != 'I' || sig[2] != 'F') { return MMI_FALSE; } } /* skip dimension value */ { S16 img_w, img_h; FLUSH(src, 3); GET_U16(src, img_w); GET_U16(src, img_h); if(img_w < 0 || img_h < 0 || img_w >= 10240 || img_h >= 10240) { return MMI_FALSE; } } /* read the global color palette */ { S32 palette_count; GET_U8(src, palette_count); FLUSH(src, 2); if (palette_count & 0x80) { palette_count = 1 << ((palette_count & 0x7) + 1); FLUSH(src, (palette_count * 3)); } } /* start decoding */ do { U8 symbol; GET_U8(src, symbol); switch(symbol) { /* Process the GIF extension block */ case '!': { U8 ext; GET_U8(src, ext); if (ext == 0xf9) { FLUSH(src, 6); } else { U8 boffset; S32 offset; while (1) { GET_U8(src, boffset); offset = (S32)boffset; if (offset == 0) { break; } FLUSH(src, offset); } } } break; case ',': /* gdi_image_gif_dummy_decoder(); */ { S32 want_pixels; S32 bitstream_available_bits, bytestream_available; S32 GDI_TREE_BUFFER[GDI_GIF_TREE_SIZE / sizeof(S32)]; U32 bitstream; S16 GIF_current_code_size, GIF_clear_code, GIF_end_code, GIF_new_codes, GIF_top_slot, GIF_slot; S16 size, c, oc, fc, code; S16 *stack_pointer; S16 GIF_mtk_stack[GDI_GIF_STACK_SIZE / sizeof(S16)]; S16 *GIF_mtk_suffix = (S16 *) GDI_TREE_BUFFER; S16 *GIF_mtk_prefix = (S16 *) (((U8 *) GDI_TREE_BUFFER) + sizeof(GDI_TREE_BUFFER) / 2); U16 temp; U8 finished_decoding = 0; { S32 x, y, xsize, ysize; GET_U16(src, temp); x = (S32)temp; GET_U16(src, temp); y = (S32)temp; GET_U16(src, temp); xsize = (S32)temp; GET_U16(src, temp); ysize = (S32)temp; want_pixels = xsize * ysize; } { S32 n; GET_U8(src, n); if (src >= buf + file_size) { return MMI_FALSE; } if (n & 0x80) { n = 1 << ((n & 0x7) + 1); /* skip reading palette */ FLUSH(src, n * 3); } } GET_U8(src, temp); size = (S16)temp; /* GIF_INITIALIZE_DECODER(size);*/ GIF_current_code_size = (S16)(size + 1); GIF_top_slot = (S16)(1 << GIF_current_code_size); GIF_clear_code = (S16)(1 << size); GIF_end_code = (S16)(GIF_clear_code + 1); GIF_slot = (GIF_new_codes) = (S16)(GIF_end_code + 1); bitstream_available_bits = 0; bytestream_available = 0; bitstream = 0; oc = fc = 0; stack_pointer = GIF_mtk_stack; /* begin decoding */ while (!finished_decoding) { /* GIF_GET_NEXT_CODE(c); */ while(GIF_current_code_size > bitstream_available_bits) { if(bytestream_available == 0) { GET_U8(src, temp); bytestream_available = (S32)temp; } GET_U8(src, temp); bitstream |= temp << bitstream_available_bits; bitstream_available_bits +=8; bytestream_available--; } bitstream_available_bits -= GIF_current_code_size; c = (S16) bitstream & ((1 << GIF_current_code_size) - 1); bitstream >>= GIF_current_code_size; if (c == GIF_end_code) { break; } if (src >= buf + file_size) { return MMI_FALSE; } if (c == GIF_clear_code) { GIF_current_code_size = (S16) (size + 1); GIF_slot = GIF_new_codes; GIF_top_slot = (S16) (1 << GIF_current_code_size); /* GIF_GET_NEXT_CODE(c); */ while(GIF_current_code_size > bitstream_available_bits) { if(bytestream_available == 0) { GET_U8(src, temp); bytestream_available = (S32)temp; } GET_U8(src, temp); bitstream |= temp << bitstream_available_bits; bitstream_available_bits +=8; bytestream_available--; } bitstream_available_bits -= GIF_current_code_size; c = (S16) bitstream & ((1 << GIF_current_code_size) - 1); bitstream >>= GIF_current_code_size; if (c == GIF_end_code) { break; } if (src >= buf + file_size) { return MMI_FALSE; } if (c >= GIF_slot) { c = 0; } oc = fc = c; if ((--want_pixels) < 0) { finished_decoding = 1; } } else { code = c; if (code >= GIF_slot) { code = oc; *stack_pointer++ = fc; } while (code >= GIF_new_codes) { if(stack_pointer >= (S16*)(((U8*)GIF_mtk_stack) + sizeof(GIF_mtk_stack))) { return MMI_FALSE; } *stack_pointer++ = GIF_mtk_suffix[code]; code = GIF_mtk_prefix[code]; } *stack_pointer++ = code; if (GIF_slot < GIF_top_slot) { GIF_mtk_suffix[GIF_slot] = fc = code; GIF_mtk_prefix[GIF_slot++] = oc; oc = c; } if (GIF_slot >= GIF_top_slot) { if (GIF_current_code_size < 12) { GIF_top_slot <<= 1; GIF_current_code_size++; } } while (stack_pointer > GIF_mtk_stack) { if ((--want_pixels) < 0) { finished_decoding = 1; break; } --stack_pointer; } } } } (*framecount) += 1; /* peek if is last frame */ { U8 test1, test2; PEEK_U8(src, test1); PEEK_U8_N(src, test2, 1); if ((test1 == '\0') && (test2 == ';')) { /* GDI_GIF_LAST_FRAME;; */ return MMI_TRUE; } } break; case '\0': if (src >= buf + file_size) { /* GDI_GIF_LAST_FRAME */ return MMI_TRUE; } break; case ';': /* GDI_GIF_LAST_FRAME;; */ return MMI_TRUE; break; }