Shop OBEX P1 Docs P2 Docs Learn Events
Hackable Badge auto datetime — Parallax Forums

Hackable Badge auto datetime

I have a Badge hooked up to the RPi (/ttyUSB0), and I am using Python to talk to the Badge, a snippet:
if inStr.strip() == "SysTime":
		get_time()
		clockit = now.strftime("%m/%d/%y")			
		ser.write(clockit)
		ser.write('%c' % CR)    # Send CR
		clockit = now.strftime("%H/%M/%S")
		ser.write(clockit)
		ser.write('%c' % CR)    # Send CR
		#ser.write('Got it!%c' % CR)
		#time.sleep(.300)
		print('Sent it')
On the Badge, I am using PropGCC to talk to the RPi, a snippet:
  char inSysTime[40];
  writeStr(term,"SysTime\n");
  pause(300);
  readStr(term,inSysTime,40);
  oledprint("%s",inSysTime);  // Print to oled screen
  //sprintf(inSysTime,"%s",inSysTime);
  dt_fromDateStr(dt,inSysTime);
  //dt_set(dt);
  pause(100);
  readStr(term,inSysTime,40);
  oledprint("%s",inSysTime);  // Print to oled screen
  //sprintf(inSysTime,"%s",inSysTime);
  dt_fromTimeStr(dt,inSysTime);
  dt_set(dt);
  dt = dt_get();
  dt_toDateStr(dt,dates);
  dt_toTimeStr(dt,times);
  text_size(LARGE);
  oledprint("%s%s", dates, times);  // Getting all zeros for the date and time
For some reason, that I cannot figure out, 'dt_fromDateStr(dt,inSysTime);' and 'dt_fromTimeStr(dt,inSysTime);', are not working as expected. I have the 'oledprint("%s",inSysTime);' right after the readStr(), which shows the correct format that was received, but it is not converted and stored in dt. Any help on this would be appreciated.

Thanks

Ray

