import textwrap


def bytes_to_c_data(mah_bytes, length=None):
    """Converts a byte array to a CSV C array data format, with endlines!
        e.g: 0x12, 0xA4, etc.
        mah_bytes is the bytearray, and length is the number of bytes to
        generate in the array, and indent is how much to indent the output
    """
    ret = []
    # create an array of byte strings, including an endline every 10 or so bytes
    for i, bytestr in enumerate(textwrap.wrap(mah_bytes.hex(), 2)):
        ret.append("0x" + bytestr + ", ")
    # pad with extra zeros
    while length != None and len(ret) < length:
        ret.append("0x00, ")
    # join, wrap, and return
    return textwrap.fill(''.join(ret), width=6*12 + 5, initial_indent='    ', subsequent_indent='    ', break_long_words=False)