MCPcopy Create free account
hub / github.com/DexterInd/GoPiGo3 / detect

Method detect

Software/C/GoPiGo3.cpp:97–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95}
96
97int GoPiGo3::detect(bool critical){
98 char ErrorStr[100];
99 char str[21];
100 int error;
101 // assign error to the value returned by get_manufacturer, and if not 0:
102 if(error = get_manufacturer(str)){
103 if(critical){
104 fatal_error("detect error: get_manufacturer failed. Perhaps the GoPiGo3 is not connected, or the address is incorrect.");
105 }else{
106 return error;
107 }
108 }
109 if(strstr(str, "Dexter Industries") != str){
110 if(critical){
111 fatal_error("detect error: get_manufacturer string is not 'Dexter Industries'");
112 }else{
113 return ERROR_WRONG_MANUFACTURER;
114 }
115 }
116
117 // assign error to the value returned by get_board, and if not 0:
118 if(error = get_board(str)){
119 if(critical){
120 fatal_error("detect error: get_board failed");
121 }else{
122 return error;
123 }
124 }
125 if(strstr(str, "GoPiGo3") != str){
126 if(critical){
127 fatal_error("detect error: get_board string is not 'GoPiGo3'");
128 }else{
129 return ERROR_WRONG_DEVICE;
130 }
131 }
132
133 // assign error to the value returned by get_version_firmware, and if not 0:
134 if(error = get_version_firmware(str)){
135 if(critical){
136 fatal_error("detect error: get_version_firmware failed");
137 }else{
138 return error;
139 }
140 }
141 if(strstr(str, FIRMWARE_VERSION_REQUIRED) != str){
142 if(critical){
143 sprintf(ErrorStr, "detect error: GoPiGo3 firmware needs to be version %sx but is currently version %s", FIRMWARE_VERSION_REQUIRED, str);
144 fatal_error(ErrorStr);
145 }else{
146 return ERROR_FIRMWARE_MISMATCH;
147 }
148 }
149 return ERROR_NONE;
150}
151
152int GoPiGo3::get_manufacturer(char *str){
153 return spi_read_string(GPGSPI_MESSAGE_GET_MANUFACTURER, str);

Callers 6

mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80

Calls 1

fatal_errorFunction · 0.85

Tested by

no test coverage detected