Comments

  • So, I seem to be making some progress, the below program for the Hackable Badge seems to work as expected. Boy, was this a test of my patience. Now I can get the Badge time synced automatically from the RPi.

    The Python program is run on the RPi, with a Hackable Badge attached to the ttyUSB0 PORT. When the Badge gets the data, and is running, it seems like the seconds is out of sync by about a half maybe a quarter of a second, close enough for gov work.

    I decided to use a Badge, always connected, for the time being, or at least until another solution comes along, to the RPi. I plan to use this connected Badge to datetime sync other badges, plus now I will see if I can get The Python script to handle the Badge data with a file on the RPi. I also found this solution to be cheaper than going with a new QuickStart ($35.00) and an HIB($35.00) verses a Badge ($50.00). I must be the only person working with a Badge using SimpleIDE PropGCC, in the field. A personal opinion, I find working with a Hackable Badge is more useful than working with a QuickStart+other board.

    Ray
    /*
      gAutotest.c
      Jan 9, 2016
    */
    #include "simpletools.h"
    #include "simpletext.h"
    #include "fdserial.h"
    #include "badgetools.h"
    #include "datetime.h"
    
    serial *term;
    
    datetime dt = {2000, 1, 1, 0, 0, 0};
    char dates[9];
    char times[9];
    
    
    int main()
    {
      // Add startup code here.
      char inBuff[40];
      term = fdserial_open(31,30,0,115200);
      badge_setup();
      dt_run(dt);
      pause(250);  // Wait for dt_run to setup.
    
      char SysDT[20];
    
      text_size(SMALL);
    /* Send to Python. */
      writeStr(term,"SysTime\n");
      pause(150);
      readStr(term,SysDT,20);  // Get data from Python.
      pause(100);
    /* Process the date time data.*/ 
      sscan(SysDT,"%d/%d/%d/%d/%d/%d",&dt.mo,&dt.d,&dt.y,&dt.h,&dt.m,&dt.s);
    
      dt_set(dt);  // Reset dt with the new data.
      pause(200);
    
      dt = dt_get();
    /* Temp display for debug. */
      dt_toDateStr(dt,dates);
      pause(200);
      dt_toTimeStr(dt,times);
    
      cursor(0,5);
      oledprint("%s", dates);
      pause(100);
      cursor(0,6);
      oledprint("%s",times);
      cursor(0,7);
    /* Can I get the individual elements. */
      oledprint("%d",dt.h);
      oledprint(":%d",dt.m);
      oledprint(":%d",dt.s);
      pause(3000);
      
      text_size(LARGE);   
      while(1)
      {
    /* Running clock, in big characters. */
        dt = dt_get();
        dt_toTimeStr(dt,times);
        cursor(0,0);
        oledprint("%s", times);
        pause(100);
      }  
    }
    

    Python script file.
    #!/usr/bin/python
    #bgTerm.py
    import os
    import serial
    import time
    import datetime
    
    # On reboot, reset /dev/ttyUSB0 to 115200 BAUD.
    os.system("stty -F /dev/ttyUSB0 115200")
    
    # Setup ser
    ser = serial.Serial(port='/dev/ttyUSB0', baudrate=115200, writeTimeout = 0)
    
    # Close then reopen ser.
    ser.close()
    time.sleep(.250)
    ser.open()
    
    if ser.isOpen():
    	print('Open %s  %d BAUD' % (ser.portstr,ser.baudrate))
    	print('')
    
    
    inStr = ''
    CR = chr(13)
    LF = '\n'
    
    # Setup datetime for local time.
    def get_time():
    	global now
    	now = datetime.datetime.now()
    	
    
    #Main routine, a forever loop waiting for commands to process.
    while 1:
    	while ser.inWaiting() > 0:
    		time.sleep(.200)
    		inStr = ser.readline(ser.inWaiting())
    		#time.sleep(.350)
    		print(inStr)
    		if inStr.strip() == "SysTime":
    			get_time()
    			clockit = now.strftime("%m/%d/%Y/%H/%M/%S%n")			
    			ser.write(clockit)
    			#ser.write('%c' % CR)    # Send CR
    			#time.sleep(.150)
    			#get_time()
    			#clockit = now.strftime("%H:%M:%S%n")
    			#ser.write(clockit)
    			#ser.write('%c' % CR)    # Send CR
    			#ser.write('Got it!%c' % CR)
    			#time.sleep(.300)
    			print('Sent it: %s' % clockit)  # Could use for log file.
    
    
  • I cleaned up the Badge code a little, and it still runs as expected.

    The Python code has not changed yet, so the previous listing is still valid. The only problem with the Python code is, when you disconnect the USB cable from the Badge, the Python program shuts down. Not sure how to get around that. I was thinking that the program would keep running, that way you could disconnect and reconnect the Badge to get it updated at any time.

    Ray
    /*
      gBaseUnit.c
      Jan 10, 2016
      Parallax Hackable Badge base unit attached to Raspberry Pi.
      
      * Automate clock update.
    
    */
    #include "simpletools.h"
    #include "simpletext.h"
    #include "fdserial.h"
    #include "badgetools.h"
    #include "datetime.h"
    
    serial *term;
    
    datetime dt = {2000, 1, 1, 0, 0, 0};  // Seed the datetime dt value.
    
    char dates[9];
    char times[9];
    
    /* System datetime*/
    char SysDT[20];
    
    /********************/
    
    /* Function prototypes */
    int TDupDate();
    int ShowClock();
    
    /********************/
    
    int main()
    {
      // Add startup code here.
      term = fdserial_open(31,30,0,115200);
      badge_setup();
      dt_run(dt);
      pause(250);  // Wait for dt_run to setup.
    
    /* Update the datetime data, using the connected Raspberry Pi. */ 
      TDupDate();
     
      while(1)
      {
        // Add main loop code here.
        ShowClock();
        pause(100);
      }  
    }
    /********************/
    
    /* Functions */
    
    /* Update the system clock with data from
     the Raspberry Pi using the Python program.
    */
    int TDupDate()
    {
    /* Send to Python. */
      writeStr(term,"SysTime\n");
      pause(150);
      readStr(term,SysDT,20);  // Get data from Python.
      pause(100);
      
    /* Process the date time data.*/ 
      sscan(SysDT,"%d/%d/%d/%d/%d/%d",&dt.mo,&dt.d,&dt.y,&dt.h,&dt.m,&dt.s);
      dt_set(dt);  // Reset dt with the new data.
      pause(200);
      return 0;  
    }  
    /********************/
    
    ShowClock()
    {
      /* Show clock, in LARGE characters. */
        dt = dt_get();
        dt_toTimeStr(dt,times);
        text_size(LARGE);
        cursor(0,0);
        oledprint("%s", times);
       // pause(100);    
      return 0;
    }  
    
    
  • The base unit Badge is now setup to update its clock, and then do a continuous IR scan for other tasks, like in this case updating the clock on a Roaming Badge.

    For the Roaming Badge you would press P17 to get the update, and then it shows a continuous running clock.

    Now that I have these concepts working, the next step is working with data between the three units, Raspberry Pi, BaseUnit Badge, and the Roaming Badge. Now it starts to get a little complicated, passing data using the IR, and then eventually getting it onto a file on the Raspberry Pi.

    Ray


    The base unit.
    /*
      gBaseUnit.c
      Jan 10, 2016
      Parallax Hackable Badge base unit attached to Raspberry Pi.
      
      * Automate clock update.
    
    */
    #include "simpletools.h"
    #include "simpletext.h"
    #include "fdserial.h"
    #include "badgetools.h"
    #include "datetime.h"
    
    serial *term;
    
    datetime dt = {2000, 1, 1, 0, 0, 0};  // Seed the datetime dt value.
    
    char dates[9];
    char times[9];
    int et,td;
    
    /* System datetime*/
    char SysDT[20];
    
    /********************/
    
    /* Function prototypes */
    int TDupDate();
    int ShowClock();
    int GetSysTime();
    
    /********************/
    
    int main()
    {
      // Add startup code here.
      term = fdserial_open(31,30,0,115200);
      badge_setup();
      dt_run(dt);
      pause(250);  // Wait for dt_run to setup.
    
    /* Update the datetime data, using the connected Raspberry Pi. */ 
      TDupDate();
      
      ShowClock();
      pause(2000);
      
      clear(); 
      text_size(SMALL);
      cursor(0,0);
      oledprint("System is on!");
    
      td = 0;
      while(1)
      {
        // Add main loop code here.
        //ShowClock();
        //pause(100);
        GetSysTime();
        irscan("%d", &td);   // Continuous scan for IR, blinking RED RGB.
        if(td = 10)          // Check ID code, 10 is for datetime
        {
          int et = dt_toEt(dt);
          //rgbs(RED,RED);
          irprint("%d", et);
          //rgbs(OFF,OFF);
          td = 0;           // Set ID code back to 0.    
        }
        cursor(0,7);
        text_size(SMALL);
        oledprint("Waiting for IR");      
        
      }  
    }
    /********************/
    
    /* Functions */
    
    /* Update the system clock with data from
     the Raspberry Pi using the Python program.
    */
    int TDupDate()
    {
    /* Send to Python. */
      writeStr(term,"SysTime\n");
      pause(150);
      readStr(term,SysDT,20);  // Get data from Python.
      pause(100);
      
    /* Process the date time data.*/ 
      sscan(SysDT,"%d/%d/%d/%d/%d/%d",&dt.mo,&dt.d,&dt.y,&dt.h,&dt.m,&dt.s);
      dt_set(dt);  // Reset dt with the new data.
      pause(200);
      return 0;  
    }  
    /********************/
    
    int ShowClock()
    {
      /* Show clock, in LARGE characters. */
        dt = dt_get();
        dt_toTimeStr(dt,times);
        text_size(LARGE);
        cursor(0,0);
        oledprint("%s", times);
       // pause(100);    
      return 0;
    }
    
    int GetSysTime()
    {
        dt = dt_get();
        dt_toTimeStr(dt,times);
    }    
    
    
    The roaming Hackable Badge.
    /*
      sBadge.c
      Jan 10, 2016
    
    */
    #include "simpletools.h"
    #include "badgetools.h"
    #include "datetime.h"
    
    datetime dt;
    int et;
    char dates[9];
    char times[9];
    int td = 10;   // ID for datetime IR update.
    
    
    
    int main()
    {
      // Add startup code here.
      badge_setup();
      dt_run(dt);
      pause(250);
      
     
      while(1)
      {
        // Add main loop code here.
        // Run the clock.
        text_size(SMALL);
        dt = dt_get(); 
        dt_toDateStr(dt, dates);
        dt_toTimeStr(dt, times);
        cursor(4, 6);
        oledprint("%s", dates); 
        cursor(4, 7); 
        oledprint("%s", times);
        pause(100);    
    
        if(button(5) == 1)  // If P17 is pressed
        {
          irprint("td",td);  // Send ID for datetime update.
          pause(100);
          irscan("%d", &et);  // Get the upload.
          rgbs(BLUE,BLUE);    // Got it.
          pause(50);
          rgbs(OFF,OFF);
          dt = dt_fromEt(et);  // Conversion
          dt_set(dt);          // Update dt with new data.
          clear();
        }
                 
      }  
    }
    
    
  • The program below is my updated Mobile Hackable Badge. I have added some, system maintenance, clock functions, battery function, plus I am saving the IR Send/Receive for last. That is going to be the hardest to code, the way I want it to function.

    To recap, I have the RPi code that updates my clock for the Base Unit Badge. The Base Unit Badge can auto update the Mobile Badge. Now what I need is, maybe a Raspberry Pi HAT that has IR send/receive hardware on it, with some C code for using the the IR hardware. That way I could free up my Base Unit Badge and make that a Mobile Badge. I am not a hardware guy, so I guess I will just keep my fingers crossed...

    I was also so thinking, if the Badge had the IR hardware at the top of the Badge, you could almost have a comfortable remote control setup for driving your ActivityBot around, amongst other uses.

    Ray
    /*
      sBadge.c
      Jan 10, 2016
      * Mobile Hackable Badge
      * Clock Functions
      * Battery Functions
      * System Maintain
      * TBD - Messages
      * TBD - IR Receive
      * TBD - IR Send
    
    */
    #include "simpletools.h"
    #include "badgetools.h"
    #include "datetime.h"
    
    
    datetime dt = {2016, 1, 1, 0, 0, 0,};
    
    /* Temp badge name, this will be handled from
       the base uniit. Badge name could be updated
       when you get the clock update.*/
    char BadgeName[] = {"Ray\n"};
    /* Permenent number for badge control.*/
    int BadgeID = 0001;  // ID specific for Badge.
    
    /* Voltage gauge*/
    float calcVt(float batteryVolts, int decayMicros);
    float batVolts(float vt);
    
    float RC = 360000.0 * (1.0 / 100000000.0);
    float vt, vbat;
    /****************/
    
    int et;
    char dates[9];
    char times[9];
    int td = 10;   // ID for datetime IR update.
    
    
    /* Function prototypes */
    void menu(void);
    void SysMaint(void);
    void SysTDB(void);
    void DTupdate(void);
    void BatUpdate(void);
    void NewClear();  // Clears screen lines 0 - 6.
    void bLine();  // Clean a line.
    /* Set Clock (SC) */
    void SetClock();
    void SCmenu();
    void SCsubmenu();
    void SCsetYear();
    void SCsetMonth();
    void SCsetDay();
    void SCsetHour();
    void SCsetMinute();
    void SCsetSecond();
    
    void Store_edClock();
    
    int main()
    {
      // Add startup code here.
      badge_setup();
      dt_run(dt);    // Start datetime COG.
      pause(250);    // Wait for datetime setup.
      
    /* Voltage RCT value. */
      vt = calcVt(4.17, 1453);  // Universal RCT value.
    /******************/
      
    text_size(SMALL);
    oledprint("OSH-Menu");
     
      while(1)
      {
        // Add main loop code here.
        if( button(6) == 1)
        {
          menu();
          pause(1000);
          int states = 0;
          while(states == 0)
          {
            states = buttons();
            states = 0;
            while(states != 0b1000000)  
            {
              states = buttons();
              switch(states)
              {
                case 0b0100000:   // P17
                  NewClear();
                  oledprint("Time,date,bat");
                  SysTDB();
                  BatUpdate();
                  break;
                case 0b0010000:   // P16 - Name
                  NewClear();
                  text_size(LARGE);
                  oledprint(BadgeName);
                  text_size(SMALL);
                  break;
                case 0b0001000:   // P15 - TBD(Mesages)
                  break;
                case 0b0000100:   // P25 - SysMaint
                  clear();
                  oledprint("System Maint");
                  pause(1000);
                  SysMaint();
                  break;
                case 0b0000010:   // P26 - TBD(Receive IR)
                  break;
                case 0b0000001:   // P27 - TBD(Send IR)
                  break;
                case 0b1000000:   // OSH to exit back.
                  clear();
                  pause(1000);
                  oledprint("OSH-Menu");
                  break;
              }            
            }          
          }        
        }      
      }  
    }
    
    void menu()
    {
      clear();
      text_size(SMALL);
      cursor(0,0);
      oledprint("P17-Clock&Bat");
      cursor(6,1);
      oledprint("IR Rcv-P27");
      cursor(0,2);
      oledprint("P16-Name");
      cursor(6,3);
      oledprint("IR Snd-P26");
      cursor(0,4);
      oledprint("P15-Msgs");
      cursor(2,5);
      oledprint("Sys Maint-P25");
      cursor(4,7);
      oledprint("OSH-Exit");
    }  
    
    void SysMaint(void)
    {
      clear();
      oledprint("System Maint");
      cursor(0,1);
      oledprint("P17-Update Clock");
      cursor(0,2);
      oledprint("P16-Set Clock");
      cursor(0,3);
      oledprint("P15-Store(ed)Clk");
      cursor(4,7);
      oledprint("OSH exit");
      pause(1000);
      int states = 0;
      while(states == 0)
      {
        states = buttons();
        while(states != 0b1000000)
        {
          states = buttons();
          switch(states)
          {
            case 0b0100000:   // P17
              pause(500);
              cursor(0,6);
              oledprint("Updating Clock");
              DTupdate();
              cursor(0,6);
              oledprint("               ");
              break;
            case 0b0010000:  // P16 - set clock         
              SetClock();
              break;
            case 0b0001000:
              Store_edClock();  // P15 - store/retrieve clock
              break;
            case 0b1000000:  // OSH
            break;
          }        
        }
        break;
      }
      clear();
      cursor(4,7);  
      oledprint("OSH exit");    
    }
    
    void SysTDB(void)
    {
      clear();
      text_size(LARGE);
      dt = dt_get(); 
      dt_toDateStr(dt, dates);
      dt_toTimeStr(dt, times);
      oledprint("%s",dates);
      pause(1000);
      cursor(0,0);
      oledprint("%s",times);
      text_size(SMALL);
      cursor(4,7);
      oledprint("OSH exit");
    }
    
    void DTupdate(void)
    {
      irprint("td",td);  // Send ID for datetime update.
      pause(100);
      irscan("%d", &et);  // Get the upload.
      rgbs(BLUE,BLUE);    // Got it.
      pause(50);
      rgbs(OFF,OFF);
      dt = dt_fromEt(et);  // Conversion
      dt_set(dt);          // Update dt with new data. 
    }
    
    void BatUpdate(void)
    {
      text_size(SMALL);
      cursor(0,6);
      // Voltage
      vbat = batVolts(vt);
      pause(100);
      oledprint("%1.2f V", vbat);
    }
    
    float calcVt(float voltsBattery, int microsDecay)
    {
      float voltsThreshold, tDecay;
      tDecay = ((float) microsDecay) / 1000000.0;
      voltsThreshold = voltsBattery * (1 - exp(-tDecay / RC));
      return voltsThreshold;
    }
      
    float batVolts(float voltsThreshold)
    {
      float voltsBattery, microsDecay;
      low(0);
      pause(1);
      microsDecay = ((float) rc_time(0, 0)) / 1000000.0;
      voltsBattery = voltsThreshold / (1 - exp(-microsDecay / RC));
      return voltsBattery;
    }
    
    /* To be used for clearing lines 0 - 6 */
    void NewClear()
    {
      cursor(0,0);
      bLine();
      cursor(0,1);
      bLine();
      cursor(0,2);
      bLine();
      cursor(0,3);
      bLine();
      cursor(0,4);
      bLine();
      cursor(0,5);
      bLine();
      cursor(0,6);
      bLine();
      cursor(0,0);
    }
    
    
    /* Blanks a line. */
    void bLine()
    {
      oledprint("                ");
    }    
    
    
    /* Set Clock */
    
    void SetClock()
    {
      clear();
      //oledprint("TBD");
      //pause(2000);
      //NewClear();
      SCmenu();
      while(1)
      {
    
        if(button(5) == 1)  // P17 - set year
        {
          SCsetYear();
          SCmenu();
        }
        if(button(4) == 1)  // P16 - set month
        {
          SCsetMonth();
          SCmenu();
        }
        if(button(3) == 1)  // P15 - set day
        {
          SCsetDay();
          SCmenu();
        }
        if(button(2) == 1)  // P25 - set hour
        {
          SCsetHour();
          SCmenu();
        }
        if(button(1) == 1)  // P26 - set minute
        {
          SCsetMinute();
          SCmenu();
        }
        if(button(0) == 1)  // P27 - set second
        {
          SCsetSecond();
          SCmenu();
        }                             
        if(button(6) == 1)  // OSH
        {
          dt_set(dt);
          break;
        }           
      }    
    }  
    
    
    void SCmenu()
    {
      clear();
      text_size(SMALL);
      cursor(0,0);
      oledprint("P17-Yr");
      cursor(0,3);
      oledprint("P16-Mon");
      cursor(0,6);
      oledprint("P15-Day");
      cursor(10,6);
      oledprint("P25-Hr");
      cursor(9,3);
      oledprint("P26-Min");
      cursor(9,0);
      oledprint("P27-Sec");
      cursor(4,7);
      oledprint("OSH-Done");
    }  
    
    
    void SCsubmenu()
    {
      text_size(SMALL);
      cursor(9,0);
      oledprint("P27-UP");
      cursor(12,3);
      oledprint("P26");
      cursor(11,4);
      oledprint("NEXT");
      cursor(9,7);
      oledprint("P25-DN");
      //text_size(LARGE);
    }  
    
    void SCsetYear()
    {
      clear();
      oledprint("YEAR");
      SCsubmenu();
      int y = dt.y;
      cursor(0,1);
      oledprint("%d",y);
      pause(1000);
      while(1)
      {
        if(button(0) == 1)  // P27
        {
          y++;
        }
        else if(button(2) == 1) // P25
        {
          y--;
        }
        else if(button(1) == 1)  // P26
        {
          dt.y = y;
          break;
        }
        text_size(SMALL);
        cursor(0,1);
        oledprint("%d",y);
        pause(100);                
      }
      
    }
    
    void SCsetMonth()
    {
      clear();
      oledprint("MON");
      SCsubmenu();
      int mo = dt.mo;
      cursor(0,1);
      oledprint("%02d",mo);
      pause(1000);
      while(1)
      {
        if(button(0) == 1)  // P27
        {
          mo++;
          if(mo > 12) mo = 1;
        }
        else if(button(2) == 1) // P25
        {
          mo--;
          if(mo < 1) mo = 12;
        }
        else if(button(1) == 1)  // P26
        {
          dt.mo = mo;
          break;
        }
        text_size(SMALL);
        cursor(0,1);
        oledprint("%02d",mo);
        pause(100); 
      }    
    }
    
    
    void SCsetDay()
    {
      clear();
      oledprint("DAY");
      SCsubmenu();
      int d = dt.d;
      cursor(0,1);
      oledprint("%02d",d);
      pause(1000);
      while(1)
      {
        if(button(0) == 1)  // P27
        {
          d++;
          if(d > 31) d = 1;
        }
        else if(button(2) == 1) // P25
        {
          d--;
          if(d < 1) d = 31;
        }
        else if(button(1) == 1)  // P26
        {
          dt.d = d;
          break;
        }
        text_size(SMALL);
        cursor(0,1);
        oledprint("%02d",d);
        pause(100); 
      }    
    }
    
    void SCsetHour()
    {
      clear();
      oledprint("HOUR");
      SCsubmenu();
      int h = dt.h;
      cursor(0,1);
      oledprint("%02d",h);
      pause(1000);
      while(1)
      {
        if(button(0) == 1)  // P27
        {
          h++;
          if(h > 24) h = 0;
        }
        else if(button(2) == 1) // P25
        {
          h--;
          if(h < 0) h = 23;
        }
        else if(button(1) == 1)  // P26
        {
          dt.h = h;
          break;
        }
        text_size(SMALL);
        cursor(0,1);
        oledprint("%02d",h);
        pause(100); 
      }    
    }
    
    void SCsetMinute()
    {
      clear();
      oledprint("MIN");
      SCsubmenu();
      int m = dt.m;
      cursor(0,1);
      oledprint("%02d",m);
      pause(1000);
      while(1)
      {
        if(button(0) == 1)  // P27
        {
          m++;
          if(m > 59) m = 0;
        }
        else if(button(2) == 1) // P25
        {
          m--;
          if(m < 0) m = 59;
        }
        else if(button(1) == 1)  // P26
        {
          dt.m = m;
          break;
        }
        text_size(SMALL);
        cursor(0,1);
        oledprint("%02d",m);
        pause(100); 
      }    
    }
    
    void SCsetSecond()
    {
      clear();
      oledprint("SEC");
      SCsubmenu();
      int s = dt.s;
      cursor(0,1);
      oledprint("%02d",s);
      pause(1000);
      while(1)
      {
        if(button(0) == 1)  // P27
        {
          s++;
          if(s > 59) s = 0;
        }
        else if(button(2) == 1) // P25
        {
          s--;
          if(s < 0) s = 59;
        }
        else if(button(1) == 1)  // P26
        {
          dt.s = s;
          break;
        }
        text_size(SMALL);
        cursor(0,1);
        oledprint("%02d",s);
        pause(100); 
      }    
    }
    
    
    void Store_edClock()
    {
      clear();
      oledprint("Clock BU");
      cursor(0,1);
      oledprint("P27-Store");
      cursor(0,2);
      oledprint("P25-Retrieve");
      cursor(4,7);
      oledprint("OSH-Done");
      while(1)
      {
        if(button(0) == 1)   // P27 - store current clock
        {
          cursor(0,5);
          oledprint("Storing...");
          dt = dt_get();
          et = dt_toEt(dt);
          ee_writeInt(et,60000);
          pause(2000);
          cursor(0,5);
          oledprint("              ");
        }
        if(button(2) == 1)   // P25 - retrieve stored clock
        {
          cursor(0,5);
          oledprint("Retrieving...");
          et = ee_readInt(60000);
          dt = dt_fromEt(et);
          dt_set(dt);
          pause(2000);
          cursor(0,5);
          oledprint("              ");
        }            
        if(button(6) == 1)   // OSH
        {
          break;
        }      
      }    
    }  
    
    
  • Today I was looking into my Learn folder to see what is now available in the Simple Libraries. To my surprise I did not see any libraries that deal with the EEPROM, IR Send/Receive, or use of the RC for battery voltage purposes. You would think that because the C code has been developed for the Badge, the individual Libs would have found there way over too the Simple Libraries folder.

    For my Mobile Badge prototype, I am now ready to start looking into the best way to deal with the use of the EEPROM and the IR Send/Receive items, plus the messages part. My concept really relies on having a Base Unit, whether it is another Badge connected to a Raspberry Pi or a Raspberry Pi with a Propeller RPi HAT that has IR Send/Receive hardware. Another concern, SimpleIDE for the Raspberry Pi does not know how or cannot deal with Propeller RPi HAT attached. A side note: I think that using C with the Badge is a way better way of programming the Badge, strictly my opinion on this.

    Why the Base Unit? I think this would be the most efficient way of dealing with data and string transfers. What is available now is a Parallax program that you add some names and data strings which in turn re-programs your Badge. The direction that I am going in is, you have your basic firmware on the Badge and then you would use the Base Unit to upload/download Badge specific information using the IR hardware.

    I think that it is more convenient to deal with files, that contain your information for upload, on a Raspberry Pi, using some sort of editor, than using the existing method, but that is my preference. Also when you have captured data on your Badge, once you upload it to the Base Unit, it would be much simpler to use the tools on the RPi to manipulate the uploaded information.

    Like I mentioned, in another post, the use of the IR Send/Receive and use of the EEPROM will be an interesting programming session.

    Ray

Sign In or Register to comment.