summaryrefslogtreecommitdiff
path: root/fw/fe310/phone/phone.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310/phone/phone.c')
-rw-r--r--fw/fe310/phone/phone.c118
1 files changed, 76 insertions, 42 deletions
diff --git a/fw/fe310/phone/phone.c b/fw/fe310/phone/phone.c
index a8d5a86..ca877e4 100644
--- a/fw/fe310/phone/phone.c
+++ b/fw/fe310/phone/phone.c
@@ -39,41 +39,68 @@ static void handle_mic(unsigned char type) {
}
static void handle_cell_voice(unsigned char type, unsigned char *buffer, uint16_t len) {
+ int rv;
+
switch (type) {
case EOS_CELL_MTYPE_VOICE_RING: {
- app_status_set_msg("RING");
+ rv = EOS_OK;
+ if (len > EOS_CELL_MAX_DIAL_STR + 1) rv = EOS_ERR_SIZE;
+ if (rv) {
+ APP_LOG(APP_LOG_ERR, "RING ERROR:%d\n", rv);
+ break;
+ }
+
+ buffer[len + 1] = '\0';
APP_LOG(APP_LOG_DEBUG, "RING:%s\n", buffer+1);
- phone_state = PHONE_STATE_RING;
+ if ((phone_state == PHONE_STATE_IDLE) || (phone_state == PHONE_STATE_RING)) {
+ phone_state = PHONE_STATE_RING;
+ app_status_set_msg("RING");
+ }
+ break;
+ }
+
+ case EOS_CELL_MTYPE_VOICE_BUSY: {
+ APP_LOG(APP_LOG_DEBUG, "BUSY\n");
+ if (phone_state == PHONE_STATE_DIAL) {
+ phone_state = PHONE_STATE_IDLE;
+ app_status_set_msg("BUSY");
+ }
break;
}
case EOS_CELL_MTYPE_VOICE_MISS: {
- app_status_set_msg("MISS");
APP_LOG(APP_LOG_DEBUG, "MISS\n");
- phone_state = PHONE_STATE_IDLE;
+ if ((phone_state == PHONE_STATE_DIAL) || (phone_state == PHONE_STATE_RING)) {
+ phone_state = PHONE_STATE_IDLE;
+ app_status_set_msg("MISS");
+ }
break;
}
case EOS_CELL_MTYPE_VOICE_BEGIN: {
- app_status_set_msg("CALL BEGIN");
APP_LOG(APP_LOG_DEBUG, "CALL BEGIN\n");
- phone_state = PHONE_STATE_CIP;
- eos_net_acquire_for_evt(EOS_EVT_I2S | EOS_I2S_ETYPE_MIC, 1);
- eos_i2s_spk_init(spk_arr, ABUF_SIZE);
- eos_i2s_mic_init(mic_arr, ABUF_SIZE);
- eos_i2s_mic_set_wm(MIC_WM);
- eos_i2s_mic_set_handler(handle_mic);
- eos_i2s_mic_set_vol(4);
- eos_i2s_start(8000);
+ if ((phone_state == PHONE_STATE_DIAL) || (phone_state == PHONE_STATE_RING)) {
+ phone_state = PHONE_STATE_CIP;
+ app_status_set_msg("CALL BEGIN");
+ eos_net_acquire_for_evt(EOS_EVT_I2S | EOS_I2S_ETYPE_MIC, 1);
+ eos_i2s_spk_init(spk_arr, ABUF_SIZE);
+ eos_i2s_mic_init(mic_arr, ABUF_SIZE);
+ eos_i2s_mic_set_wm(MIC_WM);
+ eos_i2s_mic_set_handler(handle_mic);
+ eos_i2s_mic_set_vol(4);
+ eos_i2s_start(8000);
+ }
break;
}
case EOS_CELL_MTYPE_VOICE_END: {
- app_status_set_msg("HUP");
- APP_LOG(APP_LOG_DEBUG, "HUP\n");
- phone_state = PHONE_STATE_IDLE;
- eos_net_acquire_for_evt(EOS_EVT_I2S | EOS_I2S_ETYPE_MIC, 0);
- eos_i2s_stop();
+ APP_LOG(APP_LOG_DEBUG, "CALL END\n");
+ if (phone_state == PHONE_STATE_CIP) {
+ phone_state = PHONE_STATE_IDLE;
+ app_status_set_msg("CALL END");
+ eos_net_acquire_for_evt(EOS_EVT_I2S | EOS_I2S_ETYPE_MIC, 0);
+ eos_i2s_stop();
+ }
break;
}
@@ -107,6 +134,17 @@ static void widget_btn_draw(EVEFreeWidget *widget) {
eve_cmd_dl(END());
}
+static void call(char * num) {
+ int rv;
+
+ if (strlen(num)) {
+ phone_state = PHONE_STATE_DIAL;
+ app_status_set_msg("DIAL");
+ rv = eos_cell_voice_dial(num, NULL, 0);
+ if (rv) APP_LOG(APP_LOG_ERR, "DIAL ERR:%d\n", rv);
+ }
+}
+
static int widget_btn_touch(EVEFreeWidget *widget, EVETouch *touch, uint16_t evt) {
if (evt & EVE_TOUCH_ETYPE_TAG_UP) {
uint8_t tagi;
@@ -125,19 +163,19 @@ static int widget_btn_touch(EVEFreeWidget *widget, EVETouch *touch, uint16_t evt
case PHONE_STATE_IDLE: {
EVEPage *page = widget->w.page;
EVEStrWidget *strw = (EVEStrWidget *)eve_page_widget(page, 0);
- char *num = strw->str;
- if (strlen(num)) {
- app_status_set_msg("DIAL");
- rv = eos_cell_voice_dial(num, NULL, 0);
- if (rv) APP_LOG(APP_LOG_ERR, "DIAL ERR:%d\n", rv);
- }
+ call(strw->str);
break;
}
}
} else if (tagi == 1) {
- rv = eos_cell_voice_hangup(NULL, 0);
- if (rv) APP_LOG(APP_LOG_ERR, "HANGUP ERR:%d\n", rv);
+ if (phone_state != PHONE_STATE_IDLE) {
+ if (phone_state != PHONE_STATE_CIP) {
+ phone_state = PHONE_STATE_IDLE;
+ }
+ rv = eos_cell_voice_hangup(NULL, 0);
+ if (rv) APP_LOG(APP_LOG_ERR, "HANGUP ERR:%d\n", rv);
+ }
}
return 1;
}
@@ -145,13 +183,17 @@ static int widget_btn_touch(EVEFreeWidget *widget, EVETouch *touch, uint16_t evt
return 0;
}
+void phone_init(void) {
+ eos_cell_set_handler(EOS_CELL_MTYPE_VOICE, handle_cell_voice);
+}
+
int phone_app(EVEWindow *window, EVEViewStack *stack) {
EVEFormSpec spec[] = {
{
.label.title = "Phone:",
.widget.type = EVE_WIDGET_TYPE_STR,
- .widget.tspec.str.str_size = EOS_CELL_MAX_DIAL_STR,
+ .widget.tspec.str.str_size = EOS_CELL_MAX_DIAL_STR + 1,
},
APP_SPACERW(APP_SCREEN_W, 50),
{
@@ -164,7 +206,10 @@ int phone_app(EVEWindow *window, EVEViewStack *stack) {
};
EVEPage *page = eve_form_create(window, stack, spec, APP_SPEC_SIZE(spec), NULL, phone_close);
- if (page == NULL) return EVE_ERR_NOMEM;
+ if (page == NULL) {
+ APP_LOG(APP_LOG_ERR, "OUT OF MEMORY\n");
+ return EVE_ERR_NOMEM;
+ }
return EVE_OK;
}
@@ -176,17 +221,10 @@ int phone_uievt(EVEPage *page, uint16_t evt, void *param) {
case EVE_UIEVT_WIDGET_FOCUS_OUT: {
if (param == eve_page_widget(page, 0)) {
EVEStrWidget *strw = param;
- int rv;
- rv = eos_cell_voice_dial((char *)strw->str, NULL, 0);
- if (rv) {
- APP_LOG(APP_LOG_ERR, "DIAL ERR:%d\n", rv);
- return ret;
+ if (phone_state == PHONE_STATE_IDLE) {
+ call(strw->str);
}
- app_status_set_msg("DIAL");
- APP_LOG(APP_LOG_DEBUG, "DIAL:%s\n", strw->str);
- eos_cell_voice_dial(strw->str, NULL, 0);
- phone_state = PHONE_STATE_DIAL;
}
break;
}
@@ -204,10 +242,6 @@ void phone_close(EVEPage *page) {
eve_form_destroy(page);
}
-void phone_init(void) {
- eos_cell_set_handler(EOS_CELL_MTYPE_VOICE, handle_cell_voice);
-}
-
-unsigned char app_phone_state_get(void) {
+unsigned char phone_get_state(void) {
return phone_state;
}