mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-06 19:00:27 +08:00
AP_HAL_Linux: Make RPI get_hw method public
Valid also on Bebop
This commit is contained in:
committed by
Lucas De Marchi
parent
cadef09542
commit
b6f51233db
@@ -14,6 +14,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#include "Util_RPI.h"
|
||||
#include "Util.h"
|
||||
|
||||
extern const AP_HAL::HAL& hal;
|
||||
|
||||
@@ -24,43 +25,22 @@ UtilRPI::UtilRPI()
|
||||
_check_rpi_version();
|
||||
}
|
||||
|
||||
#define MAX_SIZE_LINE 50
|
||||
int UtilRPI::_check_rpi_version()
|
||||
{
|
||||
char buffer[MAX_SIZE_LINE];
|
||||
const char* hardware_description_entry = "Hardware";
|
||||
const char* v1 = "BCM2708";
|
||||
const char* v2 = "BCM2709";
|
||||
char* flag;
|
||||
FILE* fd;
|
||||
int hw;
|
||||
hw = Util::from(hal.util)->get_hw_arm32();
|
||||
|
||||
fd = fopen("/proc/cpuinfo", "r");
|
||||
|
||||
while (fgets(buffer, MAX_SIZE_LINE, fd) != NULL) {
|
||||
flag = strstr(buffer, hardware_description_entry);
|
||||
if (flag != NULL) {
|
||||
if (strstr(buffer, v2) != NULL) {
|
||||
printf("Raspberry Pi 2 with BCM2709!\n");
|
||||
fclose(fd);
|
||||
|
||||
_rpi_version = 2;
|
||||
return _rpi_version;
|
||||
}
|
||||
else if (strstr(buffer, v1) != NULL) {
|
||||
printf("Raspberry Pi 1 with BCM2708!\n");
|
||||
fclose(fd);
|
||||
|
||||
_rpi_version = 1;
|
||||
return _rpi_version;
|
||||
}
|
||||
}
|
||||
if (hw == UTIL_HARDWARE_RPI2) {
|
||||
printf("Raspberry Pi 2 with BCM2709!\n");
|
||||
_rpi_version = 2;
|
||||
} else if (hw == UTIL_HARDWARE_RPI1) {
|
||||
printf("Raspberry Pi 1 with BCM2708!\n");
|
||||
_rpi_version = 1;
|
||||
} else {
|
||||
/* defaults to 1 */
|
||||
fprintf(stderr, "Could not detect RPi version, defaulting to 1\n");
|
||||
_rpi_version = 1;
|
||||
}
|
||||
|
||||
/* defaults to 1 */
|
||||
fprintf(stderr, "Could not detect RPi version, defaulting to 1\n");
|
||||
fclose(fd);
|
||||
|
||||
_rpi_version = 1;
|
||||
return _rpi_version;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user