Skip to content

Commit

Permalink
misc small changes. mainly just found and replaced a few old log calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus10110 committed Apr 10, 2024
1 parent 7cd665f commit 06bcab4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion firmware/include/apple_media_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace AppleMediaService
TrackTitleOnly // only get notified when the track title is set.
};
// overwrites existing notification if set.
void RegisterForNotifications( NotificationCb callback, NotificationLevel level );
void RegisterForNotifications( const NotificationCb& callback, NotificationLevel level );
const MediaInformation& GetMediaInformation();
bool StartMediaService( BLEClient* client );
}
16 changes: 8 additions & 8 deletions firmware/src/apple_media_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace AppleMediaService
LOG_INFO( "duration: %f", mDuration );
}

void RegisterForNotifications( NotificationCb callback, NotificationLevel level )
void RegisterForNotifications( const NotificationCb& callback, NotificationLevel level )
{
gCallback = callback;
gNotificationLevel = level;
Expand All @@ -84,22 +84,22 @@ namespace AppleMediaService

if( !client->isConnected() )
{
log_e( "client not connected" );
LOG_ERROR( "client not connected" );
return false;
}

auto music_service = client->getService( APPLE_SERVICE_UUID );
if( !music_service )
{
log_e( "Apple music service not found" );
LOG_ERROR( "Apple music service not found" );
return false;
}

// TODO: Add support for actually sending media control commands
auto remote_command_characteristic = music_service->getCharacteristic( APPLE_REMOTE_COMMAND_UUID );
if( !remote_command_characteristic )
{
log_e( "Apple remote command characteristic not found" );
LOG_ERROR( "Apple remote command characteristic not found" );
return false;
}

Expand All @@ -108,29 +108,29 @@ namespace AppleMediaService
auto entity_attribute_characteristic = music_service->getCharacteristic( APPLE_REMOTE_COMMAND_UUID );
if( !entity_attribute_characteristic )
{
log_e( "Apple entity attribute characteristic not found" );
LOG_ERROR( "Apple entity attribute characteristic not found" );
return false;
}

auto entity_update = music_service->getCharacteristic( APPLE_ENTITY_UPDATE_UUID );
if( !entity_update )
{
log_e( "Apple entity update characteristic not found" );
LOG_ERROR( "Apple entity update characteristic not found" );
return false;
}

entity_update->registerForNotify( []( BLERemoteCharacteristic* characteristic, uint8_t* data, size_t length, bool is_notify ) {
bool notify = gNotificationLevel == NotificationLevel::All;
if( length < 3 )
{
log_e( "entity_update notification less than 3 bytes, ignoring." );
LOG_ERROR( "entity_update notification less than 3 bytes, ignoring." );
return;
}
uint8_t entity_id = data[ 0 ];
uint8_t attribute_id = data[ 1 ];
uint8_t flags = data[ 2 ];
std::string value( reinterpret_cast<char*>( data ) + 3, length - 3 );
log_d( "entity update. id: %i, attribute: %i, flags: %i, value: %s", entity_id, attribute_id, flags, value.c_str() );
LOG_TRACE( "entity update. id: %i, attribute: %i, flags: %i, value: %s", entity_id, attribute_id, flags, value.c_str() );
switch( entity_id )
{
case EntityIDPlayer:
Expand Down
8 changes: 4 additions & 4 deletions firmware/src/apple_notification_center_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,29 @@ namespace AppleNotifications

if( !client->isConnected() )
{
log_e( "client not connected" );
LOG_ERROR( "client not connected" );
return false;
}

auto notification_service = client->getService( ANCS_SERVICE_UUID );
if( !notification_service )
{
log_e( "Apple ANCS service not found" );
LOG_ERROR( "Apple ANCS service not found" );
return false;
}

auto notification_source = notification_service->getCharacteristic( APPLE_NOTIFICATION_SOURCE_CHARACTERISTIC_UUID );
if( !notification_source )
{
log_e( "Apple notification source characteristic not found" );
LOG_ERROR( "Apple notification source characteristic not found" );
return false;
}

notification_source->registerForNotify(
[]( BLERemoteCharacteristic* characteristic, uint8_t* data, size_t length, bool is_notify ) {
if( length != 8 )
{
log_e( "Apple notification source message not exactly 8 bytes" );
LOG_ERROR( "Apple notification source message not exactly 8 bytes" );
return;
}

Expand Down
8 changes: 4 additions & 4 deletions firmware/src/current_time_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace CurrentTimeService
CurrentTime time;
if( length < 9 )
{
log_e( "time data length too short" );
LOG_ERROR( "time data length too short" );
return time;
}
time.mYear = data[ 0 ] | ( data[ 1 ] << 8 );
Expand Down Expand Up @@ -117,21 +117,21 @@ namespace CurrentTimeService

if( !client->isConnected() )
{
log_e( "client not connected" );
LOG_ERROR( "client not connected" );
return false;
}

auto time_service = client->getService( CURRENT_TIME_SERVICE_UUID );
if( !time_service )
{
log_e( "time service not found" );
LOG_ERROR( "time service not found" );
return false;
}

auto current_time_characteristic = time_service->getCharacteristic( CURRENT_TIME_UUID );
if( !current_time_characteristic )
{
log_e( "current time characteristic not found" );
LOG_ERROR( "current time characteristic not found" );
return false;
}

Expand Down
30 changes: 15 additions & 15 deletions firmware/src/screens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,28 +182,28 @@ namespace Screens
char buffer[ 128 ];
char ns = mLatitude > 0 ? 'N' : 'S';
char ew = mLongitude > 0 ? 'E' : 'W';
sprintf( buffer, "%2.4f %c", abs( mLatitude ), ns );
snprintf( buffer, sizeof( buffer ), "%2.4f %c", std::abs( mLatitude ), ns );
DrawPair( display, "Latitude", buffer, x1, y1 );

sprintf( buffer, "%3.4f %c", abs( mLongitude ), ew );
snprintf( buffer, sizeof( buffer ), "%3.4f %c", std::abs( mLongitude ), ew );
DrawPair( display, "Longitude", buffer, x2, y1 );

sprintf( buffer, "%3.1f mph", mSpeedMph );
snprintf( buffer, sizeof( buffer ), "%3.1f mph", mSpeedMph );
DrawPair( display, "Speed", buffer, x1, y1 + y_pitch );

DrawPair( display, "Heading", HeadingToDirection( mHeadingDegrees ), x2, y1 + y_pitch );

sprintf( buffer, "%2.1f V", mBatteryVolts );
snprintf( buffer, sizeof( buffer ), "%2.1f V", mBatteryVolts );
DrawPair( display, "Battery", buffer, x1, y1 + y_pitch * 2 );

sprintf( buffer, "% 1.1f/% 1.1f/% 1.1f", mForwardG, mLateralG, mVerticalG );
snprintf( buffer, sizeof( buffer ), "% 1.1f/% 1.1f/% 1.1f", mForwardG, mLateralG, mVerticalG );
DrawPair( display, "G-Force", buffer, x2, y1 + y_pitch * 2, true );
}

void OtaInProgress::Draw( Display::Display* display )
{
char buffer[ 128 ];
sprintf( buffer, "%u Bytes", mBytesReceived );
snprintf( buffer, sizeof( buffer ), "%u Bytes", mBytesReceived );

display->clear();
display->setFont( &JetBrainsMono_Thin14pt7b );
Expand Down Expand Up @@ -240,7 +240,7 @@ namespace Screens
display->WriteAligned( "Waiting for Launch", Display::HorizontalAlignment::Center, Display::VerticalAlignment::Top,
&second_region );
char buffer[ 128 ];
sprintf( buffer, "%.1f g", mAccelerationG );
snprintf( buffer, sizeof( buffer ), "%.1f g", mAccelerationG );
display->WriteAligned( buffer, Display::HorizontalAlignment::Center, Display::VerticalAlignment::Center );
}

Expand Down Expand Up @@ -269,16 +269,16 @@ namespace Screens
const int y1 = 40;
const int y_pitch = 46;
char buffer[ 128 ];
sprintf( buffer, "%.1f s", mTimeSec );
snprintf( buffer, sizeof( buffer ), "%.1f s", mTimeSec );
DrawPair( display, "Time", buffer, x1, y1 );

sprintf( buffer, "%.2f mi", mDistanceMiles );
snprintf( buffer, sizeof( buffer ), "%.2f mi", mDistanceMiles );
DrawPair( display, "Distance", buffer, x2, y1 );

sprintf( buffer, "%.1f g", mAccelerationG );
snprintf( buffer, sizeof( buffer ), "%.1f g", mAccelerationG );
DrawPair( display, "Accel", buffer, x1, y1 + y_pitch );

sprintf( buffer, "%.1f mph", mSpeedMph );
snprintf( buffer, sizeof( buffer ), "%.1f mph", mSpeedMph );
DrawPair( display, "Speed", buffer, x2, y1 + y_pitch );
double distance = mDistanceMiles;
if( distance < 0 )
Expand All @@ -304,16 +304,16 @@ namespace Screens
const int y_pitch = 55;

char buffer[ 128 ];
sprintf( buffer, "%.1f s", mQuarterMileTimeSec );
snprintf( buffer, sizeof( buffer ), "%.1f s", mQuarterMileTimeSec );
DrawPair( display, "1/4 mi", buffer, x1, y1 );

sprintf( buffer, "%.1f s", mZeroSixtyTimeSec );
snprintf( buffer, sizeof( buffer ), "%.1f s", mZeroSixtyTimeSec );
DrawPair( display, "0-60", buffer, x2, y1 );

sprintf( buffer, "%.1f mph", mMaxSpeedMph );
snprintf( buffer, sizeof( buffer ), "%.1f mph", mMaxSpeedMph );
DrawPair( display, "Max Speed", buffer, x1, y1 + y_pitch );

sprintf( buffer, "%.1f g", mMaxAccelerationG );
snprintf( buffer, sizeof( buffer ), "%.1f g", mMaxAccelerationG );
DrawPair( display, "Max Accel", buffer, x2, y1 + y_pitch );
}
}
Expand Down

0 comments on commit 06bcab4

Please sign in to comment.