-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Herzka
committed
Sep 28, 2017
1 parent
df33bb7
commit baf2099
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CFLAGS = -Wall -Weverything -lobjc -framework IOBluetooth | ||
|
||
build: btname | ||
|
||
install: build | ||
install -m 755 btname /usr/local/bin/btname | ||
|
||
uninstall: | ||
${RM} /usr/local/bin/btname | ||
|
||
clean: | ||
${RM} btname |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#import <stdio.h> | ||
#import <string.h> | ||
#import <objc/objc.h> | ||
|
||
@interface IOBluetoothHostController | ||
+ (IOBluetoothHostController *)defaultController; | ||
- (int)BluetoothHCIReadLocalName:(char[248])name; | ||
- (int)BluetoothHCIWriteLocalName:(char[248])name; | ||
@end | ||
|
||
int main() | ||
{ | ||
IOBluetoothHostController *controller = [IOBluetoothHostController defaultController]; | ||
|
||
char oldName[248]; | ||
[controller BluetoothHCIReadLocalName:oldName]; | ||
printf("Current bluetooth name is \"%s\". New name? ", oldName); | ||
|
||
BOOL changed = false; | ||
char newName[248]; | ||
if (fgets(newName, sizeof(newName), stdin) != NULL) { | ||
// Get rid of newline at end | ||
newName[strcspn(newName, "\n")] = '\0'; | ||
|
||
if (newName[0] != '\0') { | ||
[controller BluetoothHCIWriteLocalName:newName]; | ||
changed = true; | ||
} | ||
} else { | ||
printf("\n"); | ||
} | ||
|
||
if (changed) { | ||
// Read again for good measure | ||
[controller BluetoothHCIReadLocalName:newName]; | ||
printf("Bluetooth name has been changed to \"%s\"\n", newName); | ||
} else { | ||
printf("Name not changed\n"); | ||
} | ||
|
||
return 0; | ||
} |