Changed a lot, added all current commands in a debug way...
This commit is contained in:
@ -14,7 +14,7 @@
|
||||
|
||||
@implementation ViewController
|
||||
|
||||
@synthesize btControl, box, status;
|
||||
@synthesize btControl, box, status, connected;
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
@ -25,8 +25,8 @@
|
||||
[btControl setup];
|
||||
btControl.delegate = self;
|
||||
|
||||
[_nameEntry setDelegate:self];
|
||||
|
||||
[_dataEntry setDelegate:self];
|
||||
[_fileEntry setDelegate:self];
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning
|
||||
@ -58,20 +58,104 @@
|
||||
}
|
||||
|
||||
-(void) serialGATTCharValueUpdated:(NSString *)UUID value:(NSData *)data {
|
||||
NSString *value = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
||||
[[[UIAlertView alloc] initWithTitle:@"RCV!" message:value delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil] show];
|
||||
NSString *retstring = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
||||
//[[[UIAlertView alloc] initWithTitle:@"RCV!" message:retstring delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil] show];
|
||||
//parseValue here
|
||||
_output.text = [_output.text stringByAppendingString:retstring];
|
||||
/*
|
||||
NSData *retdata = [retstring dataUsingEncoding:[NSString defaultCStringEncoding]];
|
||||
NSError *e = nil;
|
||||
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: retdata options: NSJSONReadingMutableContainers error: &e];
|
||||
|
||||
if (!jsonArray) {
|
||||
NSLog(@"Error parsing JSON: %@", e);
|
||||
} else {
|
||||
for(NSDictionary *item in jsonArray) {
|
||||
NSLog(@"Item: %@", item);
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
- (IBAction)clearOutput:(id)sender{
|
||||
_output.text = @"";
|
||||
}
|
||||
|
||||
- (IBAction)listDrinks:(id)sender {
|
||||
|
||||
if(self.connected){
|
||||
//NSString *sendString = [NSString stringWithFormat:@"!%@;",_nameEntry.text];
|
||||
[self sendString:@"#1;"];
|
||||
|
||||
}else{
|
||||
[[[UIAlertView alloc] initWithTitle:@"Error" message:@"BeerBox not connected!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil] show];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (IBAction)listUsers:(id)sender {
|
||||
if(self.connected){
|
||||
//NSString *sendString = [NSString stringWithFormat:@"!%@;",_nameEntry.text];
|
||||
[self sendString:@"#2;"];
|
||||
}else{
|
||||
[[[UIAlertView alloc] initWithTitle:@"Error" message:@"BeerBox not connected!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil] show];
|
||||
}
|
||||
|
||||
/*
|
||||
UITableViewController* tab =[self.storyboard instantiateViewControllerWithIdentifier:@"tableView"];
|
||||
//tab.anotherString = self.originalString;
|
||||
[tab.tableView setDelegate:self];
|
||||
[tab.tableView setDataSource:self];
|
||||
[self presentViewController:tab animated:YES completion:nil];
|
||||
*/
|
||||
}
|
||||
|
||||
- (IBAction)startScan:(id)sender{
|
||||
if(self.connected){
|
||||
//NSString *sendString = [NSString stringWithFormat:@"!%@;",_nameEntry.text];
|
||||
[self sendString:@"!3;"];
|
||||
}else{
|
||||
[[[UIAlertView alloc] initWithTitle:@"Error" message:@"BeerBox not connected!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil] show];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)getUser:(id)sender {
|
||||
NSString *sendString = [NSString stringWithFormat:@"!2%@;",_fileEntry.text];
|
||||
[self sendString:sendString];
|
||||
}
|
||||
|
||||
- (IBAction)createUser:(id)sender {
|
||||
|
||||
NSString *sendString = [NSString stringWithFormat:@"!%@;",_nameEntry.text];
|
||||
NSString *sendString = [NSString stringWithFormat:@"!1%@;",_dataEntry.text];
|
||||
[self sendString:sendString];
|
||||
}
|
||||
|
||||
- (IBAction)removeUser:(id)sender {
|
||||
NSString *sendString = [NSString stringWithFormat:@"!6%@;",_fileEntry.text];
|
||||
[self sendString:sendString];
|
||||
}
|
||||
|
||||
- (IBAction)setCredits:(id)sender {
|
||||
NSString *sendString = [NSString stringWithFormat:@"!7%@;%@;",_fileEntry.text,_dataEntry.text];
|
||||
[self sendString:sendString];
|
||||
}
|
||||
- (IBAction)setName:(id)sender {
|
||||
NSString *sendString = [NSString stringWithFormat:@"!8%@;%@;",_fileEntry.text,_dataEntry.text];
|
||||
[self sendString:sendString];
|
||||
}
|
||||
|
||||
- (IBAction)revokeRFID:(id)sender {
|
||||
NSString *sendString = [NSString stringWithFormat:@"!5%@;",_fileEntry.text];
|
||||
[self sendString:sendString];
|
||||
}
|
||||
- (IBAction)revokeFinger:(id)sender {
|
||||
NSString *sendString = [NSString stringWithFormat:@"!4%@;",_fileEntry.text];
|
||||
[self sendString:sendString];
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void) sendString:(NSString*)sendString{
|
||||
NSData *data = [sendString dataUsingEncoding:[NSString defaultCStringEncoding]];
|
||||
|
||||
if(data.length > 20)
|
||||
@ -98,11 +182,11 @@
|
||||
//NSData *data = [MsgToArduino.text dataUsingEncoding:[NSString defaultCStringEncoding]];
|
||||
[btControl write:box data:data];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
- (IBAction)revokeRFID:(id)sender {
|
||||
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Revoke RFID" message:@"Enter an ID" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];
|
||||
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
|
||||
@ -113,6 +197,7 @@
|
||||
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypePhonePad];
|
||||
[[alert textFieldAtIndex:0] becomeFirstResponder];
|
||||
}
|
||||
*/
|
||||
|
||||
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
|
||||
// The user created a new item, add it
|
||||
@ -133,12 +218,14 @@
|
||||
{
|
||||
[[[UIAlertView alloc] initWithTitle:@"Found!" message:@"BeerBox found!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
|
||||
status.text=@"Connected!";
|
||||
self.connected = true;
|
||||
}
|
||||
|
||||
-(void)setDisconnect
|
||||
{
|
||||
[[[UIAlertView alloc] initWithTitle:@"Lost!" message:@"BeerBox lost :-(" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
|
||||
status.text=@"not Connected";
|
||||
self.connected = false;
|
||||
}
|
||||
|
||||
|
||||
@ -147,6 +234,22 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
//####### Table View stuff
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
||||
return 10;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||||
NSString *protoID = @"userCell";
|
||||
|
||||
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:protoID];
|
||||
cell.textLabel.text = @"Lol";
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user