Skip to content

Include routine to access case COMMON_COMMONCMD. #22

@clplaneguy

Description

@clplaneguy

My project is to use the MegaPi board to balance the "Balancing Robot" while a Raspberry Pi 3B+ is left available for other tasks. The balancing code is already on the board in the firmware. The firmware has a feature to change the "megapi_mode" in case "COMMON_COMMONCMD". However, there is no corresponding method in Python_for_MegaPi to access this case. Please include in Python_for _MegaPi a Python routine that will allow exicution of the arduino c++ code. A user's program would have something like . . .

bot.MegaPi_Mode(megapi_mode);

to access the firmware code . . .

case COMMON_COMMONCMD:                                               //    60            
      {
        uint8_t subcmd = port;
        uint8_t cmd_data = readBuffer(7);
        if(SET_MEGAPI_MODE == subcmd)                 //    #define SET_MEGAPI_MODE      0x12
                
        {
          Stop();
          if((cmd_data == BLUETOOTH_MODE) ||                             //    0        
             (cmd_data == AUTOMATIC_OBSTACLE_AVOIDANCE_MODE) ||          //    1         
             (cmd_data == BALANCED_MODE) ||                              //    2
             (cmd_data == IR_REMOTE_MODE) ||                             //    3          
             (cmd_data == LINE_FOLLOW_MODE))                             //    4          
          {
            megapi_mode = cmd_data;
            if(EEPROM.read(MEGAPI_MODE_CONFIGURE) != megapi_mode)   //  != buffer[7]
            {
              EEPROM.write(MEGAPI_MODE_CONFIGURE, megapi_mode);     //   = buffer[7]
            }
          }
          else
          {
            megapi_mode = BLUETOOTH_MODE;
            if(EEPROM.read(MEGAPI_MODE_CONFIGURE) != megapi_mode)
            {
              EEPROM.write(MEGAPI_MODE_CONFIGURE, megapi_mode);
            }
          }
        }
      }
      break;

Python_for_MegaPi would have something like . . .

#def COMMON_COMMONCMD (self,slot,speed):    subcmd=0x12, megapi_mode=?
def .MegaPi_Mode (self, megapi_mode):
        deviceId = 60;
#  uint8_t port = readBuffer(6);
#          Number count               1     2    3     4     5         6           7            8                     9               
#          Butter Position            0     1    2     3     4         5           6            7                     8
#          Defination/Output         ff    55   len   idx  action   device       port         slot                 data_a
#                                                                               subcmd      cmd_data                     
#                                                                                         megapi_mode                                                        
self.__writePackage(   bytearray( [0xff, 0x55, 0x07, 0x00,  0x02,  deviceId,     0x12,     megapi_mode     ]    +   self.short2bytes(speed) )   )
#          Buffer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions