ubluepy_delegate.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2017 Glenn Ruben Bakke
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #include "py/obj.h"
  27. #include "py/runtime.h"
  28. #if MICROPY_PY_UBLUEPY_PERIPHERAL || MICROPY_PY_UBLUEPY_CENTRAL
  29. #include "modubluepy.h"
  30. STATIC void ubluepy_delegate_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
  31. ubluepy_delegate_obj_t * self = (ubluepy_delegate_obj_t *)o;
  32. (void)self;
  33. mp_printf(print, "DefaultDelegate()");
  34. }
  35. STATIC mp_obj_t ubluepy_delegate_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
  36. ubluepy_delegate_obj_t *s = m_new_obj(ubluepy_delegate_obj_t);
  37. s->base.type = type;
  38. return MP_OBJ_FROM_PTR(s);
  39. }
  40. /// \method handleConnection()
  41. /// Handle connection events.
  42. ///
  43. STATIC mp_obj_t delegate_handle_conn(mp_obj_t self_in) {
  44. ubluepy_delegate_obj_t *self = MP_OBJ_TO_PTR(self_in);
  45. (void)self;
  46. return mp_const_none;
  47. }
  48. STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_delegate_handle_conn_obj, delegate_handle_conn);
  49. /// \method handleNotification()
  50. /// Handle notification events.
  51. ///
  52. STATIC mp_obj_t delegate_handle_notif(mp_obj_t self_in) {
  53. ubluepy_delegate_obj_t *self = MP_OBJ_TO_PTR(self_in);
  54. (void)self;
  55. return mp_const_none;
  56. }
  57. STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_delegate_handle_notif_obj, delegate_handle_notif);
  58. STATIC const mp_rom_map_elem_t ubluepy_delegate_locals_dict_table[] = {
  59. { MP_ROM_QSTR(MP_QSTR_handleConnection), MP_ROM_PTR(&ubluepy_delegate_handle_conn_obj) },
  60. { MP_ROM_QSTR(MP_QSTR_handleNotification), MP_ROM_PTR(&ubluepy_delegate_handle_notif_obj) },
  61. #if 0
  62. { MP_ROM_QSTR(MP_QSTR_handleDiscovery), MP_ROM_PTR(&ubluepy_delegate_handle_disc_obj) },
  63. #endif
  64. };
  65. STATIC MP_DEFINE_CONST_DICT(ubluepy_delegate_locals_dict, ubluepy_delegate_locals_dict_table);
  66. const mp_obj_type_t ubluepy_delegate_type = {
  67. { &mp_type_type },
  68. .name = MP_QSTR_DefaultDelegate,
  69. .print = ubluepy_delegate_print,
  70. .make_new = ubluepy_delegate_make_new,
  71. .locals_dict = (mp_obj_dict_t*)&ubluepy_delegate_locals_dict
  72. };
  73. #endif // MICROPY_PY_UBLUEPY_PERIPHERAL || MICROPY_PY_UBLUEPY_CENTRAL