struct razer_report razer_chroma_misc_set_orochi2011_poll_dpi(unsigned short poll_rate, unsigned char dpi_x, unsigned char dpi_y) { struct razer_report report = {0}; memcpy(&report, &orochi2011_dpi, sizeof(orochi2011_dpi)); switch(poll_rate) { case 1000: poll_rate = 0x01; break; case 500: poll_rate = 0x02; break; case 125: poll_rate = 0x08; break; default: // 500Hz poll_rate = 0x02; break; } report.arguments[1] = poll_rate; report.arguments[3] = clamp_u8(dpi_x, 0x15, 0x9C); report.arguments[4] = clamp_u8(dpi_y, 0x15, 0x9C); return report; }
GUIChatConsole::GUIChatConsole( gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, ChatBackend* backend, Client* client, IMenuManager* menumgr ): IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, core::rect<s32>(0,0,100,100)), m_chat_backend(backend), m_client(client), m_menumgr(menumgr), m_animate_time_old(porting::getTimeMs()) { // load background settings s32 console_alpha = g_settings->getS32("console_alpha"); m_background_color.setAlpha(clamp_u8(console_alpha)); // load the background texture depending on settings ITextureSource *tsrc = client->getTextureSource(); if (tsrc->isKnownSourceImage("background_chat.jpg")) { m_background = tsrc->getTexture("background_chat.jpg"); m_background_color.setRed(255); m_background_color.setGreen(255); m_background_color.setBlue(255); } else { v3f console_color = g_settings->getV3F("console_color"); m_background_color.setRed(clamp_u8(myround(console_color.X))); m_background_color.setGreen(clamp_u8(myround(console_color.Y))); m_background_color.setBlue(clamp_u8(myround(console_color.Z))); } m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Mono); if (!m_font) { errorstream << "GUIChatConsole: Unable to load mono font "; } else { core::dimension2d<u32> dim = m_font->getDimension(L"M"); m_fontsize = v2u32(dim.Width, dim.Height); m_font->grab(); } m_fontsize.X = MYMAX(m_fontsize.X, 1); m_fontsize.Y = MYMAX(m_fontsize.Y, 1); // set default cursor options setCursor(true, true, 2.0, 0.1); }
/** * Set the charging effect, think if I remember correctly, it's either static colour, or "whatever the mouse was last on" */ struct razer_report razer_chroma_misc_set_dock_charge_type(unsigned char charge_type) { struct razer_report report = get_razer_report(0x03, 0x10, 0x01); report.arguments[0] = clamp_u8(charge_type, 0x00, 0x01); return report; }
/** * Set the effect of the LED matrix to Wave * * Status Trans Packet Proto DataSize Class CMD Args * ? TODO fill this */ struct razer_report razer_chroma_standard_matrix_effect_wave(unsigned char variable_storage, unsigned char led_id, unsigned char wave_direction) { struct razer_report report = get_razer_report(0x03, 0x0A, 0x02); report.arguments[0] = 0x01; // Effect ID report.arguments[1] = clamp_u8(wave_direction, 0x01, 0x02); return report; }
/** * Toggled whether F1-12 act as F1-12 or if they act as the function options (without Fn pressed) * * If 0 should mean that the F-keys work as normal F-keys * If 1 should mean that the F-keys act as if the FN key is held */ struct razer_report razer_chroma_misc_fn_key_toggle(unsigned char state) { struct razer_report report = get_razer_report(0x02, 0x06, 0x02); report.arguments[0] = 0x00; // ?? Variable storage maybe report.arguments[1] = clamp_u8(state, 0x00, 0x01); // State return report; }
/** * Set the device to "Starlight" effect * * Speed is 0x01 - 0x03 * * Status Trans Packet Proto DataSize Class CMD Args * 00 3f 0000 00 06 0f 02 010507000100 | SET LED MATRIX Effect (VARSTR, Backlight, Starlight 0x07, ? 0x00, Speed 0x01, Colours 0x00) * 00 3f 0000 00 06 0f 02 010507000200 | SET LED MATRIX Effect (VARSTR, Backlight, Starlight 0x07, ? 0x00, Speed 0x02, Colours 0x00) * 00 3f 0000 00 06 0f 02 010507000300 | SET LED MATRIX Effect (VARSTR, Backlight, Starlight 0x07, ? 0x00, Speed 0x03, Colours 0x00) * 00 3f 0000 00 09 0f 02 010507000301ff0000 | SET LED MATRIX Effect (VARSTR, Backlight, Starlight 0x07, ? 0x00, Speed 0x03, Colours 0x01, RGB 0xFF0000) * 00 3f 0000 00 0c 0f 02 010507000302ff000000ff00 | SET LED MATRIX Effect (VARSTR, Backlight, Starlight 0x07, ? 0x00, Speed 0x03, Colours 0x02, RGB 0xFF0000, RGB 0x00FF00) */ struct razer_report razer_chroma_extended_matrix_effect_starlight_random(unsigned char variable_storage, unsigned char led_id, unsigned char speed) { struct razer_report report = razer_chroma_extended_matrix_effect_base(0x06, variable_storage, led_id, 0x07); speed = clamp_u8(speed, 0x01, 0x03); report.arguments[4] = speed; return report; }
/** * Set the state of an LED on the device * * Status Trans Packet Proto DataSize Class CMD Args * 00 3f 0000 00 03 03 00 010801 | SET LED STATE (VARSTR, GAMEMODE, ON) * 00 3f 0000 00 03 03 00 010800 | SET LED STATE (VARSTR, GAMEMODE, OFF) */ struct razer_report razer_chroma_standard_set_led_state(unsigned char variable_storage, unsigned char led_id, unsigned char led_state) { struct razer_report report = get_razer_report(0x03, 0x00, 0x03); report.arguments[0] = variable_storage; report.arguments[1] = led_id; report.arguments[2] = clamp_u8(led_state, 0x00, 0x01); return report; }
/** * Set the device to "Wave" effect * * Seems like direction is now 0x00, 0x01 for Left/Right, used to be 0x01, 0x02 * * Status Trans Packet Proto DataSize Class CMD Args * 00 3f 0000 00 06 0f 02 010504002800 | SET LED MATRIX Effect (VARSTR, Backlight, Wave 0x04, Dir 0x00, ? 0x2800) * 00 3f 0000 00 06 0f 02 010504012800 | SET LED MATRIX Effect (VARSTR, Backlight, Wave 0x04, Dir 0x01, ? 0x2800) */ struct razer_report razer_chroma_extended_matrix_effect_wave(unsigned char variable_storage, unsigned char led_id, unsigned char direction) { struct razer_report report = razer_chroma_extended_matrix_effect_base(0x06, variable_storage, led_id, 0x04); direction = clamp_u8(direction, 0x00, 0x01); report.arguments[3] = direction; report.arguments[4] = 0x28; // Unknown return report; }
/** * Set low battery threshold * * 0x3F = 25% * 0x26 = 15% * 0x0C = 5% */ struct razer_report razer_chroma_misc_set_low_battery_threshold(unsigned char battery_threshold) { struct razer_report report = get_razer_report(0x07, 0x01, 0x01); // Keep the idle time within bounds battery_threshold = clamp_u8(battery_threshold, 0x0C, 0x3F); report.arguments[0] = battery_threshold; return report; }
/** * Set the effect of the LED matrix to Reactive * * Status Trans Packet Proto DataSize Class CMD Args * ? TODO fill this */ struct razer_report razer_chroma_standard_matrix_effect_reactive(unsigned char variable_storage, unsigned char led_id, unsigned char speed, struct razer_rgb *rgb1) { struct razer_report report = get_razer_report(0x03, 0x0A, 0x05); report.arguments[0] = 0x02; // Effect ID report.arguments[1] = clamp_u8(speed, 0x01, 0x04); // Time report.arguments[2] = rgb1->r; /*rgb color definition*/ report.arguments[3] = rgb1->g; report.arguments[4] = rgb1->b; return report; }
struct razer_report razer_chroma_standard_matrix_effect_starlight_random(unsigned char variable_storage, unsigned char led_id, unsigned char speed) { struct razer_report report = get_razer_report(0x03, 0x0A, 0x01); speed = clamp_u8(speed, 0x01, 0x03); // For now only seen report.arguments[0] = 0x19; // Effect ID report.arguments[1] = 0x03; // Type random color report.arguments[2] = speed; // Speed return report; }
/** * Set the device to "Reactive" effect * * Status Trans Packet Proto DataSize Class CMD Args * 00 3f 0000 00 07 03 0d 010102 0300ff00 | SET Extended Matrix Effect (VARSTORE, SCROLL_WHEEL, REACTIVE, TIME, RGB) * 00 3f 0000 00 07 03 0d 010102 0200ff00 | SET Extended Matrix Effect (VARSTORE, SCROLL_WHEEL, REACTIVE, TIME, RGB) * 00 3f 0000 00 07 03 0d 010102 0100ff00 | SET Extended Matrix Effect (VARSTORE, SCROLL_WHEEL, REACTIVE, TIME, RGB) */ struct razer_report razer_chroma_mouse_extended_matrix_effect_reactive(unsigned char variable_storage, unsigned char led_id, unsigned char speed, struct razer_rgb *rgb) { struct razer_report report = razer_chroma_mouse_extended_matrix_effect_base(0x07, variable_storage, led_id, 0x02); speed = clamp_u8(speed, 0x01, 0x04); report.arguments[3] = speed; report.arguments[4] = rgb->r; report.arguments[5] = rgb->g; report.arguments[6] = rgb->b; return report; }
struct razer_report razer_chroma_extended_matrix_effect_starlight_single(unsigned char variable_storage, unsigned char led_id, unsigned char speed, struct razer_rgb *rgb1) { struct razer_report report = razer_chroma_extended_matrix_effect_base(0x09, variable_storage, led_id, 0x07); speed = clamp_u8(speed, 0x01, 0x03); report.arguments[4] = speed; report.arguments[5] = 0x01; report.arguments[6] = rgb1->r; report.arguments[7] = rgb1->g; report.arguments[8] = rgb1->b; return report; }
void dot3k_bl_calibrate(DOT3K *dot3k, float gamma, float r_div, float g_div, float b_div) { for(int level = 0; level < 256; level++) { float p = powf(level / 256.0f, gamma); for(int off = 0; off < 3; off++) { uint8_t r = clamp_u8(p / r_div * 255.0f); uint8_t g = clamp_u8(p / g_div * 255.0f); uint8_t b = clamp_u8(p / b_div * 255.0f); dot3k->backlight_level_map[off * 3 + 0][level] = clamp_u8(r); dot3k->backlight_level_map[off * 3 + 1][level] = clamp_u8(g); dot3k->backlight_level_map[off * 3 + 2][level] = clamp_u8(b); //printf("%02x: %02x %02x %02x\n", level, r, g, b); } } }
/** * Set the effect of the LED matrix to Starlight * * Status Trans Packet Proto DataSize Class CMD Args * ? TODO fill this */ struct razer_report razer_chroma_standard_matrix_effect_starlight_dual(unsigned char variable_storage, unsigned char led_id, unsigned char speed, struct razer_rgb *rgb1, struct razer_rgb *rgb2) { struct razer_report report = get_razer_report(0x03, 0x0A, 0x01); speed = clamp_u8(speed, 0x01, 0x03); // For now only seen report.arguments[0] = 0x19; // Effect ID report.arguments[1] = 0x02; // Type two color report.arguments[2] = speed; // Speed report.arguments[3] = rgb1->r; // Red 1 report.arguments[4] = rgb1->g; // Green 1 report.arguments[5] = rgb1->b; // Blue 1 // For now haven't seen any chroma using this, seen the extended version report.arguments[6] = rgb2->r; // Red 2 report.arguments[7] = rgb2->g; // Green 2 report.arguments[8] = rgb2->b; // Blue 2 return report; }
GUIChatConsole::GUIChatConsole( gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, ChatBackend* backend, Client* client ): IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, core::rect<s32>(0,0,100,100)), m_chat_backend(backend), m_client(client), m_screensize(v2u32(0,0)), m_animate_time_old(0), m_open(false), m_height(0), m_desired_height(0), m_desired_height_fraction(0.0), m_height_speed(5.0), m_open_inhibited(0), m_cursor_blink(0.0), m_cursor_blink_speed(0.0), m_cursor_height(0.0), m_background(NULL), m_background_color(255, 0, 0, 0), m_font(NULL), m_fontsize(0, 0) { m_animate_time_old = getTimeMs(); // load background settings bool console_color_set = !g_settings->get("console_color").empty(); s32 console_alpha = g_settings->getS32("console_alpha"); // load the background texture depending on settings m_background_color.setAlpha(clamp_u8(console_alpha)); if (console_color_set) { v3f console_color = g_settings->getV3F("console_color"); m_background_color.setRed(clamp_u8(myround(console_color.X))); m_background_color.setGreen(clamp_u8(myround(console_color.Y))); m_background_color.setBlue(clamp_u8(myround(console_color.Z))); } else { m_background = env->getVideoDriver()->getTexture(getTexturePath("background_chat.jpg").c_str()); m_background_color.setRed(255); m_background_color.setGreen(255); m_background_color.setBlue(255); } // load the font // FIXME should a custom texture_path be searched too? #if USE_FREETYPE std::string font_name = g_settings->get("mono_font_path"); u16 font_size = g_settings->getU16("mono_font_size"); m_font = gui::CGUITTFont::createTTFont(env, font_name.c_str(), font_size); #else std::string font_name = "fontdejavusansmono.png"; m_font = env->getFont(getTexturePath(font_name).c_str()); #endif if (m_font == NULL) { dstream << "Unable to load font: " << font_name << std::endl; } else { core::dimension2d<u32> dim = m_font->getDimension(L"M"); m_fontsize = v2u32(dim.Width, dim.Height); dstream << "Font size: " << m_fontsize.X << " " << m_fontsize.Y << std::endl; } m_fontsize.X = MYMAX(m_fontsize.X, 1); m_fontsize.Y = MYMAX(m_fontsize.Y, 1); // set default cursor options setCursor(true, true, 2.0, 0.1); }
void __CtrlSetAnalogY(float y, int stick) { std::lock_guard<std::recursive_mutex> guard(ctrlMutex); int scaled = (int)ceilf(-y * 127.5f + 127.5f); ctrlCurrent.analog[stick][CTRL_ANALOG_Y] = clamp_u8(scaled); }
int receive_sample_block(hackrf_transfer *transfer) { uint64_t local_frequency = frequency; if (skip > 0) { skip--; return 0; } if (history_rows >= FFT_HISTORY_SIZE) return 0; int ii = 0; for (int i = 0; i < SAMPLES_SIZE; i += 2) { int vi = (transfer->buffer[i] + 128) % 256; int vq = (transfer->buffer[i + 1] + 128) % 256; fft_in[ii][0] = powf(-1, ii) * vi / 256.0; fft_in[ii][1] = powf(-1, ii) * vq / 256.0; ii++; } fftw_execute(fft_plan); // Move one line down. memcpy(fft_history + FFT_SIZE, fft_history, FFT_SIZE * (FFT_HISTORY_SIZE - 1) * sizeof(fftw_complex)); // Set the first line. memcpy(fft_history, fft_out, FFT_SIZE * sizeof(fftw_complex)); history_rows++; // Verify that there actually is some data before continuing. if (history_rows == EVALUATE_ROWS) { double total = 0; int size = history_rows * FFT_SIZE; for (int i = 0; i < size; i ++) { double ci = fft_history[i][0]; double cq = fft_history[i][1]; double pwr = sqrt(ci * ci + cq * cq); total += pwr; } double avg_pwr = total / (double) size; printf("\n(Average power: %.2f)\n", avg_pwr); if (avg_pwr < 1.1) { printf("Not interesting. Skipping...\n"); // Trigger exit condition. history_rows = FFT_HISTORY_SIZE; return 0; } } printf("\r%.f%%", history_rows / (float)FFT_HISTORY_SIZE * 100); fflush(stdout); if (history_rows >= FFT_HISTORY_SIZE) { printf("\n"); // Write image. uint8_t *buffer = calloc(FFT_SIZE * FFT_HISTORY_SIZE, sizeof(uint8_t)); for (int y = 0; y < FFT_HISTORY_SIZE; y++) { for (int x = 0; x < FFT_SIZE; x++) { double ci = fft_history[y * FFT_SIZE + x][0]; double cq = fft_history[y * FFT_SIZE + x][1]; double pwr = ci * ci + cq * cq; //double pwr_dbfs = 10.0 * log2(pwr + 1.0e-20) / log2(2.7182818284); double pwr_dbfs = 10.0 * log10(pwr + 1.0e-20); pwr_dbfs = pwr_dbfs * 5; uint8_t v = clamp_u8(pwr_dbfs, 0, 255); if (x == FFT_SIZE / 2) { v = buffer[y * FFT_SIZE + x - 1]; } buffer[y * FFT_SIZE + x] = v; } } char file_name[100]; snprintf(file_name, 100, "broad-%.0f.png", local_frequency / 1.0e6); write_gray_png(file_name, FFT_SIZE, FFT_HISTORY_SIZE, buffer); free(buffer); } return 0; }
void __CtrlSetAnalogX(float x, int stick) { u8 scaled = clamp_u8((int)ceilf(x * 127.5f + 127.5f)); std::lock_guard<std::recursive_mutex> guard(ctrlMutex); ctrlCurrent.analog[stick][CTRL_ANALOG_X] = scaled; }