<commit_before>###*
@class
PERIDOT board support
###
class PeridotBoard extends Board
  Board.addBoard(this)

  #----------------------------------------------------------------
  # Class attributes/methods

  @boardname: "PERIDOT"
  @author: "<NAME> (@s_osafune)"
  @website: "https://peridotcraft.com/"
  @portClasses: [SerialPort]

  #----------------------------------------------------------------
  # Instance attributes/methods

  ###*
  Constructor
  ###
  constructor: (config) ->
    @canarium = new Canarium()

  ###*
  Connect to PERIDOT board
  @param {Object}   port      Port object
  @param {Function} callback  Callback ({Boolean} result)
  ###
  connect: (port, callback) ->
    return callback?(true) if @isConnected
    @canarium.open(port.name, (result) =>
      return callback?(false) unless result
      @canarium.avm.option({forceConfigured: true}, (result) =>
        return callback?(false) unless result
        @isConnected = true
        callback?(true)
      )
    )

  ###*
  Disconnect from PERIDOT board
  @param {Function} callback  Callback ({Boolean} result)
  ###
  disconnect: (callback) ->
    return callback?(true) unless @isConnected
    @canarium.close((result) =>
      return callback?(false) unless result
      super(callback)
    )

  dumpMemory: (addr, words, callback) ->
    @canarium.avm.read(addr, words * 4, (result, readdata) =>
      return console.log("MEM_READ @ 0x#{addr.toString(16)}: failed") unless result
      arr = new Uint8Array(readdata)
      for i in [0...words]<commit_msg>Fix PERIDOT connection failure on Chromebook<commit_after>###*
@class
PERIDOT board support
###
class PeridotBoard extends Board
  Board.addBoard(this)

  #----------------------------------------------------------------
  # Class attributes/methods

  @boardname: "PERIDOT"
  @author: "<NAME> (@s_osafune)"
  @website: "https://peridotcraft.com/"
  @portClasses: [SerialPort]

  #----------------------------------------------------------------
  # Instance attributes/methods

  ###*
  Constructor
  ###
  constructor: (config) ->
    @canarium = new Canarium()

  ###*
  Connect to PERIDOT board
  @param {Object}   port      Port object
  @param {Function} callback  Callback ({Boolean} result)
  ###
  connect: (port, callback) ->
    return callback?(true) if @isConnected
    @canarium.open(port.path, (result) =>
      return callback?(false) unless result
      @canarium.avm.option({forceConfigured: true}, (result) =>
        return callback?(false) unless result
        @isConnected = true
        callback?(true)
      )
    )

  ###*
  Disconnect from PERIDOT board
  @param {Function} callback  Callback ({Boolean} result)
  ###
  disconnect: (callback) ->
    return callback?(true) unless @isConnected
    @canarium.close((result) =>
      return callback?(false) unless result
      super(callback)
    )

  dumpMemory: (addr, words, callback) ->
    @canarium.avm.read(addr, words * 4, (result, readdata) =>
      return console.log("MEM_READ @ 0x#{addr.toString(16)}: failed") unless result
      arr = new Uint8Array(readdata)
      for i in [0...words]
{'fraction_non_alphanumeric': 0.2096825905739019, 'fraction_numerical': 0.0038473869830073742, 'mean_word_length': 2.3839479392624727, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2064353', 'n_tokens_mistral': 927, 'n_tokens_neox': 911, 'n_words': 226}