Esempio n. 1
0
CString ConvertKeyBoardShortcut(int32 &iKBShortcut)
{
  CString kbs(_T(""));
  if (iKBShortcut != 0) {
    CString cs_temp;
    WORD wVirtualKeyCode = iKBShortcut & 0xff;
    WORD wPWSModifiers = iKBShortcut >> 16;

    if (iKBShortcut != 0) {
      if (wPWSModifiers & PWS_HOTKEYF_ALT) {
        cs_temp.LoadString(IDS_ALTP);
        kbs += cs_temp;
      }
      if (wPWSModifiers & PWS_HOTKEYF_CONTROL) {
        cs_temp.LoadString(IDS_CTRLP);
        kbs += cs_temp;
      }
      if (wPWSModifiers & PWS_HOTKEYF_SHIFT) {
        cs_temp.LoadString(IDS_SHIFTP);
        kbs += cs_temp;
      }
      cs_temp.Format(L"%c", wVirtualKeyCode);
      kbs += cs_temp;
    }
  }
Esempio n. 2
0
TEST(FamilyReplacement, WorksAsExpected){
  AlgorithmState state;

  for(int i = 0; i < population_size; i++){
    Individual * next = new Individual(num_tasks);
    next->randomize();
    next->set_cost(i + population_size);
    state.population().add(next);
  }

  state.population().update_stats();
  
  KBestSelector kbs(num_parents);
  std::vector<const Individual *> parents = kbs(state);

  PMX pmx;
  RandomPairCrossoverStrategy rpcs(pmx);

  std::vector<Individual *> children = rpcs(state, parents);
  for(unsigned int i = 0; i < children.size(); i++)
    children[i]->set_cost(i);

  FamilyReplacement fr;
  fr(state, children);

  ASSERT_EQ(population_size, state.population().size());

  // all children should be in population
  for(int i = 0; i < num_parents; i++){
    bool found = false;
    for(int j = 0; j < population_size; j++){
      if(state.population()[j] == children[i]){
        found = true;
        break;
      }
    }

    ASSERT_TRUE(found);
  }
}
Esempio n. 3
0
std::string XKeyboard::get_kb_string()
{
  XkbGetControls(_display, XkbAllControlsMask, _kbdDescPtr);
  XkbGetNames(_display, XkbSymbolsNameMask, _kbdDescPtr);

  Atom symNameAtom = _kbdDescPtr->names->symbols;
  CHECK(symNameAtom != None);

  char* kbsC = XGetAtomName(_display, symNameAtom);
  std::string kbs(kbsC);
  XFree(kbsC);

  CHECK(!kbs.empty());
  return kbs;

  /*     StringVector symNames; */
  /*     XkbSymbolParser symParser; */
  /*     symParser.parse(symName, symNames); */
  /*     return symNames; */
}
Esempio n. 4
0
//
// Main Routine
//
int main(void) {
#ifdef DEBUG
	CSerial ser;		// declare a UART object
	ser.enable();
	CDebug dbg(ser);	// Debug stream use the UART object
	dbg.start();
#endif
	//
	// SoftDevice
	//
	bleDevice ble;
	ble.enable("Shutter", "1234");	// enable BLE SoftDevice task

	// Pin to clear all center list
	CPin btn(17);
	btn.input();

	// Device Manager for bond device.
	bleDeviceManager man(ble, (btn==LOW ? true : false));
	man.connect_directed_mode();	// enable "connect directed" mode to fast connected. (BT 4.1 spec.)

	// GAP
	ble.m_gap.settings( DEVICE_NAME,
			 	 	 	20,		// min. connection interval in millisecond
						100,	// max. connection interval in millisecond
						12);	// slave latency (save power)

	ble.m_gap.tx_power(BLE_TX_0dBm);

	//
	// HID Keyboard Service
	//
	bleServiceKB kbs(ble);

	//
	// Battery Level Service
	//
	bleServiceBattery bat(ble);

	//
	// Optional: Add "Connection Parameters Update" negotiation.
	//
	bleConnParams conn(ble);

	//
	// BLE Advertising
	//
	ble.m_advertising.add_uuid_to_complete_list(bat);				// add bat object to the uuid list of advertising
	ble.m_advertising.add_uuid_to_complete_list(kbs);				// add kbs object to the uuid list of advertising

	// Optional: add appearance to indicate who you are in advertisement.
	ble.m_advertising.appearance(BLE_APPEARANCE_HID_KEYBOARD);
	ble.m_advertising.update();										// update advertisement data

	// Start advertising
	ble.m_advertising.interval(APP_ADV_INTERVAL);					// set advertising interval
	ble.m_advertising.timeout(30);									// Enter system power off mode when adv. timeout. (disable system off if timeout=0)
	ble.m_advertising.start();

	//
	// Optional: Enable tickless technology
	//
#ifndef DEBUG
	CPowerSave::tickless(true);
#endif

	//
	// Key Test Task
	//
	CThread t(keyTask);
	t.start("kb", 76);		// start the keyTask

	//
	// Analog
	//
	CAdc::init();
	CAdc::source(VDD_1_3);	// to detect the VDD voltage
	CAdc::enable();

	//
	// LED
	//
	CPin led(LED_PIN_0);
	led.output();

	CTimeout tmBAT, tmLED;
	uint16_t value;
	float 	 percentage;

	//
    // Enter main loop.
	//
    while(1) {

    	//
    	// BLE Battery Service
    	//
    	if ( bat.isAvailable() ) {
    		if ( tmBAT.isExpired(1000) ) {
    			tmBAT.reset();
    			if ( CAdc::read(value) ) {
    				percentage = (value / 1024.0f) * 100;
    				bat.send(percentage);
    			}
    		}
    	}

    	//
    	// blink led
    	//
    	led = LED_ON;
    	sleep(10);
    	led = LED_OFF;
    	if ( ble.isConnected() ) {
    		sleep(290);
    	} else {
    		sleep(1990);
    	}

    	// Negotiate the "connection parameters update" in main-loop
    	conn.negotiate();
    }
}