Merge pull request #143 from alanbjohnston/pi-zero-2

Pi zero 2
pull/146/head
alanbjohnston 4 years ago committed by GitHub
commit af8e43e75f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -23,6 +23,22 @@
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
char resbuffer[1000];
const char testStr[] = "cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//' | grep '902120'";
FILE *file_test = sopen(testStr); // see if Pi Zero 2
fgets(resbuffer, 1000, file_test);
// fprintf(stderr, "test result: %s\n", resbuffer);
fclose(file_test);
// fprintf(stderr, " %x ", resbuffer[0]);
// fprintf(stderr, " %x ", resbuffer[1]);
if (resbuffer[1] != 0)
{
sleep(5); // try sleep at start to help boot
voltageThreshold = 3.7;
printf("Pi Zero 2 detected");
}
printf("\n\nCubeSatSim v1.1 starting...\n\n"); printf("\n\nCubeSatSim v1.1 starting...\n\n");
FILE * rpitx_stop = popen("sudo systemctl stop rpitx", "r"); FILE * rpitx_stop = popen("sudo systemctl stop rpitx", "r");
@ -723,6 +739,8 @@ int main(int argc, char * argv[]) {
fprintf(stderr, "INFO: Battery voltage: %5.2f V Threshold %5.2f V Current: %6.1f mA Threshold: %6.1f mA\n", batteryVoltage, voltageThreshold, batteryCurrent, currentThreshold); fprintf(stderr, "INFO: Battery voltage: %5.2f V Threshold %5.2f V Current: %6.1f mA Threshold: %6.1f mA\n", batteryVoltage, voltageThreshold, batteryCurrent, currentThreshold);
#endif #endif
// if ((batteryVoltage > 1.0) && (batteryVoltage < batteryThreshold)) // no battery INA219 will give 0V, no battery plugged into INA219 will read < 1V // if ((batteryVoltage > 1.0) && (batteryVoltage < batteryThreshold)) // no battery INA219 will give 0V, no battery plugged into INA219 will read < 1V
/**/
if ((batteryCurrent > currentThreshold) && (batteryVoltage < voltageThreshold) && !sim_mode) // currentThreshold ensures that this won't happen when running on DC power. if ((batteryCurrent > currentThreshold) && (batteryVoltage < voltageThreshold) && !sim_mode) // currentThreshold ensures that this won't happen when running on DC power.
{ {
fprintf(stderr, "Battery voltage too low: %f V - shutting down!\n", batteryVoltage); fprintf(stderr, "Battery voltage too low: %f V - shutting down!\n", batteryVoltage);
@ -745,7 +763,7 @@ int main(int argc, char * argv[]) {
pclose(file6); pclose(file6);
sleep(10); sleep(10);
} }
/**/
// sleep(1); // Delay 1 second // sleep(1); // Delay 1 second
ctr = 0; ctr = 0;
#ifdef DEBUG_LOGGING #ifdef DEBUG_LOGGING

@ -14,60 +14,12 @@ int main(int argc, char *argv[]) {
debug = ON; debug = ON;
} }
} }
wiringPiSetup ();
printf("\n"); printf("CubeSatSim v1.1 INA219 Voltage and Current Telemetry\n");
map[MINUS_X] = MINUS_Y;
pinMode (2, INPUT); map[PLUS_Z] = MINUS_X;
pullUpDnControl (2, PUD_UP); map[MINUS_Y] = PLUS_Z;
snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(3));
if (digitalRead(2) != HIGH)
{
printf("vB3 with TFB Present\n");
map[BUS] = MINUS_Z;
map[BAT] = BUS;
map[PLUS_Z] = BAT;
map[MINUS_Z] = PLUS_Z;
snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(0));
}
else
{
pinMode (3, INPUT);
pullUpDnControl (3, PUD_UP);
if (digitalRead(3) != HIGH)
{
printf("vB4 Present\n");
map[BAT] = BUS;
map[BUS] = BAT;
snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(0));
// strcpy(busStr,"1 0");
}
else
{
pinMode (26, INPUT);
pullUpDnControl (26, PUD_UP);
if (digitalRead(26) != HIGH)
{
// if (debug == ON)
printf("CubeSatSim v1.1 INA219 Voltage and Current Telemetry\n");
map[MINUS_X] = MINUS_Y;
map[PLUS_Z] = MINUS_X;
map[MINUS_Y] = PLUS_Z;
snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(3));
}
else
{
printf("VB3 Present\n");
map[BUS] = MINUS_Z;
map[BAT] = BUS;
map[PLUS_Z] = BAT;
map[MINUS_Z] = PLUS_Z;
snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(0));
}
}
}
// Reading I2C voltage and current sensors // Reading I2C voltage and current sensors
// printf("Starting\n"); // printf("Starting\n");
@ -128,6 +80,7 @@ int main(int argc, char *argv[]) {
printf("-Z | % 4.2f V % 5.0f mA \n", voltage[map[MINUS_Z]], current[map[MINUS_Z]]); printf("-Z | % 4.2f V % 5.0f mA \n", voltage[map[MINUS_Z]], current[map[MINUS_Z]]);
printf("Bat | % 4.2f V % 5.0f mA \n", voltage[map[BAT]], current[map[BAT]]); printf("Bat | % 4.2f V % 5.0f mA \n", voltage[map[BAT]], current[map[BAT]]);
printf("Bus | % 4.2f V % 5.0f mA \n\n", voltage[map[BUS]], current[map[BUS]]); printf("Bus | % 4.2f V % 5.0f mA \n\n", voltage[map[BUS]], current[map[BUS]]);
fclose(file1);
return 0; return 0;
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.