Skip to content

Commit da9ef75

Browse files
committed
Call out I2C timeouts in errors
1 parent 94bd484 commit da9ef75

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

c_src/i2c_nif.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ struct I2cNifPriv {
130130
static ERL_NIF_TERM atom_ok;
131131
static ERL_NIF_TERM atom_error;
132132
static ERL_NIF_TERM atom_nak;
133+
static ERL_NIF_TERM atom_timeout;
134+
static ERL_NIF_TERM atom_retry;
133135

134136
static void i2c_dtor(ErlNifEnv *env, void *obj)
135137
{
@@ -166,6 +168,8 @@ static int i2c_load(ErlNifEnv *env, void **priv_data, ERL_NIF_TERM info)
166168
atom_ok = enif_make_atom(env, "ok");
167169
atom_error = enif_make_atom(env, "error");
168170
atom_nak = enif_make_atom(env, "i2c_nak");
171+
atom_timeout = enif_make_atom(env, "timeout");
172+
atom_retry = enif_make_atom(env, "retry");
169173

170174
*priv_data = priv;
171175
return 0;
@@ -187,6 +191,14 @@ static ERL_NIF_TERM enif_make_errno_error(ErlNifEnv *env)
187191
reason = atom_nak;
188192
break;
189193
#endif
194+
case ETIMEDOUT:
195+
reason = atom_timeout;
196+
break;
197+
198+
case EAGAIN:
199+
reason = atom_retry;
200+
break;
201+
190202
case ENOENT:
191203
reason = enif_make_atom(env, "bus_not_found");
192204
break;

0 commit comments

Comments
 (0)