Skip to content

Commit

Permalink
Remove a few more DAL dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
markshannon authored and dpgeorge committed Mar 31, 2017
1 parent 8e85863 commit 9aa6dc9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
3 changes: 0 additions & 3 deletions source/microbit/modantigravity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
* THE SOFTWARE.
*/

#include <stdio.h>
#include "MicroBit.h"

extern "C" {

#include "py/mphal.h"
Expand Down
3 changes: 0 additions & 3 deletions source/microbit/modlove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
* THE SOFTWARE.
*/

#include <stdio.h>
#include "MicroBit.h"

extern "C" {

#include "microbit/modmicrobit.h"
Expand Down
49 changes: 41 additions & 8 deletions source/microbit/modmicrobit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@
* THE SOFTWARE.
*/

#include "MicroBit.h"
#include "mbed.h"

extern "C" {

#include "py/nlr.h"
#include "py/obj.h"
#include "py/mphal.h"
#include "modmicrobit.h"
#include "microbitdisplay.h"
#include "microbitimage.h"

extern uint32_t ticks;

STATIC mp_obj_t microbit_reset_(void) {
uBit.reset();
NVIC_SystemReset();
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_0(microbit_reset_obj, microbit_reset_);
Expand All @@ -54,22 +58,51 @@ STATIC mp_obj_t microbit_sleep(mp_obj_t ms_in) {
MP_DEFINE_CONST_FUN_OBJ_1(microbit_sleep_obj, microbit_sleep);

STATIC mp_obj_t microbit_running_time(void) {
return MP_OBJ_NEW_SMALL_INT(uBit.systemTime());
return MP_OBJ_NEW_SMALL_INT(ticks);
}
MP_DEFINE_CONST_FUN_OBJ_0(microbit_running_time_obj, microbit_running_time);

static const monochrome_5by5_t panic = SMALL_IMAGE(
1,1,0,1,1,
1,1,0,1,1,
0,0,0,0,0,
0,1,1,1,0,
1,0,0,0,1
);

STATIC mp_obj_t microbit_panic(mp_uint_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
uBit.panic();
} else {
uBit.panic(mp_obj_get_int(args[0]));
while(true) {
microbit_display_show(&microbit_display_obj, (microbit_image_obj_t*)&panic);
mp_hal_delay_ms(1000);
char num[4];
int code;
if (n_args) {
code = mp_obj_get_int(args[0]);
} else {
code = 0;
}
num[2] = code%10 + '0';
code /= 10;
num[1] = code%10 + '0';
code /= 10;
num[0] = code%10 + '0';
for (int i = 0; i < 3; i++) {
microbit_display_show(&microbit_display_obj, microbit_image_for_char(num[i]));
mp_hal_delay_ms(1000);
}
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(microbit_panic_obj, 0, 1, microbit_panic);

STATIC mp_obj_t microbit_temperature(void) {
return mp_obj_new_int(uBit.thermometer.getTemperature());
int temp;
NRF_TEMP->TASKS_START = 1;
while (NRF_TEMP->EVENTS_DATARDY == 0);
NRF_TEMP->EVENTS_DATARDY = 0;
temp = NRF_TEMP->TEMP;
NRF_TEMP->TASKS_STOP = 1;
return mp_obj_new_float(temp/4.0);
}
MP_DEFINE_CONST_FUN_OBJ_0(microbit_temperature_obj, microbit_temperature);

Expand Down
1 change: 0 additions & 1 deletion source/microbit/modthis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/

#include <stdio.h>
#include "MicroBit.h"

extern "C" {

Expand Down

0 comments on commit 9aa6dc9

Please sign in to comment.