void button_callback_timer_isr(button_t *button_table, uint8_t num_of_btns, void *dest_queue) { sampling_time_count = sampling_time_count + 1; if (sampling_time_count == BTN_SAMPLING_PERIOD) { sampling_time_count = 0; uint8_t i = 0; for (i = 0; i < num_of_btns; i++) { button_processing(&button_table[i]); if (is_changed_status(&button_table[i])) { if (!dest_queue || !(&button_table[i].enable_btn_evt) || !enable_all_btn_evts) { return; } _mqx_uint msg = (_mqx_uint) (((uint32_t) button_table[i].dev_id << BTN_NUM_BITS_IN_VALUE)| (uint16_t) get_button_status(&button_table[i])); _lwmsgq_send((pointer) dest_queue, &msg, 0); } else { if (button_table[i].current_status == btn_on_hold) { button_hold_processing(&button_table[i], dest_queue); } } } //end for() } //end if() }
static void button_hold_processing(button_t *a_button, void *dest_queue) { button_hold_time_count++; if (button_hold_time_count == BTN_HOLD_PERIOD) { button_hold_time_count = 0; a_button->old_status = btn_no_pressed; if (!dest_queue || !(a_button->enable_btn_evt) || !enable_all_btn_evts) { return; } _mqx_uint msg = (_mqx_uint) (((uint32_t) a_button->dev_id << BTN_NUM_BITS_IN_VALUE) | (uint16_t) get_button_status(a_button)); _lwmsgq_send((pointer) dest_queue, &msg, 0); } }
void loop() { uint8_t new_status; uint8_t tmp; uint8_t tmp_pitch_bit; // // the loop updates the sound parameters // // since we don't want all the parameters updated when playing, // some parameters are updated only on silence and on sustain, // and others are updated only on silence // // envelopes are updated only on silence and sustain if ((g_env_stage != 0) && (g_env_stage != 2)) { g_env_lengths[0] = analogRead(ATTACK_CTRL) * 16; g_env_lengths[1] = analogRead(RELEASE_CTRL) * 16; g_env_type = (digitalRead(LOWPASS_PIN) == LOW) ? 1 : ((digitalRead(FREQ_PIN) == LOW) ? 2 : 0); } // vibrato and resonance are always welcome tmp = (uint8_t)(analogRead(VIBRATO_CTRL) / 4); g_vib_strength = (tmp > 20) ? tmp : 0; tmp = analogRead(RESONANCE_CTRL) / 4; g_lpf_resonance = (tmp > 20) ? tmp : 0; // so are tremolo and distortion g_trem_status = digitalRead(TREM_PIN)==LOW ? 1 : 0; g_dist_status = digitalRead(DIST_PIN)==LOW ? 1 : 0; // // pitch buttons // new_status = get_button_status(); // is the current pitch released? if ((g_env_stage < 2) && ((g_current_pitch_bit & new_status) == 0)) { g_env_stage = 2; } // are all buttons released? if (new_status == 0) { g_current_pitch_bit = 0x00; } // or is a different pitch selected? else if (new_status != g_button_status) { tmp_pitch_bit = g_current_pitch_bit; // if a new button is pressed - select it if (new_status & (~g_button_status)) { tmp_pitch_bit = new_status & (~g_button_status); } // or if the current pitch is released - select another else if ((new_status & (~g_current_pitch_bit)) == 0) { tmp_pitch_bit = new_status; } // select only one pitch tmp_pitch_bit &= (~(tmp_pitch_bit-1)); // if it's really a different pitch, play it if (tmp_pitch_bit != g_current_pitch_bit) { g_current_pitch_bit = tmp_pitch_bit; // change the pitch with interrupts disabled cli(); g_base_freq = get_base_freq(g_current_pitch_bit); reset_sample(); g_env_stage = 0; sei(); } } g_button_status = new_status; }