88#include " MBNet_1000.h"
99#include " names.h"
1010#include " stdlib.h"
11+ #include " errno.h"
1112
1213
1314MBNet_1000::MBNet_1000 (KPUClass& kpu, Sipeed_ST7789& lcd, Sipeed_OV2640& camera)
1415:_kpu(kpu),_lcd(lcd), _camera(camera),
15- _count(0 ), _result(nullptr )
16+ _model( nullptr ), _count(0 ), _result(nullptr )
1617{
1718 _names = mbnet_label_name;
1819 memset (_statistics, 0 , sizeof (_statistics));
1920}
2021
2122MBNet_1000::~MBNet_1000 ()
2223{
23-
24+ if (_model)
25+ free (_model);
2426}
2527
2628
@@ -32,25 +34,44 @@ int MBNet_1000::begin(const char* kmodel_name)
3234 if (!_lcd.begin (15000000 , COLOR_RED))
3335 return -2 ;
3436 _camera.run (true );
37+ _lcd.setTextSize (2 );
38+ _lcd.setTextColor (COLOR_WHITE);
3539
3640 if (!SD.begin ())
41+ {
42+ _lcd.setCursor (100 ,100 );
43+ _lcd.print (" No SD Card" );
3744 return -3 ;
45+ }
3846
3947 myFile = SD.open (kmodel_name);
4048 if (!myFile)
4149 return -4 ;
4250 uint32_t fSize = myFile.size ();
43- _lcd.setTextSize (2 );
44- _lcd.setTextColor (COLOR_WHITE);
4551 _lcd.setCursor (100 ,100 );
4652 _lcd.print (" Loading ... " );
53+ _model = (uint8_t *)malloc (fSize );
54+ if (!_model)
55+ {
56+ _lcd.setCursor (100 ,140 );
57+ _lcd.print (" Memmory not enough ... " );
58+ return ENOMEM;
59+ }
4760 long ret = myFile.read (_model, fSize );
4861 myFile.close ();
4962 if (ret != fSize )
63+ {
64+ free (_model);
65+ _model = nullptr ;
5066 return -5 ;
67+ }
5168
5269 if (_kpu.begin (_model) != 0 )
70+ {
71+ free (_model);
72+ _model = nullptr ;
5373 return -6 ;
74+ }
5475 return 0 ;
5576}
5677
0 commit comments