Advertisement
Guest User

Untitled

a guest
Nov 4th, 2020
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. /*
  2. Updated for the multiple device support: June 2013
  3. by ihsan Kehribar <ihsan@kehribar.me>
  4.  
  5. Updated for the new firmware: July 2012
  6. by ihsan Kehribar <ihsan@kehribar.me>
  7.  
  8. Created: December 2011
  9. by Omer Kilic <omerkilic@gmail.com>
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include "littleWire.h"
  15. #include "littleWire_util.h"
  16.  
  17. #define LED PIN1
  18.  
  19. unsigned char version;
  20. int total_lwCount;
  21. int i;
  22.  
  23. int main(int argc, char **argv) {
  24. littleWire *lw = NULL;
  25.  
  26. total_lwCount = littlewire_search();
  27.  
  28. if(total_lwCount == 1) {
  29. printf("----------------------------------------------------------\n");
  30. printf("> 1 Little Wire device is found with serialNumber: %d\n", lwResults[0].serialNumber);
  31. printf("----------------------------------------------------------\n");
  32. } else if(total_lwCount > 1) {
  33. printf("----------------------------------------------------------\n");
  34. printf("> %d Little Wire devices are found\n", total_lwCount);
  35. printf("----------------------------------------------------------\n");
  36. printf("> #id - serialNumber\n");
  37. for(i=0; i < total_lwCount; i++) {
  38. printf("> %2d - %3d\n", i, lwResults[i].serialNumber);
  39. }
  40. printf("----------------------------------------------------------\n");
  41. } else if(total_lwCount == 0) {
  42. printf("----------------------------------------------------------\n");
  43. printf("> Little Wire could not be found!\n");
  44. printf("----------------------------------------------------------\n");
  45. exit(EXIT_FAILURE);
  46. }
  47.  
  48. /* Connects to the first littleWire device the computer can find. */
  49. // lw = littleWire_connect();
  50.  
  51. /* Connects to the spesific littleWire device by array id. */
  52. lw = littlewire_connect_byID(0);
  53.  
  54. /* Connects to the spesific littleWire with a given serial number. */
  55. /* If multiple devices have the same serial number, it connects to the last one it finds */
  56. // lw = littlewire_connect_bySerialNum(126);
  57.  
  58. if(lw == NULL){
  59. printf("> Little Wire connection problem!\n");
  60. exit(EXIT_FAILURE);
  61. }
  62.  
  63. version = readFirmwareVersion(lw);
  64. printf("> Little Wire firmware version: %d.%d\n", ((version & 0xF0) >> 4), (version&0x0F));
  65. if(version < 0x12) {
  66. printf("> This example requires the new 1.2 version firmware. Please update soon.\n");
  67. return 0;
  68. }
  69.  
  70. /* In order to change the serial number of the current connected device, use the following function. */
  71. /* You need to unplug-plug to see the change. */
  72. /* Serial numbers have to be between 100-999 */
  73. // changeSerialNumber(lw,152);
  74.  
  75. /*------------------------------------------------------------------------------------------------------*/
  76.  
  77. if (argc == 0) {
  78. return 0;
  79. }
  80.  
  81. pinMode(lw, LED, OUTPUT);
  82.  
  83. digitalWrite(lw, LED, HIGH);
  84. delay(atoi(argv[1]));
  85. digitalWrite(lw, LED, LOW);
  86.  
  87. if(lwStatus < 0) {
  88. printf("> lwStatus: %d\n", lwStatus);
  89. printf("> Connection error: ");
  90. printf("%s\n", littleWire_errorName());
  91. return 0;
  92. }
  93. return 0;
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement