示例#1
0
/***********************************************************
Return :  The column(s) affected are the 0 bits.
ie.  0xEF  means a button on SW4 column is pushed.
ie.  0x7F  means a button on SW4 & SW3 columns are pushed.
***********************************************************/
void wait_for_press()
{
	byte change;

	set_rows_output();
	all_rows_low();				// will show a press
	set_switches_input();		// switches are pulled high unless button is pushed

	// If there are no glitches _slower_ than 5ms.  This will work.

	// repeat until first sign of change:
	do {
		do { 
			scan_keys(keys);
			change = check_for_change(prev_keys, keys); 
		} while (change==0);

		// slight delay ~5ms
		delay(5);		// adjust time for 5ms!

		/* Reread : 
			if still different from previous, 
				then real debounce event
			if return to previous,
				then ignore the event		*/
			scan_keys( keys2 );
			change = check_for_change( prev_keys, keys2 );
	} while	( change==0 );

	// Real event!
	update_prev_keys();
}
示例#2
0
int redis_hash::hscan(const char* key, int cursor, std::map<string, string>& out,
	  const char* pattern /* = NULL */, const size_t* count /* = NULL */)
{
	if (key == NULL || *key == 0 || cursor < 0)
		return -1;

	size_t size;
	const redis_result** children = scan_keys("HSCAN", key, cursor,
		size, pattern, count);
	if (children == NULL)
		return cursor;

	if (size % 2 != 0)
		return -1;

	const redis_result* rr;
	string name(128), value(128);
	// out.clear();

	for (size_t i = 0; i < size;)
	{
		rr = children[i];
		rr->argv_to_string(name);
		i++;

		rr = children[i];
		rr->argv_to_string(value);
		i++;

		out[name] = value;
	}

	return cursor;
}
示例#3
0
int redis_key::scan(int cursor, std::vector<string>& out,
	const char* pattern /* = NULL */, const size_t* count /* = NULL */)
{
	if (cursor < 0)
		return -1;

	size_t size;
	const redis_result** children = scan_keys("SCAN", NULL, cursor,
		size, pattern, count);
	if (children == NULL)
		return cursor;

	const redis_result* rr;
	string key_buf(128);

	// out.clear();
	out.reserve(out.size() + size);

	for (size_t i = 0; i < size; i++)
	{
		rr = children[i];
		rr->argv_to_string(key_buf);
		out.push_back(key_buf);
		key_buf.clear();
	}

	return cursor;
}
示例#4
0
static int build_codes(const input_port_entry *input_ports, struct InputCode *codes, int map_lowercase)
{
	UINT32 ports[NUM_SIMUL_KEYS];
	const input_port_entry *ipts[NUM_SIMUL_KEYS];
	int switch_upper, rc = 0;
	unicode_char_t c;

	/* first clear the buffer */
	memset(codes, 0, CODE_BUFFER_SIZE);

	if (!scan_keys(input_ports, codes, ports, ipts, 0, 0))
		goto done;

	if (map_lowercase)
	{
		/* special case; scan to see if upper case characters are specified, but not lower case */
		switch_upper = 1;
		for (c = 'A'; c <= 'Z'; c++)
		{
			if (!inputx_can_post_key(c) || inputx_can_post_key(unicode_tolower(c)))
			{
				switch_upper = 0;
				break;
			}
		}

		if (switch_upper)
			memcpy(&codes['a'], &codes['A'], sizeof(codes[0]) * 26);
	}

	rc = 1;

done:
	return rc;
}
示例#5
0
void buttons_init()
{
	for (int i=0; i<NUM_ROWS; i++)
		prev_keys[i] = 0xFF;		// assume all up.
	set_rows_output();
	//all_rows_low();
	set_switches_input();
	scan_keys(keys);
	update_prev_keys();
}
示例#6
0
static int scan_keys(const input_port_entry *input_ports, struct InputCode *codes, UINT32 *ports, const input_port_entry **shift_ports, int keys, int shift)
{
	int result = 0;
	const input_port_entry *ipt;
	const input_port_entry *ipt_key = NULL;
	UINT32 port = (UINT32) -1;
	unicode_char_t code;

	assert(keys < NUM_SIMUL_KEYS);

	ipt = input_ports;
	while(ipt->type != IPT_END)
	{
		switch(ipt->type) {
		case IPT_KEYBOARD:
			ipt_key = ipt;

			code = ipt->keyboard.chars[shift];
			if (code)
			{
				/* mark that we have found some natural keyboard codes */
				result = 1;

				/* is this a shifter key? */
				if ((code >= UCHAR_SHIFT_BEGIN) && (code <= UCHAR_SHIFT_END))
				{
					ports[keys] = port;
					shift_ports[keys] = ipt_key;
					scan_keys(input_ports, codes, ports, shift_ports, keys+1, code - UCHAR_SHIFT_1 + 1);
				}
				else if (code < NUM_CODES)
				{
					memcpy(codes[code].port, ports, sizeof(ports[0]) * keys);
					memcpy((void *) codes[code].ipt, shift_ports, sizeof(shift_ports[0]) * keys);
					codes[code].port[keys] = port;
					codes[code].ipt[keys] = ipt_key;

					if (LOG_INPUTX)
						logerror("inputx: code=%i (%s) port=%i ipt->name='%s'\n", (int) code, charstr(code), port, ipt->name);
				}
			}
			break;

		case IPT_PORT:
			port++;
			/* fall through */

		default:
			ipt_key = NULL;
			break;
		}
		ipt++;
	}
	return result;
}
示例#7
0
int main() {
  init();
  //blink(1);
  while(1) {
    //DEBUG("\r\n");
    clear_keys();
    //debounce(DEBOUNCE_PASSES);
    scan_keys();
    cool_down_inactive_layers();
    pre_invoke_functions();
    calculate_presses();
    //b();
    //clear_screen();
    //debug_state();
    //debug_layers();
    usb_keyboard_send();
  };
};
示例#8
0
int redis_zset::zscan(const char* key, int cursor,
	std::vector<std::pair<string, double> >& out,
	const char* pattern /* = NULL */, const size_t* count /* = NULL */)
{
	if (key == NULL || *key == 0 || cursor < 0)
		return -1;

	size_t size;
	const redis_result** children = scan_keys("ZSCAN", key, cursor,
		size, pattern, count);
	if (children == NULL)
		return cursor;

	if (size % 2 != 0)
		return -1;

	out.reserve(out.size() + size);

	const redis_result* rr;
	string name(128), value(128);

	for (size_t i = 0; i < size;)
	{
		rr = children[i];
		rr->argv_to_string(name);
		i++;

		rr = children[i];
		rr->argv_to_string(value);
		i++;

		out.push_back(std::make_pair(name, atof(value.c_str())));
	}

	return cursor;
}
示例#9
0
static void kp_work(struct kp *kp)
{
	int i, code;
	kp_search_key(kp);

	//add for adc keys(channel 4)
	//start, select
	i = 4;
	code = kp->key_code[i];
	if ((!code) && (!kp->cur_keycode[i])) {
		;
	} else if (code != kp->tmp_code[i]) {
		kp->tmp_code[i] = code;
		kp->count[i] = 0;
	} else if(++kp->count[i] == 2) {
		if (kp->cur_keycode[i] != code) {
			if (!code) {
				kp->cur_keycode_status[i] = 0;
				//printk("key %d up\n", kp->cur_keycode[i]);
				input_report_key(kp->input, kp->cur_keycode[i], 0);
				kp->cur_keycode[i] = code;
			} else if (kp->cur_keycode_status[i] == 1) {
				//printk("--------------------------- error cur = %d  new code = %d -------------------------\n", kp->cur_keycode[i], code);
				//printk("key %d up(force)\n", kp->cur_keycode[i]);
				input_report_key(kp->input, kp->cur_keycode[i], 0);
				kp->cur_keycode_status[i] = 0;
				kp->count[i] = 0;
			} else {
				kp->cur_keycode_status[i] = 1;
				//printk("key %d down\n", code);
				input_report_key(kp->input, code, 1);
				kp->cur_keycode[i] = code;
			}
		}
	}
	//end

	if (key_param[0]) {
		//circle 0
		if ((kp->key_valid[2] == 1) || (kp->key_valid[3] == 1)) {
			kp->circle_flag[0] = 1;
			if(second0 < CENTER_TRY) {
				if(second0 == 0)
					key_report(kp, key_param[1], key_param[2], 0);
				if(second0 == 1)
					key_report(kp, key_param[1] + 1, key_param[2], 0);
				if(second0 == 2)
					key_report(kp, key_param[1], key_param[2] + 1, 0);
				if(second0 == 3)
					key_report(kp, key_param[1] - 1, key_param[2], 0);
				if(second0 == 4)
					key_report(kp, key_param[1], key_param[2] - 1, 0);
				second0++;
			} else {
				key_report(kp, key_param[1] +  (kp->key_value[2] - 512) * key_param[3] / 512, 
						key_param[2] +  (kp->key_value[3] - 512) * key_param[3] / 512, 0);
			}
		} else if (kp->circle_flag[0] == 1) {
			kp->circle_flag[0] = 0;
			second0 = 0;
		}

		scan_keys(kp);
		input_sync(kp->input);

		if (release && (kp->circle_flag[0] == 0) \
			&& kp->flaga && kp->flagb && kp->flagx && kp->flagy && kp->flagl && kp->flagr) {
			release = 0;
			input_report_key(kp->input, BTN_TOUCH, 0);
			input_report_abs(kp->input, ABS_MT_TOUCH_MAJOR, 0);
			input_report_abs(kp->input, ABS_MT_WIDTH_MAJOR, 0);
			input_mt_sync(kp->input);
			input_sync(kp->input);
			//printk("-------------- release all point -----------------\n");
		}
	} else {
		//left,right,up,down
		for (i=2; i<kp->chan_num; i++) {
			code = kp->key_code[i];
			if (!code && !kp->cur_keycode[i]) {
				continue;
			} else if (code != kp->tmp_code[i]) {
				kp->tmp_code[i] = code;
				kp->count[i] = 0;
			} else if(++kp->count[i] == 2) {
				if (kp->cur_keycode[i] != code) {
					if (!code) {
						kp->cur_keycode_status[i] = 0;
						//printk("key %d up\n", kp->cur_keycode[i]);
						input_report_key(kp->input, kp->cur_keycode[i], 0);
						kp->cur_keycode[i] = code;
					} else if (kp->cur_keycode_status[i] == 1) {
						//printk("--------------------------- error cur = %d  new code = %d -------------------------\n", kp->cur_keycode[i], code);
						//printk("key %d up(force)\n", kp->cur_keycode[i]);
						input_report_key(kp->input, kp->cur_keycode[i], 0);
						kp->cur_keycode_status[i] = 0;
						kp->count[i] = 0;
					} else {
						kp->cur_keycode_status[i] = 1;
						//printk("key %d down\n", code);
						input_report_key(kp->input, code, 1);
						kp->cur_keycode[i] = code;
					}
				}
			}
		}
		scan_keys(kp);
		input_sync(kp->input);
	}
}
示例#10
0
int main() {
	unsigned long T_LED = 0L;  // time of last digit update
	unsigned long T_time = 0L; // timer
	int i = 00, j = 00;
	U8 beep_delay = 0;
	int show_time_delay = 0;
	U8 counter_enabled = 0;
	key_state = 0;
	work_hours = (work_hours_t*)EEPROM_START_ADDR;	

	keys_scan_buffer[0] = keys_scan_buffer[1] = keys_scan_buffer[2] = keys_scan_buffer[3] = 0;
	Global_time = 0L; // global time in ms
	ADC_value = 0; // value of last ADC measurement
	LED_delay = 1; // one digit emitting time

	// Configure clocking
	CLK_CKDIVR = 0; // F_HSI = 16MHz, f_CPU = 16MHz
	// Configure pins
	CFG_GCR |= 1; // disable SWIM
	LED_init();
	// Configure Timer1
	// prescaler = f_{in}/f_{tim1} - 1
	// set Timer1 to 1MHz: 1/1 - 1 = 15
	TIM1_PSCRH = 0;
	TIM1_PSCRL = 15; // LSB should be written last as it updates prescaler
	// auto-reload each 1ms: TIM_ARR = 1000 = 0x03E8
	TIM1_ARRH = 0x03;
	TIM1_ARRL = 0xE8;
	// interrupts: update
	TIM1_IER = TIM_IER_UIE;
	// auto-reload + interrupt on overflow + enable
	TIM1_CR1 = TIM_CR1_APRE | TIM_CR1_URS | TIM_CR1_CEN;
	// configure ADC
  BEEP_CSR = 0x1e; // Configure BEEP

	_asm("rim");    // enable interrupts
		
	display_int(i);
	
	show_next_digit(); // show zero
	
	// Loop
	do 
	{
		U8 *test = (U8*)0x4010;
		U8 result;		
		if(((unsigned int)(Global_time - T_time) > DIGIT_PER) || (T_time > Global_time)) // set next timer value
		{
			T_time = Global_time;
			if(i && counter_enabled == 2)
			{
				PA_ODR |= (1<<2); // Relay is on
				i--;
				if(!i)
				{
					counter_enabled = 0;					
				}
			}
			else
			{
				PA_ODR &= ~(1<<2); // Relay is off
			}
			if((i % 100) > 59)
			{
				i -= 40;
			}
			if(counter_enabled == 1)
			{
				if(j)
				{
					j--;
					if(!j)
				  {
						i++;
					}
					if((j % 100) > 59)
					{
						j -= 40;
					}
				}
				if(!j)
				{
					counter_enabled = 2;
					add_minutes_to_eeprom(i/100);
				}
		  }
			if(counter_enabled == 1)
			{
				display_int(-j);
			}
			else
			{
				display_int(i);
			}
			
			//if(i > 9999) i = -1200;
			// check ADC value to light up DPs proportionaly
		
			// values less than 206 == 0
		}
		if((U8)(Global_time - T_LED) > LED_delay)
		{
			T_LED = Global_time;
			show_next_digit();	
			if(beep_delay)
			{
				beep_delay--;
				if(!beep_delay)
				{
					BEEP_CSR = 0x1e; // Configure BEEP
				}
			}
			if(show_time_delay)
			{
			  show_time_delay--;
				if(!show_time_delay)
				{
					i = 0; // Stop show time
				}
				
			}
		}
		result = scan_keys();		
		
		if(result & KEY_0_PRESSED) // Start
		{
			if(counter_enabled == 1 && j < 859) // 859 - wait 3 sec from 1-st start press
			{
				BEEP_CSR = 0xbe;
				beep_delay = 200;
				counter_enabled = 2;
				add_minutes_to_eeprom(i/100);
				i++;
				j = 0;
			}
			if(!counter_enabled)
			{
				BEEP_CSR = 0xbe;
				beep_delay = 10;
				if(show_time_delay == 0 && i>0)
				{
					counter_enabled = 1;
					j = 901; // 6 minutes pre time 
				}
				else
				{
					// Show Time
					i = work_hours->minutes + (int)(work_hours->hours_L) * 100 + (int)(work_hours->hours_H) * 10000;
					show_time_delay = 2450;
				}
		  }
		}
		else 
		{			
			if(result && show_time_delay)
			{
				i = 0;
				show_time_delay = 0;
			}			
			if(!counter_enabled)
			{
				if(result & KEY_3_PRESSED)
				{
					i+=100;
					display_int(i);
					BEEP_CSR = 0xbe;
					beep_delay = 10;
				}
				if(result & KEY_2_PRESSED)
				{
					if(i >= 100)
					{
						i-=100;
						display_int(i);
					}
					BEEP_CSR = 0xbe;
					beep_delay = 10;
				}
			}
		}
		
		if(result & KEY_1_PRESSED) //Stop
		{
			counter_enabled = 0;
			j = i = 0;
			display_int(i);
			BEEP_CSR = 0xbe;
			beep_delay = 40;
			show_time_delay = 0;			
		}
		if((result & KEY_PRESSED) == KEY_PRESSED && Global_time < 1000)
		{
			BEEP_CSR = 0xbe;
			beep_delay = 40;		
			clear_eeprom();
		}
		
		
	} while(1);
}