Ejemplo n.º 1
0
void PMDialPad::adcDone() {
	if (status == CONVERT) {
		uint16_t res = anaIn.read_result_u16();
		keys[keymap(res)]++;
		// do SIMPLEKEYBOARD_NB_CONVERT_RUN runs, than lower the sampling freq
		if (convert_run++ >= SIMPLEKEYBOARD_NB_CONVERT_RUN) {
			convert_run = 0;
			uint8_t maxVal = 0;
			enum Key maxIdx = KEY_NONE;
			for (int i = 0; i < KEY_LIST_LEN; ++i) {
				if (keys[i] > maxVal) {
					maxVal = keys[i]; maxIdx = static_cast<enum Key>(i); keys[i] = 0;
				}
			}
			// call appropriate callbacks if there was a change
			if (button != maxIdx) {
				if (released_cb && button < KEY_INVALID) {
					released_cb.call(button);
				}
				button = maxIdx;
				if (button != KEY_NONE) {
					if (pressed_cb) {
						pressed_cb.call(button);
					}
					// if hold_cb is set, start a timer
					if (hold_cb) {
						cancelCallbackSave(holdtime_evt_handle);
						holdtime_evt_handle = minar::Scheduler::postCallback(holdtime_evt).delay(minar::milliseconds(holdTime)).getHandle();
					}
				} else {
					// no button pressed, cancle callback if scheduled
					cancelCallbackSave(holdtime_evt_handle);
				}
			}
			// decide what to do next
			if (button == KEY_NONE) {
				interruptMode();
				status = IDLE;
			} else {
				status = MEASUREMENT;
				minar::Scheduler::postCallback(timeout_evt).tolerance(minar::milliseconds(CB_TOLERANCE_MS)).delay(minar::milliseconds(RECHECK_TIME_MS));
			}
		} else {
			status = MEASUREMENT;
			minar::Scheduler::postCallback(timeout_evt).tolerance(minar::milliseconds(CB_TOLERANCE_MS)).delay(minar::milliseconds(DEBOUNCE_TIME_MS));
		}
	}
}
Ejemplo n.º 2
0
PMDialPad::PMDialPad(PinName button, PinName scale) :
		button(KEY_NONE),
		holdTime(BUTTON_HOLD_TIME_MS),
		anaIn(button),
		intIn(button),
		scaleOut(scale),
		status(IDLE),
		convert_run(0),
		timeout_evt(mbed::util::FunctionPointer0<void>(this, &PMDialPad::timeout).bind()),
		adc_evt(mbed::util::FunctionPointer0<void>(this, &PMDialPad::adcDone).bind()),
		holdtime_evt(mbed::util::FunctionPointer0<void>(this, &PMDialPad::holdTimeout).bind()),
		holdtime_evt_handle(0),
		pressed_cb(0),
		released_cb(0),
		hold_cb(0)
{
	anaIn.config(ADC_CONFIG_RES_10bit, ADC_CONFIG_INPSEL_AnalogInputTwoThirdsPrescaling,
			ADC_CONFIG_REFSEL_SupplyOneHalfPrescaling, ADC_CONFIG_EXTREFSEL_None);
	anaIn.interrupt(this, &PMDialPad::adcInterrupt);
	anaIn.disable();
	intIn.input();
	intIn.fall(this, &PMDialPad::buttonPress);
	interruptMode();
}
Ejemplo n.º 3
0
void interruptMode(uint8_t pin, uint8_t mode)
{
	GPIO_INT_TYPE type = ConvertArduinoInterruptMode(mode);
	interruptMode(pin, type);
}