コード例 #1
0
ファイル: main.c プロジェクト: drmilhous/Academic
int main(void)
{
	
	//256
    uint8_t key[] = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
                      0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4 };
    uint8_t in[]  = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};
    uint8_t out[16];
	
	for(int i = 0; i < 16; i++)
	{
		out[i] = in[i];
	}
	phex(out,16);
	
    struct AES_ctx ctx;
    AES_init_ctx(&ctx, key);
    AES_ECB_encrypt(&ctx, in);
	phex(in,16);
	AES_init_ctx(&ctx, key);
	AES_ECB_decrypt(&ctx, in);
	phex(out,16);


    return 0;
}
コード例 #2
0
void usb_keyboard_print_report(report_keyboard_t *report)
{
    if (!debug_keyboard) return;
    print("keys: ");
    for (int i = 0; i < REPORT_KEYS; i++) { phex(report->keys[i]); print(" "); }
    print(" mods: "); phex(report->mods); print("\n");
}
コード例 #3
0
ファイル: macro.c プロジェクト: myhackit/firmware
void parse_macro(char* line){
	uint8_t action, length, i, j = 0;
	if(memcmp(line,"[MACRO_",7)==0){
		macro_idx = line[7] - '0' - 1;
	} else { 
		ptr = line;
		j=0;
		while((token = strtok_r(ptr, ",", &rest)) != NULL) {
			ptr2 = token;
			i = length = action = 0;
			while((token2 = strtok_r(ptr2, ":", &rest2)) != NULL) {
				if(i==0){
					length = atoi(token2);
				} else if(i == 1){
					action = lookup_id(token2);
				}
				i++;
				ptr2 = rest2;
			}
			phex(action); phex(length); print("\n");
			macro_steps[macro_idx][(j*2)] = action;
			macro_steps[macro_idx][(j*2)+1] = length;
			ptr = rest;
			j++;
		}
		macro_sizes[macro_idx] = j;
		//for(j=0;j<macro_sizes[macro_idx];){
		//	phex(j);phex(macro_steps[macro_idx][j++]); phex(macro_steps[macro_idx][j++]);print(" ");
		//}
	}
}
コード例 #4
0
ファイル: usb_mouse.c プロジェクト: 0mark/tmk_keyboard
void usb_mouse_print(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons) {
    if (!debug_mouse) return;
    print("usb_mouse[btn|x y v h]: ");
    phex(buttons); print("|");
    phex(x); print(" ");
    phex(y); print(" ");
    phex(wheel_v); print(" ");
    phex(wheel_h); print("\n");
}
コード例 #5
0
ファイル: main.c プロジェクト: gioele/costar_keyboard
void debug_print(void) {
  debug_counter++;
  if(debug_counter > 100) {
    debug_counter = 0;
    for(uint8_t i = 0; i < 7; i++)
      phex(queue[i]);
    print("\n");
    for(uint8_t k = 0; k < NUMBER_OF_KEYS; k++)
      phex(key[k].bounce);
    print("\n");
  }
}
コード例 #6
0
ファイル: tuner.c プロジェクト: eframp/p600fw
static NOINLINE void ffDoTimeout(void)
{
	++ff_timeoutCount;
#ifdef DEBUG
	print("bad flip flop status : ");
	phex(ff_step);
	phex(io_read(0x9));
	print(" timeout count : ");
	phex(ff_timeoutCount);
	print("\n");
#endif	
}
コード例 #7
0
void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
{
    print("action_function called\n");
    print("id  = "); phex(id); print("\n");
    print("opt = "); phex(opt); print("\n");
    if (id == TEENSY_KEY) {
        clear_keyboard();
        print("\n\nJump to bootloader... ");
        _delay_ms(250);
        bootloader_jump(); // should not return
        print("not supported.\n");
    }
}
コード例 #8
0
ファイル: test.c プロジェクト: xutianxi/hls_segmenter_aes
static void test_decrypt_cbc(void)
{
  // Example "simulating" a smaller buffer...

  uint8_t key[] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x61, 0x62, 0x63, 0x64, 0x65, 0x0a };
  uint8_t iv[]  = { 0x4b, 0xb2, 0x77, 0x87, 0x77, 0xb8, 0x8b, 0xe0, 0xf8, 0x53, 0x4b, 0x7b, 0xd5, 0xba, 0x91, 0x30 };
  /*uint8_t in[]  = { 0x28, 0x93, 0x77, 0xc4, 0x9f, 0x3e, 0xd4, 0x9a, 0x1e, 0x85, 0x84, 0x58, 0x6b, 0x40, 0x23, 0xf8,
					0xff, 0xbd, 0x21, 0x0f, 0x2a, 0x62, 0xe5, 0x4e, 0x6e, 0x89, 0xad, 0x96, 0xee, 0x2e, 0xf2, 0xb9,
                    0x73, 0xbe, 0xd6, 0xb8, 0xe3, 0xc1, 0x74, 0x3b, 0x71, 0x16, 0xe6, 0x9e, 0x22, 0x22, 0x95, 0x16, 
                    0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09, 0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7 };
  uint8_t out[] = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
                    0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
                    0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
                    0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 };
	*/ 
  char in[32] = "1234567890abcdef";
	char out[64] = {0};
 uint8_t buffer[64] = {0};

int j;
  for ( j = 16; j<32; j++)
{
	in[j] = 0x10;
}

  printf("xtx CBC encrypt: \n");
  AES128_CBC_encrypt_buffer(buffer+0, in+0,  32, key, iv);
  phex(buffer);
  //AES128_CBC_decrypt_buffer(buffer+16, in+16, 16, 0, 0);
  phex(buffer+16);
  //AES128_CBC_decrypt_buffer(buffer+32, in+32, 16, 0, 0);
  //AES128_CBC_decrypt_buffer(buffer+48, in+48, 16, 0, 0);

  printf("xtx  CBC encrypt: \n");
  int i;
      for(i = 0; i < 4; ++i)
    {
        //AES128_CBC_decrypt_buffer(buffer + (i*16), in+(i*16), 16, key, iv);
        //phex(buffer + (i*16));
    }
    printf("\n");

  if(0 == strncmp((char*) out, (char*) buffer, 64))
  {
    printf("SUCCESS!\n");
  }
  else
  {
    printf("FAILURE!\n");
  }
}
コード例 #9
0
bool TCPConnection::write(uint8_t *buf, int len) {
	if (stopped) {
		return false;
	}

	assert(buf);
	assert(len > 0);

	boost::shared_array<uint8_t> bufCpy(new uint8_t[len]);

	memcpy(bufCpy.get(), buf, len);
	pendingWrites.increment();
	beetle.writers.schedule(getId(), [this, bufCpy, len] {
		uint8_t bufLen = len;
		if (SSL_write_all(ssl, &bufLen, 1) != 1 || SSL_write_all(ssl, bufCpy.get(), len) != len) {
			if (debug_socket) {
				std::stringstream ss;
				ss << "socket write failed : " << strerror(errno);
				pdebug(ss.str());
			}
			stopInternal();
		} else {
			if (debug_socket) {
				pdebug("wrote " + std::to_string(len) + " bytes to " + getName());
				phex(bufCpy.get(), len);
			}
		}
		pendingWrites.decrement();
	});
	return true;
}
コード例 #10
0
ファイル: matrix.c プロジェクト: 0xdec/qmk_firmware
void matrix_print(void) {
  print("\nr/c 0123456789ABCDEF\n");
  for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
    phex(row); print(": ");
    pbin_reverse16(matrix_get_row(row));
    print("\n");
  }
}
コード例 #11
0
ファイル: matrix.c プロジェクト: Flight310/tmk_keyboard
void matrix_print(void)
{
    print("\nr/c 01234567\n");
    for (uint8_t row = 0; row < matrix_rows(); row++) {
        phex(row); print(": ");
        pbin_reverse(matrix_get_row(row));
        print("\n");
    }
}
コード例 #12
0
void matrix_print(void) {
  print_matrix_header();

  for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
    phex(row); print(": ");
    print_matrix_row(row);
    print("\n");
  }
}
コード例 #13
0
ファイル: m0110.c プロジェクト: mihow/tmk_keyboard
void m0110_init(void)
{
    uint8_t data;
    idle();
    _delay_ms(1000);

    // Model Number
    // M0110 : 0x09  00001001 : model number 4 (100)
    // M0110A: 0x0B  00001011 : model number 5 (101)
    // M0110 & M0120: ???
    m0110_send(M0110_MODEL);
    data = m0110_recv();
    print("m0110_init model: "); phex(data); print("\n");

    m0110_send(M0110_TEST);
    data = m0110_recv();
    print("m0110_init test: "); phex(data); print("\n");
}
コード例 #14
0
ファイル: ps2.c プロジェクト: WonjoonLee/tmk_keyboard
/* get data received by interrupt */
uint8_t ps2_host_recv(void)
{
    if (ps2_error) {
        print("x");
        phex(ps2_error);
        ps2_host_send(0xFE);    // request to resend
        ps2_error = PS2_ERR_NONE;
    }
    idle();
    return pbuf_dequeue();
}
コード例 #15
0
ファイル: mousekey.c プロジェクト: mikelduffy/qmk_firmware
static void mousekey_debug(void)
{
    if (!debug_mouse) return;
    print("mousekey [btn|x y v h](rep/acl): [");
    phex(mouse_report.buttons); print("|");
    print_decs(mouse_report.x); print(" ");
    print_decs(mouse_report.y); print(" ");
    print_decs(mouse_report.v); print(" ");
    print_decs(mouse_report.h); print("](");
    print_dec(mousekey_repeat); print("/");
    print_dec(mousekey_accel); print(")\n");
}
コード例 #16
0
ファイル: matrix.c プロジェクト: mtl/tmk_keyboard
void matrix_print() {

    print( "\nr/c 0123456789ABCDEFGHI\n" );

    for ( uint8_t row = 0; row < MATRIX_ROWS; row++ ) {

        phex( row );
        print( ": " );
        xprintf( "%019lb", bitrev32( matrix_get_row( row ) ) >> 13 );
        print( "\n" );
    }
}
コード例 #17
0
ファイル: test.c プロジェクト: xutianxi/hls_segmenter_aes
static void test_encrypt_ecb_verbose(void)
{
    // Example of more verbose verification

    uint8_t i, buf[64], buf2[64];

    // 128bit key
    uint8_t key[16] =        { (uint8_t) 0x2b, (uint8_t) 0x7e, (uint8_t) 0x15, (uint8_t) 0x16, (uint8_t) 0x28, (uint8_t) 0xae, (uint8_t) 0xd2, (uint8_t) 0xa6, (uint8_t) 0xab, (uint8_t) 0xf7, (uint8_t) 0x15, (uint8_t) 0x88, (uint8_t) 0x09, (uint8_t) 0xcf, (uint8_t) 0x4f, (uint8_t) 0x3c };
    // 512bit text
    uint8_t plain_text[64] = { (uint8_t) 0x6b, (uint8_t) 0xc1, (uint8_t) 0xbe, (uint8_t) 0xe2, (uint8_t) 0x2e, (uint8_t) 0x40, (uint8_t) 0x9f, (uint8_t) 0x96, (uint8_t) 0xe9, (uint8_t) 0x3d, (uint8_t) 0x7e, (uint8_t) 0x11, (uint8_t) 0x73, (uint8_t) 0x93, (uint8_t) 0x17, (uint8_t) 0x2a,
                               (uint8_t) 0xae, (uint8_t) 0x2d, (uint8_t) 0x8a, (uint8_t) 0x57, (uint8_t) 0x1e, (uint8_t) 0x03, (uint8_t) 0xac, (uint8_t) 0x9c, (uint8_t) 0x9e, (uint8_t) 0xb7, (uint8_t) 0x6f, (uint8_t) 0xac, (uint8_t) 0x45, (uint8_t) 0xaf, (uint8_t) 0x8e, (uint8_t) 0x51,
                               (uint8_t) 0x30, (uint8_t) 0xc8, (uint8_t) 0x1c, (uint8_t) 0x46, (uint8_t) 0xa3, (uint8_t) 0x5c, (uint8_t) 0xe4, (uint8_t) 0x11, (uint8_t) 0xe5, (uint8_t) 0xfb, (uint8_t) 0xc1, (uint8_t) 0x19, (uint8_t) 0x1a, (uint8_t) 0x0a, (uint8_t) 0x52, (uint8_t) 0xef,
                               (uint8_t) 0xf6, (uint8_t) 0x9f, (uint8_t) 0x24, (uint8_t) 0x45, (uint8_t) 0xdf, (uint8_t) 0x4f, (uint8_t) 0x9b, (uint8_t) 0x17, (uint8_t) 0xad, (uint8_t) 0x2b, (uint8_t) 0x41, (uint8_t) 0x7b, (uint8_t) 0xe6, (uint8_t) 0x6c, (uint8_t) 0x37, (uint8_t) 0x10 };

    memset(buf, 0, 64);
    memset(buf2, 0, 64);

    // print text to encrypt, key and IV
    printf("ECB encrypt verbose:\n\n");
    printf("plain text:\n");
    for(i = (uint8_t) 0; i < (uint8_t) 4; ++i)
    {
        phex(plain_text + i * (uint8_t) 16);
    }
    printf("\n");

    printf("key:\n");
    phex(key);
    printf("\n");

    // print the resulting cipher as 4 x 16 byte strings
    printf("ciphertext:\n");
    for(i = 0; i < 4; ++i)
    {
        AES128_ECB_encrypt(plain_text + (i*16), key, buf+(i*16));
        phex(buf + (i*16));
    }
    printf("\n");
}
コード例 #18
0
ファイル: tuner.c プロジェクト: eframp/p600fw
static LOWERCODESIZE void tuneCV(p600CV_t oscCV, p600CV_t ampCV)
{
#ifdef DEBUG		
	print("\ntuning ");phex(oscCV);print("\n");
#endif
	int8_t isOsc,i;
	
	// init
	
	tuner.currentCV=oscCV;
	isOsc=(oscCV<pcFil1);

	// open VCA

	sh_setCV(ampCV,UINT16_MAX,0);
	
	// tune

	if (isOsc)
	{
		for(i=TUNER_OSC_NTH_C_LO;i<=TUNER_OSC_NTH_C_HI;++i)
			if (tuneOffset(oscCV,i,12*(TUNER_OSC_NTH_C_LO-2),TUNER_OSC_PRECISION))
				break;

		// extrapolate for octaves that aren't directly tunable
		
		for(i=TUNER_OSC_NTH_C_LO-1;i>=0;--i)
			settings.tunes[i][oscCV]=(uint32_t)2*settings.tunes[i+1][oscCV]-settings.tunes[i+2][oscCV];

		for(i=TUNER_OSC_NTH_C_HI+1;i<TUNER_OCTAVE_COUNT;++i)
			settings.tunes[i][oscCV]=(uint32_t)2*settings.tunes[i-1][oscCV]-settings.tunes[i-2][oscCV];
	}
	else
	{
		for(i=TUNER_FIL_NTH_C_LO;i<=TUNER_FIL_NTH_C_HI;++i)
			if (tuneOffset(oscCV,i,12*(TUNER_FIL_NTH_C_LO-1),TUNER_FIL_PRECISION))
				break;

		for(i=TUNER_FIL_NTH_C_LO-1;i>=0;--i)
			settings.tunes[i][oscCV]=(uint32_t)2*settings.tunes[i+1][oscCV]-settings.tunes[i+2][oscCV];

		for(i=TUNER_FIL_NTH_C_HI+1;i<TUNER_OCTAVE_COUNT;++i)
			settings.tunes[i][oscCV]=(uint32_t)2*settings.tunes[i-1][oscCV]-settings.tunes[i-2][oscCV];
	}
	
	// close VCA

	sh_setCV(ampCV,0,0);
	sh_update();
}
コード例 #19
0
ファイル: vusb.c プロジェクト: 82times/qmk_firmware
/* transfer keyboard report from buffer */
void vusb_transfer_keyboard(void)
{
    if (usbInterruptIsReady()) {
        if (kbuf_head != kbuf_tail) {
            usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t));
            kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE;
            if (debug_keyboard) {
                print("V-USB: kbuf["); pdec(kbuf_tail); print("->"); pdec(kbuf_head); print("](");
                phex((kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail));
                print(")\n");
            }
        }
    }
}
コード例 #20
0
ファイル: flash_pmc29f002.c プロジェクト: amuntner/rx5usb
char flash_checkId(void)
{
	unsigned char mfg,dev;
	
	flash_command(0x90);
	
	SET_ADDR(0);
	
	mfg=flash_getData();
	print("mfg ");
	phex(mfg);
	print(" dev ");

	SET_ADDR(1);

	dev=flash_getData();
	phex(dev);
	print("\n");

	flash_command(0xf0);
	
	return (mfg==0x9d) && (dev==0x1d || dev==0x2d);
}
コード例 #21
0
ファイル: matrix.c プロジェクト: bgould/tmk_keyboard
void matrix_print(void)
{
    print("\nr/c 01234567\n");
    for (uint8_t row = 0; row < matrix_rows(); row++) {
        phex(row); print(": ");
        pbin_reverse(matrix_get_row(row));
#ifdef MATRIX_HAS_GHOST
        if (matrix_has_ghost_in_row(row)) {
            print(" <ghost");
        }
#endif
        print("\n");
    }
}
コード例 #22
0
ファイル: hd-idle.c プロジェクト: Duckbox-Developers/apps
/* spin-down a disk */
static void spindown_disk(const char *name)
{
	struct sg_io_hdr io_hdr;
	unsigned char sense_buf[255];
	char dev_name[100];
	int fd;

	dprintf("spindown: %s\n", name);

	/* fabricate SCSI IO request */
	memset(&io_hdr, 0x00, sizeof(io_hdr));
	io_hdr.interface_id = 'S';
	io_hdr.dxfer_direction = SG_DXFER_NONE;

	/* SCSI stop unit command */
	io_hdr.cmdp = (unsigned char *) "\x1b\x00\x00\x00\x00\x00";

	io_hdr.cmd_len = 6;
	io_hdr.sbp = sense_buf;
	io_hdr.mx_sb_len = (unsigned char) sizeof(sense_buf);

	/* open disk device (kernel 2.4 will probably need "sg" names here) */
	snprintf(dev_name, sizeof(dev_name), "/dev/%s", name);
	if ((fd = open(dev_name, O_RDONLY)) < 0)
	{
		perror(dev_name);
		return;
	}

	/* execute SCSI request */
	if (ioctl(fd, SG_IO, &io_hdr) < 0)
	{
		char buf[100];
		snprintf(buf, sizeof(buf), "ioctl on %s:", name);
		perror(buf);

	}
	else if (io_hdr.masked_status != 0)
	{
		fprintf(stderr, "error: SCSI command failed with status 0x%02x\n",
			io_hdr.masked_status);
		if (io_hdr.masked_status == CHECK_CONDITION)
		{
			phex(sense_buf, io_hdr.sb_len_wr, "sense buffer:\n");
		}
	}

	close(fd);
}
コード例 #23
0
void move_mouse(void) {

    /* don't move the mouse unless we already took 2 readings */
    if (!initalized) {
        initalized = 1;
    } else {
        // ignore least significant bit, as it's probably noise
        currentX = currentX >> 1; 
        currentY = currentY >> 1;

        deltaX = previousX - currentX;
        deltaY = previousY - currentY;
    
        if (((deltaX < THRESHOLD) &&  (deltaX > -THRESHOLD))
            && (deltaY < THRESHOLD && (deltaY > -THRESHOLD))) {
        
#ifdef DEBUG
            if (deltaX != 0 || deltaY != 0) {
              print("x="); phex(deltaX); print("\t");
              print("y="); phex(deltaY); print("\n");
            }
#endif
            usb_mouse_move(deltaX, deltaY, 0);
            currButtonState = PIND & 0x01;  // Care about D0 only
            // button pressed
            if (!currButtonState) {
                usb_mouse_buttons(1, 0, 0);
            } else { // released
                usb_mouse_buttons(0, 0, 0);
            }
        }
    }
            
    previousX = currentX;
    previousY = currentY;
}
コード例 #24
0
int main() {
	int port_num = 0;
    printf("plz enter the COM Port number:\n");
    scanf("%d",&port_num);
	ComPort cp = newComPort(port_num);

	void* context = zmq_ctx_new();
	ZMQServer zmq_server = newZMQServer(context, "tcp://*:5555", ZMQ_REP);
	ZMQServer zmq_publisher = newZMQServer(context, "tcp://*:5556", ZMQ_PUB);
	
    char buf[BUFFER_SIZE];
	int len;
	while(1){
		char port_cmd[32];
		len = read(zmq_server, buf);
		if (!strcmp("lights on", buf + 9)) {
			write(cp, "\xAA", 1, buf);
		} else if (!strcmp("lights off", buf + 9)) {
			write(cp, "\xBB", 1, buf);
		}

		len = read(cp, buf);
		phex(buf, len);
		char light_ack[32];
		if (!strncmp("\xAB\xCD", buf, 2)) {
			memcpy(light_ack, buf + 2, 8);
			memcpy(light_ack + 8, " lights on OK", 13);
			printf("light_ack = %s\n", light_ack);
			write(zmq_server, light_ack, 21);
		} else if (!strncmp("\xCD\xEF", buf, 2)) {
			memcpy(light_ack, buf + 2, 8);
			memcpy(light_ack + 8, " lights off OK", 14);
			printf("light_ack = %s\n", light_ack);
			write(zmq_server, light_ack, 22);
		} else if (!strncmp("\x00\x00", buf, 2)) {
			memcpy(light_ack, buf + 2, 8);
			memcpy(light_ack + 8, " lights error", 13);
			printf("light_ack = %s\n", light_ack);
			write(zmq_server, light_ack, 21);
		} else {
			write(zmq_publisher, (char*)buf, len);
		}
	}
}
コード例 #25
0
ファイル: m0110.c プロジェクト: mihow/tmk_keyboard
uint8_t m0110_recv(void)
{
    uint8_t data = 0;
    m0110_error = 0;

    WAIT_MS(clock_lo, 250, 1);  // keyboard may block long time
    for (uint8_t i = 0; i < 8; i++) {
        data <<= 1;
        WAIT_US(clock_lo, 200, 2);
        WAIT_US(clock_hi, 200, 3);
        if (data_in()) {
            data |= 1;
        }
    }
    idle();
    return data;
ERROR:
    print("m0110_recv err: "); phex(m0110_error); print("\n");
    _delay_ms(500);
    idle();
    return 0xFF;
}
コード例 #26
0
ファイル: matrix.c プロジェクト: Pyrolistical/tmk_keyboard
uint8_t matrix_scan(void)
{
    uint8_t key;

    is_modified = false;
    key = m0110_recv_key();

#ifdef MATRIX_HAS_LOCKING_CAPS
    // Send Caps key up event
    if (matrix_is_on(ROW(CAPS), COL(CAPS))) {
        is_modified = true;
        register_key(CAPS_UP);
    }
#endif
    if (key == M0110_NULL) {
        return 0;
    } else {
#ifdef MATRIX_HAS_LOCKING_CAPS    
        if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) {
            // CAPS LOCK on:
            // Ignore LockingCaps key down event
            if (key == CAPS) return 0;
            // Convert LockingCaps key up event into down event
            if (key == CAPS_UP) key = CAPS;
        } else {
            // CAPS LOCK off:
            // Ignore LockingCaps key up event
            if (key == CAPS_UP) return 0;
        }
#endif        
        is_modified = true;
        register_key(key);
    }

    if (debug_enable) {
        print("key: "); phex(key); print("\n");
    }
    return 1;
}
コード例 #27
0
ファイル: matrix.c プロジェクト: doxkb/tmk_keyboard
void matrix_print(void)
{
#if (MATRIX_COLS <= 8)
    print("\nr/c 01234567\n");
#else
    print("\nr/c 0123456789ABCDEF\n");
#endif
    for (uint8_t row = 0; row < matrix_rows(); row++) {
        phex(row); print(": ");
#if (MATRIX_COLS <= 8)
        pbin_reverse(matrix_get_row(row));
#else
        pbin_reverse16(matrix_get_row(row));
#endif
#ifdef MATRIX_HAS_GHOST
        if (matrix_has_ghost_in_row(row)) {
            print(" <ghost");
        }
#endif
        print("\n");
    }
}
コード例 #28
0
ファイル: m0110.c プロジェクト: mihow/tmk_keyboard
uint8_t m0110_send(uint8_t data)
{
    m0110_error = 0;

    request();
    WAIT_MS(clock_lo, 250, 1);  // keyboard may block long time
    for (uint8_t bit = 0x80; bit; bit >>= 1) {
        WAIT_US(clock_lo, 250, 3);
        if (data&bit) {
            data_hi();
        } else {
            data_lo();
        }
        WAIT_US(clock_hi, 200, 4);
    }
    _delay_us(100); // hold last bit for 80us
    idle();
    return 1;
ERROR:
    print("m0110_send err: "); phex(m0110_error); print("\n");
    _delay_ms(500);
    idle();
    return 0;
}
コード例 #29
0
void TCPConnection::startInternal() {
	beetle.readers.add(sockfd, [this] {
		if (stopped) {
			return;
		}

		uint8_t buf[256];
		uint8_t len;

		// read length of ATT message
		int bytesRead = SSL_read(ssl, &len, sizeof(len));
		if (bytesRead <= 0) {
			if (debug_socket) {
				std::stringstream ss;
				ss << "socket errno: " << strerror(errno);
				pdebug(ss.str());
			}
			stopInternal();
		} else {
			assert(bytesRead == 1);
			if (debug_socket) {
				pdebug("tcp expecting " + std::to_string(len) + " bytes");
			}

			time_t startTime = time(NULL);

			struct timeval defaultTimeout;
			defaultTimeout.tv_sec = 0;
			defaultTimeout.tv_usec = 100000;

			fd_set fdSet;
			FD_ZERO(&fdSet);
			FD_SET(sockfd, &fdSet);

			// read payload ATT message
			bytesRead = 0;
			while (!stopped && bytesRead < len) {
				if (difftime(time(NULL), startTime) > TIMEOUT_PAYLOAD) {
					if (debug_socket) {
						pdebug("timed out reading payload");
					}
					stopInternal();
					break;
				}

				int result = SSL_pending(ssl);

				if (result <= 0) {
					struct timeval timeout = defaultTimeout;
					fd_set readFds = fdSet;
					fd_set exceptFds = fdSet;
					result = select(sockfd + 1, &readFds, NULL, &exceptFds, &timeout);
					if (result < 0) {
						if (debug_socket) {
							std::stringstream ss;
							ss << "select failed : " << strerror(errno);
							pdebug(ss.str());
						}
						stopInternal();
						break;
					}
				}

				if (result > 0) {
					int n = SSL_read(ssl, buf + bytesRead, len - bytesRead);
					if (n < 0) {
						if (debug_socket) {
							std::cerr << "socket errno: " << strerror(errno) << std::endl;
						}
						stopInternal();
						break;
					} else {
						bytesRead += n;
					}
				}
			}

			if (bytesRead < len) {
				return;
			}

			if (debug_socket) {
				phex(buf, bytesRead);
				pdebug("read " + std::to_string(bytesRead) + " bytes from " + getName());
			}

			readHandler(buf, bytesRead);
		}
	});
}
コード例 #30
0
 //Key Execute function
 //Decodes a keycode, and executes depending on codetype
 void key_execute(keycode aKey, uint8_t down)
 {
	print("inside key_execute\n");
	phex(aKey.type);
	print("<-Type:Code->");
	phex(aKey.code);
	print("\n");
	switch(aKey.type)
	{
		case TYPE_KEY:
			//Check for type, and call functions
			if(down)
				add_key(aKey.code);
			else
				del_key(aKey.code);
		break;
		case TYPE_MOD:
			//Check for type, and call functions
			if(down)
				add_mod(aKey.code);
			else
				del_mod(aKey.code);
		break;
		case TYPE_MEDIA:
		case TYPE_MOUSE:
			//Placeholder if mouse and media keys implemented
		break;
		case TYPE_MOMENTARY:
			//For mementary layer changes
			clear_keyboard(); //Clear all current plessed keys, because they may not exist in new layer
			if(down)
				set_current_layer(aKey.code);
			else
				set_current_layer(0); //Return to default layer
		break;
		case TYPE_TOGGLE:
			//For toggleing layer changes
			if(down && (aKey.code ^ get_current_layer()) )
			{
				clear_keyboard();
				set_current_layer(aKey.code);
			}
		break;
		case TYPE_MISC:
			//Miscelaneous functions need special treatment
			switch(aKey.code)
			{
				case CODE_JMP_BOOT:
					//Jump to boot loader
					if(down) //Only want to activate on key-down
					{
						jump_bootloader();
					}
					break;
				case CODE_BR_UP:
					//Raise brightness of LEDS
					//In steps of 24
					if(down) //Only want to activate on key-down
					{
						if(OCR4D < 0xF0) OCR4D += 0x20;
					}
					break;
				case CODE_BR_DOWN:
					//Lower brightness of LEDS
					//In steps of 24
					if(down) //Only want to activate on key-down
					{
						if(OCR4D > 0x10) OCR4D -= 0x20;
					}
					break;
			}
			break;
		default:
			//Default case: Unknown Keytype
			//Print error and do nothing
			print("Unknown Key Type: ");
			phex(aKey.type);
			pchar('\n');
	}
 }