Skip to content

Commit

Permalink
Notify after the historical information is appended.
Browse files Browse the repository at this point in the history
The notification apparently occurs right away, so we need to get the data all
set up before sending the notification or the log view doesn't update at the
right time.
  • Loading branch information
dustin committed Feb 11, 2005
1 parent a66492f commit d803d55
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions Thermometer.m
Expand Up @@ -39,16 +39,7 @@ - (void)dealloc


-(void)setValidReading:(float)r -(void)setValidReading:(float)r
{ {
// Normal reading update stuff // Grab all the historical and trend data first
if(reading != r) {
float oldreading=reading;
reading=r;
NSLog(@"Updated %@ (%.2f -> %.2f)", [self name], oldreading, reading);

// Send the notification
[[NSNotificationCenter defaultCenter]
postNotificationName:DATA_UPDATED object:self];
}


// Keep the array small enough. // Keep the array small enough.
while([lastReadings count] >= RING_BUFFER_SIZE) { while([lastReadings count] >= RING_BUFFER_SIZE) {
Expand All @@ -63,6 +54,20 @@ -(void)setValidReading:(float)r
TempReading *lastReading=[lastReadings lastObject]; TempReading *lastReading=[lastReadings lastObject];
// Remember the trend (upwards or downwards) // Remember the trend (upwards or downwards)
trend=r - [lastReading floatValue]; trend=r - [lastReading floatValue];

// Then process the reading change and send notifications

// Normal reading update stuff
if(reading != r) {
float oldreading=reading;
reading=r;
NSLog(@"Updated %@ (%.2f -> %.2f)", [self name], oldreading, reading);

// Send the notification
[[NSNotificationCenter defaultCenter]
postNotificationName:DATA_UPDATED object:self];
}

} }


// Check for valid values // Check for valid values
Expand Down

0 comments on commit d803d55

Please sign in to comment.