Led Update Function

master
esterTion 2020-02-29 12:42:52 +08:00
parent 18b41f6b2b
commit adef11266d
1 changed files with 41 additions and 2 deletions

View File

@ -30,8 +30,23 @@
self.sliderIOView = [[UIView alloc] initWithFrame:CGRectMake(0, offsetY, screenWidth, sliderHeight)];
[self.view addSubview:self.airIOView];
[self.view addSubview:self.sliderIOView];
self.airIOView.backgroundColor = [UIColor blueColor];
self.sliderIOView.backgroundColor = [UIColor redColor];
//self.airIOView.backgroundColor = [UIColor blueColor];
//self.sliderIOView.backgroundColor = [UIColor redColor];
self.ledBackground = [CAGradientLayer layer];
self.ledBackground.frame = CGRectMake(0, 0, screenWidth, sliderHeight);
[self.sliderIOView.layer addSublayer:self.ledBackground];
self.ledBackground.startPoint = CGPointMake(1,0);
self.ledBackground.endPoint = CGPointMake(0,0);
{
float pointOffset = 0;
NSMutableArray *locations = [NSMutableArray arrayWithCapacity:33];
for (int i=0; i<33; i++) {
NSNumber *loc = [NSNumber numberWithFloat:pointOffset];
locations[i] = loc;
pointOffset += 1.0/32;
}
self.ledBackground.locations = locations;
}
struct CGColor *whiteColor = [UIColor whiteColor].CGColor;
float airOffset=0, airHeight = screenHeight*0.4/6;
@ -51,6 +66,30 @@
sliderOffset += sliderWidth;
[self.sliderIOView addSubview:sliderInput];
}
dispatch_async(dispatch_get_main_queue(), ^(){
char ledDataChar[32*3] = {0,254,254,0,254,254,0,254,254,0,0,0,254,254,254,254,254,254,254,254,254,0,0,0,10,10,10,10,10,10,10,10,10,0,0,0,0,254,128,0,254,128,0,254,128,0,254,128,0,254,128,0,254,128,0,254,128,0,0,0,0,0,254,0,0,254,0,0,254,0,0,254,0,0,254,0,0,0,0,0,254,0,0,254,0,0,254,0,0,254,0,0,254,0,0,0};
NSData *ledData = [NSData dataWithBytes:ledDataChar length:32*3];
[self updateLed:ledData];
});
}
-(void)updateLed:(NSData*)rgbData {
if (rgbData.length != 32*3) return;
NSMutableArray *colorArr = [NSMutableArray arrayWithCapacity:33];
colorArr[0] = (__bridge id)([UIColor colorWithWhite:0 alpha:0].CGColor);
uint8_t *rgb = (uint8_t*)rgbData.bytes;
for (int i=0; i<32; i++) {
float r = rgb[i*3+1], g = rgb[i*3+2], b = rgb[i*3];
r /= 255.0;
g /= 255.0;
b /= 255.0;
UIColor *color = [UIColor colorWithRed:r green:g blue:b alpha:1];
colorArr[i+1] = (__bridge id)color.CGColor;
}
self.ledBackground.colors = colorArr;
[self.ledBackground setNeedsDisplay];
}
-(BOOL)prefersStatusBarHidden { return kCFCoreFoundationVersionNumber < 1443.00; }